我提到了这篇文章
How to determine if a point is inside a 2D convex polygon?
但是我想在带开放层的OSM中做同样的事情,请帮帮我。
[Link](http://jsfiddle.net/Sanju5390/3tpLs6w3/)
最佳答案
您可以使用turf.js使用turf.inside进行此操作:
var polygon = new ol.Feature(new ol.geom.Polygon([[[-5e6, -1e6], [-4e6, 1e6],
[-3e6, -1e6], [-5e6, -1e6]]]));
var point = new ol.Feature(new ol.geom.Point([-4e6, 0e6]));
var format = new ol.format.GeoJSON();
var isInside = turf.inside(
format.writeFeatureObject(point),
format.writeFeatureObject(polygon));
console.log(isInside);
http://jsfiddle.net/d6o81vc7/22/
关于javascript - 我有一个多边形,我知道所有4个点。如何使用OpenLayers确定给定点是否在多边形内?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32390280/