Skip to content Skip to sidebar Skip to footer

How To Remove Square And Circle Option From Drawingmanager

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)..

Solution 1:

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

vardrawingManager=newgoogle.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:

functioninitMap() {
  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
}
<scriptsrc="https://maps.googleapis.com/maps/api/js?libraries=drawing"></script><divid="map"></div>

Post a Comment for "How To Remove Square And Circle Option From Drawingmanager"