Check if a point is inside polygon in OpenLayers 3

后端 未结 2 519
暖寄归人
暖寄归人 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:03

    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.

提交回复
热议问题