您可以:
- 創建的DrawingManager不受管制,或某些控件被忽略,那麼
- 添加自定義按鈕它們,然後
- 添加處理這些按鈕來觸發函數@ user1226919提到。
例子:
var drawingManager = new google.maps.drawing.DrawingManager({
drawingControl: false
});
drawingManager.setMap(map);
// drawingManager is now ready
var marker_btn = document.createElement("button");
marker_btn.innerHTML = "Create Marker";
// add handlers
marker_btn.addEventListener("click", (function() {
// closure handles local toggle variables
var toggled = false;
var originalHTML = marker_btn.innerHTML;
return function (e) {
if (toggled) {
drawingManager.setDrawingMode(null);
e.target.innerHTML = originalHTML;
} else {
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.MARKER);
e.target.innerHTML = "Cancel";
}
toggled = !toggled;
}
})());
// add button to map controls
map.controls[ google.maps.ControlPosition.TOP_CENTER ].push(marker_btn);
退房具有自定義多邊形按鈕的工作示例:https://codepen.io/bozdoz/pen/jZNXNP?editors=0010
謝謝,這是我一直在尋找;-) – tdurand 2012-02-24 02:45:28
同樣適用於,OverlayType.CIRCLE, OverlayType.POLYGON – Sam 2015-10-05 10:24:29