13

我使用google.maps.drawing.DrawingManager它看起来像:

drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: google.maps.drawing.OverlayType.MARKER,
    markerOptions: {
        draggable: true,
        optimized: false,
        icon: new google.maps.MarkerImage('uxt/images/ap_gif.gif')
    },
    drawingControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER,
        drawingModes: [
        google.maps.drawing.OverlayType.MARKER,
        google.maps.drawing.OverlayType.POLYGON
        ]
    },

    polygonOptions: {
        fillColor: '#1E90FF',
        strokeWeight: 0,
        fillOpacity: 0.3,
        editable: true
    },
    map: mapA
});

所以我的工具栏看起来像: 在此处输入图像描述

正如您在默认情况下看到的(页面重新加载后)标记被选中,但我需要选择“手”(“停止绘图”)。 在此处输入图像描述

我如何配置drawingManager来做到这一点?

谢谢你。

4

2 回答 2

27

只需将drawingMode选项设置为null

drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: null,
    ...
于 2013-02-17T12:54:43.270 回答
0

请检查以下代码。如果它不起作用,请查看这篇文章Google Maps API v3: Drawing Manager这可能会有所帮助

  var markers = [];
  var infowindow = new google.maps.InfoWindow();

  function initialize() {
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    drawingManager.setMap(map);
    google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
      if(event.type == google.maps.drawing.OverlayType.POLYLINE) {
        alert("polyline complete");
      }
      else if(event.type == google.maps.drawing.OverlayType.MARKER) {
        var newMarker = event.overlay;
        newMarker.content = "marker #" + markers.length;
        google.maps.event.addListener(newMarker, 'click', function() {
          infowindow.setContent(this.content);
          infowindow.open(map, this);
        });
        markers.push(newMarker);
      }
    });
  }
于 2013-02-17T12:32:27.530 回答