OpenLayers 4 如何检测一个多边形是否接触到另一个多边形的侧面

OpenLayers 4 how to detect if a polygon touches the side of another polygon

我想知道我是否以及如何检测到用户正在绘制或已经绘制了多边形或其他重叠的形状。我曾尝试使用 intersectsCoordinate 但没有成功。例如,用户将绘制一个正方形,然后在第一个正方形内绘制一个圆形或另一个正方形。如果在第一个正方形内绘制的形状超出边界或触及我需要知道的边界。

您可以使用 Map.getFeaturesAtPixel 方法和地图上的 pointermove 事件来检测它。当您绘制时,该方法将 return 鼠标指针处的任何特征。

map.on("pointermove", function(e) {
    console.log(e.pixel);
    var features = map.getFeaturesAtPixel(e.pixel);
    if (features && features.length >= 3) {
        // 3 => drawing cursor, line, other feature
        alert("it's on");
    }
});

从 OL 示例中检查 codepen

JSTS has good support for working with OpenLayers geometry and provides a wide range of spatial predicates and operations including touches.