所以我正在使用谷歌地图绘图管理器来绘制一些多边形,并将后期长坐标保存到我的数据库中。现在我的问题是,在我将它加载到我的数组之后,如何将保存的多边形重建回我的地图?我似乎找不到代码来理解这一点。
这就是我现在所拥有的:
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);
}