loading google maps drawing manager object
Posted
by
psychok7
on Stack Overflow
See other posts from Stack Overflow
or by psychok7
Published on 2012-09-06T15:01:44Z
Indexed on
2012/09/06
21:38 UTC
Read the original article
Hit count: 264
google-maps
|google-maps-api-3
So i am using Google Maps Drawing Manager to draw some polygons and i am saving the lat e long coordinates to my database. Now my question is, after i load that to my array, how can i rebuild the saved polygon back into my map? I can't seem to find a code to understand that.
this is what i have now :
window.initialize_2 = function () {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = maplimits;
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: {
icon: 'images/beachflag.png'
},
polygonOptions: {
fillColor: '#ffff00',
fillOpacity: 10,
strokeWeight: 5,
clickable: true,
editable: true,
zIndex: 1
}
});
var coord_listener = google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
var coordinates = (polygon.getPath().getArray());
console.log(coordinates);
window.poly = polygon;
});
//delete shape
google.maps.event.addListener(drawingManager, 'overlaycomplete', function (e) {
if (e.type != google.maps.drawing.OverlayType.MARKER) {
// Switch back to non-drawing mode after drawing a shape.
drawingManager.setDrawingMode(null);
// Add an event listener that selects the newly-drawn shape when the user
// mouses down on it.
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, 'click', function () {
setSelection(newShape);
});
setSelection(newShape);
}
});
// Clear the current selection when the drawing mode is changed, or when the
// map is clicked.
google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
google.maps.event.addListener(map, 'click', clearSelection);
drawingManager.setMap(map);
}
© Stack Overflow or respective owner