[OpenLayers-Users] help with containspoint, or opposite

Jesse Bushkar apt94jesse at gmail.com
Thu Dec 10 00:48:06 EST 2009


Hello, I'm looking for a little help with a point moving inside and outside
of a polygon.  Currently I'm using the following code:
--
for(var i = 0; i < OL.maps[map.id].map.layers[1].features.length; i++) {

  if(locationSwitch == false &&
OL.maps[map.id].map.layers[1].features[i].geometry.containsPoint
&& OL.maps[map.id].map.layers[1].features[i].geometry.containsPoint(p)) {
       var yourlocation = OL.maps[map.id
].map.layers[1].features[i].data.node_title;
   alert('now youre inside the polygon');
   locationSwitchInner = true;
  }
 if(locationSwitchInner == true){
locationSwitch = true;
}
    if(locationSwitch == true &&
!OL.maps[map.id].map.layers[1].features[i].geometry.containsPoint(p))
{
   locationSwitchInner = false;
   alert('you are now leaving the polygon');
  }
  if(locationSwitchInner == false){
locationSwitch = false;
}
 }
   };

--------------------------------------

Basically what I'm doing is tracking a point on a map that contains
polygons.  I may not have included all of the code above but the necessary
items should be there.  I am displaying an alert when I enter a polygon,
which is working just fine.  The code checks my point across (currently) 4
polygons and alerts me when I enter into one.  Once I'm in one, I want to
send another alert when I exit the polygon.  However the code above doesn't
work because in the if statement that checks if I'm not in a polygon, it
checks all 4 polygons so of course 3 of them will validate because none of
the polygons intersect.

I guess my question is this: how can I check if my point is exiting ONLY the
polygon that I'm currently in (once I'm in the polygon of course)?  I am
thinking that the [i] could be included in the 'if' statement looking for
the exit point since it's still inside the 'for' statement, however, I'm
pretty bad with my for loop understanding.

Any help is greatly appreciated.  Thanks in advance.

Jesse
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091210/eceb5572/attachment.html


More information about the Users mailing list