I have created a map upon which the user can draw a polygon. The user
can save the polygon info in our database.
Now I am trying to re-display the saved polygon when the user calls it
back from the database.
I just don't seem to be able to get the syntax correct.
I define the following global variables
var map = null;
var poly;
var markers = [];
var path = new google.maps.MVCArray;
Then I initialize the map like this:
function initialize() {
var latlng = new google.maps.LatLng(41.904704529604835,
-88.10674667358398);
var myOptions = {
zoom: 7,
center: latlng,
scaleControl: true,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
infowindow = new google.maps.InfoWindow({
content: ''
});
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addPoint);
infowindow = new google.maps.InfoWindow();
}
I use this function to let the user build the original polygon:
//boundry functions
function addPoint(event) {
path.insertAt(path.length, event.latLng);
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("#" + path.length);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i]
!= marker; +
+i);
markers.splice(i, 1);
path.removeAt(i);
}
);
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i]
!= marker; +
+i);
path.setAt(i, marker.getPosition());
}
);
}
How can I re-load the MVCArray path with the stored data?
The OLH states I can simply load an array of the coordinates and they
will automatically be converted to the MVCArray. I have tried this,
and it does not seem to work:
poly.paths = myData[0].layout;
where myData[0].layout is an array of Lat and Lngs like this:
myData[0].layout[i].lat = 41.75074632037276
myData[0].layout[i].lng = -88.1522571322632
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.