Hi there,
I have the data for a single, simple polygon to be pushed to a map stored in
mysql. I have retrieved that data, and put it into a simple javascript
variable named "bounds" as a list of lat long pairs, delimited by a colon.
My goal is to push the polygon (which should be editable) to the map. I am
able to extract each pair, and I am using the following code (with no
success) to load the polygon onto the map:
var map;
var poly;
var markers = new Array();
var path = new google.maps.MVCArray;
...
function initialize() {
//set map options propertylatlng set through a geocode on the address
var myOptions = {
zoom: 15,
center: propertylatlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
//compose map
var map = new
google.maps.Map(document.getElementById("map_canvas"),myOptions);
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);
}
function loadmap() {
var pointsArray = bounds.split(":");
if(pointsArray.length!=0){
for(var i=0; i<pointsArray.length; i++){
//check to see if the point is being isolated
console.log(pointsArray[i]);
var this_latlng = new google.maps.LatLng(pointsArray[i]);
path.insertAt(i,this_latlng);
var marker = new google.maps.Marker({
position: this_latlng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("##" + path.length);
}
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '##5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
}
}
I admit I am borrowing code for some of this; here is what I don't
understand. For poly.setPaths, why pass "new google.maps.MVCArray([path])" -
I have tried just passing "path" as poly.setPaths(path) for example. I just
don't get how to reference the MVCArray, or how to push a polygon I to the
map. I am dense I guess...from the code above, I have added elements to the
array, so I wonder whether by pushing a "new" MVCArray, I just empty the
path? Or does the path get copied to the array? I have to say, I find the
documentation unnecessarily cryptic on these things. Examples are limited.
More fundamentally, if I have a set of lat/long pairs in a javascript
variable, how do I push them to a polygon? Do the pairs have to close
(repeat the first point)? There is no "event" like a click or double click,
just have the data and want to push it. I need to use variable names that
allow the user to edit the polygon afterwards, hence the use of common
variables in the code above. At the moment, I can add polygons (by drawing
them), save them to a database, retrieve them back from the database, I just
can't display that saved data back onto the map. Help please!
Thanks!
Doug
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-maps-js-api-v3/-/XXUkbdFwpuIJ.
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.