-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make adding listeners (for example click) to L.Routing.Line easier #117
Comments
Adding a click listener for the control doesn't make sense, in my opinion: the control consists of a lot of different parts (itinerary, geocoders, various buttons, etc.) that are clickable, what does it mean to click the control? If you want to add a click listener to the line shown in the map, you can do so by using the control's var routingControl = L.Routing.control({
routeLine: function(route) {
var line = L.Routing.line(route);
line.on('click', function(e) { console.log(e); });
return line;
}
[...]
}); This way, the control will call the |
unfortunately then all options are gone. I tried to fix that by line.options.addWaypoints = false etc. but it seemed that this doesn't have any effect. And the on-click function don't work, too. New code:
Of course the code is overloaded and options are duplicated. |
Pass the line options directly to the line constructor, avoid setting options explicitly, since some things might be initialized by options when the object is created. routingControl= L.Routing.control({
waypoints:[
markers[mk+2]._latlng,
markers[mk+3]._latlng
],
routeLine: function(route) {
var line = L.Routing.line(route, {
addWaypoints: false,
extendToWaypoints: false,
routeWhileDragging: false,
autoRoute: true,
useZoomParameter: false,
draggableWaypoints: false,
addWaypoints: false
});
line.on('click',function(e) {
console.log(e);
});
console.log(line);
return line;
},
router: myRouter,
routeWhileDragging: false,
autoRoute: true,
useZoomParameter: false,
draggableWaypoints: false,
show:false,
addWaypoints:false
}); |
tried that. but there's no output while clicking at the route anyway.
|
I tried changing the styles by line.options.styles, too. No effect |
Sorry, I had forgotten exactly how this was implemented. Since This will work: line.eachLayer(function(l) {
l.on('click', function(e) {
console.log(e);
});
}); I'm reopening this issue to see if I can find a way to make this easier without knowing the insides of LRM and Leaflet. |
Thanks a lot. with that change it does the job. |
Possibly fire an event after creating the line, to make it possible to hook on listeners etc? |
I'm going to note in this thread that it's currently
Now. I had trouble until I looked in the source code. |
is there a way to do this now? temporary? (route click event) , all that i need is to turn off 'route selection' |
I'm trying to get the latlng of a click event on a leaflet routing machine created route but it seems that no click event is supported. My code:
Then I tried to call
route.on('click',function(e) { console.log(e); } );
Any idea how a click event can be added to the route after defined route. Something like
route = ...;
route.clickable = true;
The text was updated successfully, but these errors were encountered: