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:
<div>--</div><div><div>for(var i = 0; i < OL.maps[<a href="http://map.id">map.id</a>].map.layers[1].features.length; i++) {</div><div> </div><div> if(locationSwitch == false && OL.maps[<a href="http://map.id">map.id</a>].map.layers[1].features[i].geometry.containsPoint && OL.maps[<a href="http://map.id">map.id</a>].map.layers[1].features[i].geometry.containsPoint(p)) {</div>
<div> var yourlocation = OL.maps[<a href="http://map.id">map.id</a>].map.layers[1].features[i].data.node_title;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> alert('now youre inside the polygon');</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> locationSwitchInner = true;</div><div> }</div><div><div> if(locationSwitchInner == true){</div><div>locationSwitch = true;</div><div>}</div><div> if(locationSwitch == true && !OL.maps[<a href="http://map.id">map.id</a>].map.layers[1].features[i].geometry.containsPoint(p)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> locationSwitchInner = false;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> alert('you are now leaving the polygon');</div>
<div> }</div><div> if(locationSwitchInner == false){</div><div>locationSwitch = false;</div><div>}</div><div> }</div><div> };</div><div><br></div><div>--------------------------------------</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>Any help is greatly appreciated. Thanks in advance.</div><div><br></div><div>Jesse</div></div></div>