OpenLayers – Checking if Point is Inside Polygon Using JavaScript

javascriptopenlayers

When I am adding a point to my web map I want to give it a letter that represents the area where the point is, so I need to know what area the point is in.
In OpenLayers 2 I did it like this:
areas[i].geometry.containsPoint(point) —> returns true if it does.

Is there anything like this in OL3?

I searched in the OL3 API but didn't find it.

Best Answer

You can use yourVectorLayer.getSource().getFeaturesAtCoordinate(point). The result is an array, if its length > 0 then the point is inside, otherwise it's not.