【问题标题】:Check if a point is inside polygon in OpenLayers 3检查一个点是否在 OpenLayers 3 中的多边形内
【发布时间】:2017-01-03 15:02:12
【问题描述】:

当我在 OpenLayers 地图中绘制多边形时,我想知道标记是否在多边形内。我在 OpenLayers API 中进行了搜索,但没有找到解决方案。

你可以在link看到我的完整代码。

我的印象是必须修改这个函数:

  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
    });
  }
}

我该怎么做?

【问题讨论】:

    标签: javascript openlayers-3


    【解决方案1】:

    您有一个用于 ol.geom.Geometry 的方法“intersectsCoordinate”。

    所以代码如下所示:

    var polygonGeometry = e.feature.getGeometry();
    var coords = iconFeature.getGeometry().getCoordinates();
    polygonGeometry.intersectsCoordinate(coords)
    

    【讨论】:

      【解决方案2】:

      您可以使用JSTS 库,它实现了简单的几何处理,例如intersectsdifference 等。它包含一个OL3 解析器,可以将几何从OL3 转换为JSTS,反之亦然。

      查看example in OL3。基本上,您将使用一个过程来检查您的标记的几何形状是否在您的多边形内,然后从那里做您想做的事情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-26
        • 2015-06-03
        • 2019-08-23
        • 1970-01-01
        • 1970-01-01
        • 2013-03-29
        相关资源
        最近更新 更多