[OpenLayers-Users] How to find if Point is within Polygon??

plen peteralen at earthlink.net
Sat Mar 22 18:48:12 EDT 2008


Hello,

I have polyogns defined by:
var polygon = new OpenLayers.Geometry.Polygon([linearRing]);

Later, when the user clicks on the map, I can get the lat/long of the map
click and create a Point via:
var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);

The goal is to see if the point is within the polygon area.

I saw that there is a containsPoint(Point) method for the Polygon when I
look at the OpenLayers API docs at:
http://dev.openlayers.org/docs/files/OpenLayers/Geometry/Polygon-js.html
This API shows functions, properties, etc that may not be exposed to the
regular API which is listed at:
http://dev.openlayers.org/apidocs/files/OpenLayers/Geometry/Polygon-js.html

When I ran my code, I get an error that states that
OpenLayers.Geometry.Polygon does not have a containsPoint function.

I then tried to use the OpenLayers.Geometry.Polygon.intersects() method
since that was listed in the base API docs.  This function takes an
OpenLayers.Geometry object and since the point is created as
OpenLayers.Geometry.Point, I thought that might work.  But again, I got the
error that OpenLayers.Geometry.Polygon does not have an intersect function.

I am at a loss now.  This must be a common problem.  How can I check to see
if my point is within any of my polygons?

Thanks - Peter
-- 
View this message in context: http://www.nabble.com/How-to-find-if-Point-is-within-Polygon---tp16201177p16201177.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list