Google Maps API Tutorial

© 2007, 2008, 2009 Mike Williams

 
Translate this page:

 

EPolys

The EPoly extension adds seven 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.]

[The XML file that they use is here]

.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.

.GetPointsAtDistance(metres)

Returns an array of GLatLngs of points at the specified interval along the path.

By calculating all the points in a single pass, this runs a lot faster than calling GetPointAtDistance() in a loop. 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:

    var points = poly.GetPointsAtDistance(1609.344);

    for (var i=0; i<points.length; i++) {
      map.addOverlay(new GMarker(points[i]));
    }

[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 vertex v1 and vertex v2. Both parameters are optional.

If you omit v1, then the bearing from the first to last vertex is calculated.
If you specify v1 but omit v2, then the bearing from v1 to the next vertext is calculated.
If either vertex is out of range, it returns void.
If the vertexes are the same point (e.g. a closed path) then it returns zero.

The returned values are in degrees, rounded to one decimal place (because that's about the accuracy of the method used).

Back to Mike's Homepage
Up to the start of this tutorial