【问题标题】:Check existence of point on leaflet route检查传单路线上是否存在点
【发布时间】:2017-08-18 23:43:00
【问题描述】:

传单路由机器上是否有一种方法可以检查特定点(例如(lat,lng)是否在路由折线内?

【问题讨论】:

    标签: javascript routing leaflet


    【解决方案1】:

    没有,但使用 Leaflet.GeometryUtil 仍然可行

    看看belongsSegment函数:

    belongsSegment(latlng, latlngA, latlngB, toleranceopt, nullable) → {boolean}
    
    Returns true if the latlng belongs to segment A-B
    

    因此,当在 Routing Machine 中选择一条路线时,您将检查折线的每一段,如果该点属于它并具有给定的容差:

    var point = {your specific point};
    ...
    map.on('routeselected', function(e) {
        var route = e.route;
        isPointOnLine(point, route.coordinates));
    })
    

    isPointOnLine 在哪里

    function isPointOnLine(point, path) {
        for (var i = 0; i < path.length - 1; i++) {
            if (L.GeometryUtil.belongsSegment(point, path[i], path[i + 1])) {
                return true;
            }
        }
        return false;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-01-25
      • 1970-01-01
      • 2019-04-13
      • 2017-12-28
      • 2013-02-09
      • 1970-01-01
      • 2016-04-29
      • 2012-06-08
      • 1970-01-01
      相关资源
      最近更新 更多