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

Eric Lemoine eric.c2c at gmail.com
Sat Mar 22 19:36:02 EDT 2008


On Sat, Mar 22, 2008 at 11:48 PM, plen <peteralen at earthlink.net> wrote:
>
>  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?

Hi Plen

What OL version are you using? The API doc corresponds to what's in
trunk, and you're not using trunk AFACT.

Cheers,
--
Eric



More information about the Users mailing list