perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.07k stars 349 forks source link

Snapping Layer? #59

Open canadaka opened 9 years ago

canadaka commented 9 years ago

The other leaflet routing project has the feature for providing a "Snapping" layer. By default it uses OSM data served in geoJson format. But I created my own snapping layer of trails not on OSM and output it as GeoJSon service URL. This would be a great feature to allow changing the snapping source.

perliedman commented 9 years ago

That's a neat feature. However, I think it's sort of a special use case, and my guess is that it wouldn't work very well for large road networks (at least not without significant work).

I'm thinking it would be nice to support the ability to get this kind of functionality with LRM, although the exact method for snapping shouldn't be part of the plugin. For example, some options could be added to be able too hook into dragging of waypoints, to make them snap onto features.

perliedman commented 9 years ago

You could perhaps get some inspiration from the bike planner project I made with LRM as base: https://trafiken.nu/goteborg/cykelreseplanerare/. When you place a waypoint in the central parts of the city, you might notice that a couple of circle markers appear near the waypoint. These markers show where stations for bike sharing are located. When you drag the waypoints, they actually snap to these bike sharing stations.

This is implemented using Leaflet.snap (https://github.com/makinacorpus/Leaflet.Snap). As it is now, you'll have to override L.Routing.Plan's _createMarker method to make it snap to other geometries, but there's work in progress replace _createMarker with an option, to make it more obvious how to control marker creation (https://github.com/TheMarex/leaflet-routing-machine/commit/145fabe8a157a2813a6e7e1f3ee68e263d6cf4dc). I guess this technique could work in the general case as well.

mapninja commented 6 years ago

I'm looking for this functionality. I've got 4 small geojson network network layers (London in the 16th, 17th, 18th and 19th centuries) that I want to do routing on with no server backend.

perliedman commented 6 years ago

@mapninja for the actual path finding without backend, you might want to look at GeoJSON Path Finder.

As for snapping, I haven't done anything with it, although I suspect it would be somewhat straight forward to implement with turf.