Friday, 12 August 2016

javascript - OL3 check if point is inside a polygon


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.



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...