Hooking polygons in Google Maps API Version 3

39 views
Skip to first unread message

palewire

unread,
Apr 1, 2010, 2:21:15 PM4/1/10
to geodjango
Has anyone tried to jam polys and multipolys into the new syntax for
version 3?

http://code.google.com/apis/maps/documentation/v3/overlays.html#Polygons

Davepar

unread,
Apr 2, 2010, 2:31:11 AM4/2/10
to geodjango
Yes, I've done polygons. In Maps v2, I was storing my polygons in
encoded form, but v3 doesn't have the ability to create polygons from
encoded data. At least not yet.

When I query for the polygons, I add a ".geojson(precision=6)" to the
end of the query. I then do this:
result['shape'] = json.loads(x.shape.geojson)

Where "shape" is the name of my PolygonField. I ship that via AJAX
over to the client. On the client:

var pointArray = new google.maps.MVCArray();
for (var pointIdx = 0; pointIdx <
airspaceData.shape.coordinates[0].length; pointIdx++) {
var point = airspaceData.shape.coordinates[0][pointIdx];
pointArray.push(new google.maps.LatLng(point[1], point[0]));
}

var polyline = new google.maps.Polyline({
map: gmap,
path: pointArray,
strokeColor: '#0000FF',
strokeOpacity: 0.6,
strokeWeight: 4
});

That's the general sketch. Let me know if you need more details.

Dave

Reply all
Reply to author
Forward
0 new messages