osrm-frontend icon indicating copy to clipboard operation
osrm-frontend copied to clipboard

Disable adding viapoints by clicking on the route line

Open AnixPasBesoin opened this issue 9 years ago • 5 comments

What's the proper way to disable adding viapoints when clicking on the route line? I'd rather avoid monkey-patching the lrmControl.options.routeLine. What's the "by-design" approach to achieve this? Thanx in advance.

AnixPasBesoin avatar Apr 04 '17 14:04 AnixPasBesoin

@AnixPasBesoin There is no by-design way to do it.

LRM, which we depend on entirely for the UI here, has:

http://www.liedman.net/leaflet-routing-machine/api/#l-routing-plan

which has an addWaypoints: Boolean option which looks like it'll do what you're after.

danpat avatar Apr 05 '17 00:04 danpat

For some reason, toggling addWaypoint to false didn't disable adding waypoints when clicking on the line. I'm posting my current very dirty workaround:

        _onLineTouched: function (e) {
            // <patched>
            // var afterIndex = this._findNearestWpBefore(this._findClosestRoutePoint(e.latlng));
            // this.fire('linetouched', {
            //     afterIndex: afterIndex,
            //     latlng: e.latlng
            // });
            // </patched>
        },

As you can see, I simply commented the _onLineTouched code in L.Routing.Line.js. That's very ugly...

AnixPasBesoin avatar Apr 05 '17 10:04 AnixPasBesoin

@perliedman Any suggestions on the right way to do this?

danpat avatar Apr 11 '17 21:04 danpat

addWaypoints should work for this; notice that the option is in plural form and ends with s, not like written in @AnixPasBesoin comment above.

If this doesn't work, I'd step through this line with a debugger to check what's going on: https://github.com/perliedman/leaflet-routing-machine/blob/master/src/control.js#L197

perliedman avatar Apr 12 '17 06:04 perliedman

Maybe related: not sure if you're setting addWaypoints when creating the control or toggline the setting after it has been created; in the latter case, see https://github.com/perliedman/leaflet-routing-machine/issues/353

perliedman avatar Apr 12 '17 06:04 perliedman