本文介绍了如何从DrawingManager中删除正方形和圆形选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想弄到它,所以我的DrawingManager只能选择平移和有一个多边形,但我不知道如何去除其余选项(折线,方形,圆形)。。



我定义了我的DrawingManager并尝试删除rectangleOptions和circleOptions,但似乎没有做任何事情。

   


I am tyring to get it so my DrawingManager only has the option to pan and have a polygon, but I can't figure out how to remove the rest of the options (polyline, square, circle)..

I define my DrawingManager and have tried removing the rectangleOptions and circleOptions but that doesn't seem to do anything.

var polyOptions = {
        strokeWeight: 0,
        fillOpacity: 0.45,
        editable: true
    };

    drawingManager = new google.maps.drawing.DrawingManager({
        markerOptions: {
            draggable: true
        },
        polylineOptions: {
            editable: true
        },
        polygonOptions: polyOptions,
        map: map
    });

Is this possible to do?

解决方案

Look at the sample in the documentation, remove the drawingModes from the drawingControlOptions that you don't want:

  var drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: google.maps.drawing.OverlayType.MARKER,
    drawingControl: true,
    drawingControlOptions: {
      position: google.maps.ControlPosition.TOP_CENTER,
      drawingModes: [
        google.maps.drawing.OverlayType.POLYGON
      ]
    },
  });
  drawingManager.setMap(map);
}

code snippet:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {
      lat: -34.397,
      lng: 150.644
    },
    zoom: 8
  });
  var polyOptions = {
    strokeWeight: 0,
    fillOpacity: 0.45,
    editable: true
  };
  var drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: google.maps.drawing.OverlayType.MARKER,
    drawingControl: true,
    drawingControlOptions: {
      position: google.maps.ControlPosition.TOP_CENTER,
      drawingModes: [
        google.maps.drawing.OverlayType.POLYGON
      ]
    },
    markerOptions: {
      draggable: true
    },
    polylineOptions: {
      editable: true
    },
    polygonOptions: polyOptions,
  });
  drawingManager.setMap(map);
}
google.maps.event.addDomListener(window, "load", initMap);
html,
body,
#map {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=drawing"></script>
<div id="map"></div>

这篇关于如何从DrawingManager中删除正方形和圆形选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 10:53