Check if a point is inside polygon in OpenLayers 3

后端 未结 2 521
暖寄归人
暖寄归人 2021-02-08 04:49

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.

2条回答
  •  长发绾君心
    2021-02-08 05:04

    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)
    

提交回复
热议问题