[GIS] Function to intersect another polygon using OpenLayers

intersectionjavascriptopenlayers-2

I wonder if someone here have a JavaScript function that when I draw a polygon I can see if I am drawing on another polygon?

like intersect… if polygon intersect say to me a alert…

using OpenLayers.

Best Answer

You can have a look at the intersection example of OpenLayers: http://dev.openlayers.org/examples/intersects.html

for(var i=0; i<features.length-1; ++i) 
{
    feat1 = features[i];
    for(var j=i+1; j<features.length; ++j) 
    {
        feat2 = features[j];
        intersects12 = feat1.geometry.intersects(feat2.geometry);
        if(intersects12) 
        {
        alert("Intersection");
        }
    }
}