检查OpenLayers 3中的点是否在多边形内

Abd*_*imi 9 javascript openlayers-3

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

视觉澄清的截图

你可以在这个链接中看到我的完整代码.

我的印象是我必须修改此功能:

  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
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Fat*_*tAl 13

你有一个方法' intersectsCoordinate '为ol.geom.Polygon.

所以代码看起来像:

var polygonGeometry = e.feature.getGeometry();
var coords = iconFeature.getGeometry().getCoordinates();
polygonGeometry.intersectsCoordinate(coords)
Run Code Online (Sandbox Code Playgroud)