最新的代碼 - http://jsfiddle.net/YsQdh/88/ -
這個版本使用gDouglasPeuker從畫版創建rudamentary多邊形 - http://jsfiddle.net/YsQdh/94/
^這禁用地圖用於繪圖,創建形狀後再次啓用它。
我正在研究谷歌地圖應用程序。與多邊形點和點擊練習相反。我希望能夠繪製一個形狀 - 然後將其轉換爲多邊形。
這裏是我的最新應用 - http://jsfiddle.net/Cbk9J/168/
我發現下面的代碼 - 但我不能確定如何納入例子這一點。我還沒有找到任何文檔來釋放手繪,並且我不確定這些功能是否存在於Google地圖繪製管理器中。
var completeFreehand = function (changed) {
if (changed) {
isUserPolygon = true;
updateLocation();
}
unhighlightControls();
showMessages();
updateListingResults();
};
var completeDelete = function() {
map.endDeleteSearchArea();
unhighlightControls();
showMessages();
};
var cancelDelete = function() {
if (map.isDeletingSearchArea()) {
completeDelete();
updateListingResults();
enableControls();
}
return false;
};
var cancelFreehand = function() {
if (map.isDrawingFreehand()) {
map.cancelFreehand();
completeFreehand();
enableControls();
}
};
var clearMap = function (silent) {
map.clearSearchArea(silent);
mostRecentPinCount = 0;
enableControls();
map.clearMarkers(true);
return false;
};
var drawFreehand = function (element) {
if (map.isDrawingFreehand()) {
cancelFreehand();
return;
} else if (map.isDeletingSearchArea()) {
completeDelete();
}
disableControls(true);
highlightControl(element);
hideMessages();
if ($(element).hasClass('js-maps-btn-add')) {
$('.js-maps-status-message-draw').removeClass('is-hidden');
} else {
$('.js-maps-status-message-new').removeClass('is-hidden');
}
map.clearMarkers();
map.drawFreehand(completeFreehand);
updateBasePolygon();
return false;
};
function updateBasePolygon() {
if (typeof(basePolygon) == 'undefined') {
var polys = map.getPolygons();
if (polys.length) {
basePolygon = $.map(polys, function (val, i) {
var a = val.getPath().getArray();
return [
$.map(a, function (val, i) {
return [[ val.lat(), val.lng() ]];
})
];
});
}
}
}
你舉的例子似乎工作給我,你有徒手繪製多邊形。我不確定我瞭解你還需要什麼。 –
它不完整 - 我希望能夠徒手繪製 - 不要點擊多邊形點 - 畫一個像油漆一樣的形狀。然後讓它polygonised。 –
http://www.zoopla.co.uk/for-sale/map/property/london/?include_retirement_homes=true&include_shared_ownership=true&new_homes=include&q=london&results_sort=highest_price&search_source=home&pn=1&view_type=map - 像這樣 –