javascript - How to draw a polygon on google map (V3) and save it? -
this question has answer here:
i use google map in project , customize create , drawing polygon , poly-line don't save shapes, , want create polygon on map , save in database, question : how save polygon coords in database?
my code:
function initialize() { var mapoptions = { zoom: 14, minzoom: 14, maxzoom: 19, center: new google.maps.latlng(35.696282, 51.422946), maptypeid: google.maps.maptypeid.roadmap, maptypecontrol: true, scalecontrol: true, streetviewcontrol: false }; map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); drawingmanager = new google.maps.drawing.drawingmanager({ drawingmode: google.maps.drawing.overlaytype.polygon, drawingcontrol: true, drawingcontroloptions: { position: google.maps.controlposition.top_center, drawingmodes: [/*google.maps.drawing.overlaytype.circle, google.maps.drawing.overlaytype.rectangle, */google.maps.drawing.overlaytype.polyline, google.maps.drawing.overlaytype.polygon] }, polygonoptions: { editable: true } }); drawingmanager.setmap(map); google.maps.event.addlistener(drawingmanager, "overlaycomplete", function (event) { if (event.type != google.maps.drawing.overlaytype.marker) { drawingmanager.setdrawingmode(null); var newshape = event.overlay; newshape.type = event.type; google.maps.event.addlistener(newshape, 'click', function () { setselection(newshape); }); setselection(newshape); } }); google.maps.event.addlistener(drawingmanager, 'drawingmode_changed', clearselection); google.maps.event.addlistener(map, 'click', clearselection); //delete selected shape google.maps.event.adddomlistener(document.getelementbyid('deleteshape'), 'click', deleteselectedshape);
}
var len = shape.getpath().getlength(); var htmlstr = ""; (var = 0; < len; i++) { console.log(shape.getpath().getat(i).tourlvalue(7)); }
Comments
Post a Comment