leaflet-routing-machine icon indicating copy to clipboard operation
leaflet-routing-machine copied to clipboard

Snapping Layer?

Open canadaka opened this issue 11 years ago • 4 comments

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.

canadaka avatar Nov 30 '14 08:11 canadaka

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 avatar Dec 01 '14 20:12 perliedman

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.

perliedman avatar Dec 04 '14 08:12 perliedman

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.

mapninja avatar Feb 05 '18 21:02 mapninja

@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.

perliedman avatar Feb 06 '18 07:02 perliedman