Skip to content Skip to sidebar Skip to footer

Check If A Point Is Inside Polygon In Openlayers 3

When I draw a polygon in an OpenLayers map, I want to know if the marker is inside the polygon or not. I searched in the OpenLayers API, but didn't find a solution. And you can se

Solution 1:

You have a method 'intersectsCoordinate' for the ol.geom.Geometry.

So the code for that will look like:

var polygonGeometry = e.feature.getGeometry();
var coords = iconFeature.getGeometry().getCoordinates();
polygonGeometry.intersectsCoordinate(coords)

Solution 2:

You can use the JSTS library, which implements simple geometry processing such as intersects, difference, etc. It contains an OL3 parser that allows the conversion of geometry from OL3 to JSTS and vice-versa.

See an example in OL3. Basically, you would use a process that checks if the geometry of your marker is within your polygon or not and do what you want from there.

Post a Comment for "Check If A Point Is Inside Polygon In Openlayers 3"