检查点是否在OpenLayers 3中的多边形内 [英] Check if a point is inside polygon in OpenLayers 3
本文介绍了检查点是否在OpenLayers 3中的多边形内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在OpenLayers地图中绘制多边形时,我想知道标记是否在多边形内.我搜索了OpenLayers API,但没有找到解决方案.
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.
您可以在此链接中看到我的完整代码.
And you can see my full code in this link.
我觉得我必须修改此功能:
I have the impression that I have to modify this function:
function addInteraction() {
var value = typeSelect.value;
if (value !== 'None') {
draw = new ol.interaction.Draw({
source: vectorSource,
type: /** @type {ol.geom.GeometryType} */ (typeSelect.value)
});
map.addInteraction(draw);
draw.on('drawend',function(e){
//Here
});
}
}
我该怎么做?
推荐答案
You have a method 'intersectsCoordinate' for the ol.geom.Geometry.
因此该代码如下:
var polygonGeometry = e.feature.getGeometry();
var coords = iconFeature.getGeometry().getCoordinates();
polygonGeometry.intersectsCoordinate(coords)
这篇关于检查点是否在OpenLayers 3中的多边形内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文