Leaflet Routing Machine中是否有一种方法可以检查特定点(例如(lat,lng))是否在路径折线内?
Leaflet Routing Machine中是否有一种方法可以检查特定点(例如(lat,lng))是否在路径折线内?
虽然没有,但是仍然可以使用Leaflet.GeometryUtil实现
看一下belongsSegment函数:
belongsSegment(latlng, latlngA, latlngB, toleranceopt, nullable) → {boolean}
Returns true if the latlng belongs to segment A-B
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;
}