Google Maps API Tutorial© 2007 Mike Williams |
EPolysThe EPoly extension adds four extra methods to the GPolygon and GPolyline Classes.To use it, copy the epoly.js code into your own webspace and load it like: <script src="epoly.js" type="text/javascript"> </script> Here's an example [Here's an example that uses a bounds test to speed up click processing.] .Contains(latlng)Returns true if the GLatLng is inside the poly and false if the GLatLng is outside.The method works for closed or open polygons and polylines. If the shape is open, it considers there to be an additional virtual line from the last point to the first. If the point happens to lie exactly on the boundary of the polygon, then it may return either true or false. .Area()Returns the approximate area of the poly in square metres.The method works for closed or open polygons and polylines. If the shape is open, it considers there to be an additional virtual line from the last point to the first. The method doesn't fully account for spherical geometry, so the areas of large regions will be less accurate. .Distance()Returns the total length of the path in metres.
.Bounds()Returns the bounds of the polygon or polyline as a GLatLngBounds Object.
.GetPointAtDistance(metres)Returns the GLatLng of a point at the specified distance along the path.If the path is shorter than the specified distance, then it returns null. You could use this for placing mile markers along a route, like this: for (var i=0; i<poly.Distance(); i+=1609.344) {
var point = poly.GetPointAtDistance(i);
if (point) {
map.addOverlay(new GMarker(point));
}
}
[There are 1609.334 metres in a mile.]
.GetIndexAtDistance(metres)Returns the vertex number at or after the specified distance along the path.
.Bearing(v1?,v2?)Returns the bearing between vertext v1 and vertex v2. Both parameters are optional.
If you omit v1, then the bearing from the first to last vertex is calculated. The returned values are in degrees, rounded to one decimal place (because that's about the accuracy of the method used). |