javascript - google map api v3 - how to limit number of polygon lines and force closure at the 5 click? -
i have code
<script> function initialize() { var mapoptions = { center: new google.maps.latlng(-34.397, 150.644), zoom: 8 }; var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); 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 ] }, polygonoptions: { draggable: true, editable: true, strokecolor: "#000", strokeweight: "2" } }); drawingmanager.setmap(map); } google.maps.event.adddomlistener(window, 'load', initialize); </script>
and trying limit number of polygon lines 5 , 5 click force closure of polygon shape.
i unable find direction solve problem.. if u have link resource or ideas how - good!
one option: don't use drawingmanager. build polygon , keep track of markers added.
var poly; var map; function initialize() { var polyoptions = { strokecolor: '#000000', strokeopacity: 1.0, strokeweight: 3, map: map }; poly = new google.maps.polygon(polyoptions); var bounds = new google.maps.latlngbounds(); map = new google.maps.map(document.getelementbyid('map_canvas'), { center: new google.maps.latlng(10.9386, -84.888), zoom: 10, maptypeid: google.maps.maptypeid.roadmap }); var evtlistnr = google.maps.event.addlistener(map,"click",function(evt) { bounds.extend(evt.latlng); addlatlng(evt); if (poly.getpath().getlength() == 5) { google.maps.event.removelistener(evtlistnr); } }); poly.binder = new mvcarraybinder(poly.getpath()); poly.setmap(map); }
Comments
Post a Comment