leaflet-routing-machine
leaflet-routing-machine copied to clipboard
Old route line not removed
Hi, I want to remove the old route line, but it was not removed and updating to old one, I have checked with _clearLines() and spliceWaypoints, it didn't work, Wait for your positive reply and it will helpful to us.
Below is the code:
componentDidMount() { const { orderDetails: { pickLocationInfo, dropLocationInfo } } = this.props;
const { zoomLevel, maxZoom, position } = this.state;
map = L.map('map', {
center: position,
zoom: zoomLevel,
layers: [
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: maxZoom,
id: 'mapbox.streets',
accessToken: 'token-name'
}),
]
});
map.zoomControl.setPosition('bottomright');
// When Pickup and Dropoff both are exists
this.mapView(pickLocationInfo, dropLocationInfo, map);
}
mapView = (pickLocationInfo, dropLocationInfo, map) => { if (pickLocationInfo && dropLocationInfo) { let pickBound = new L.latLng(pickLocationInfo.lat, pickLocationInfo.lon); let dropBound = new L.latLng(dropLocationInfo.lat, dropLocationInfo.lon); let fitScreenToMarker = L.latLngBounds(pickBound, dropBound); map.flyToBounds(fitScreenToMarker);
const control = L.Routing.control({
waypoints: [pickBound, dropBound],
createMarker: function () { return null; },
router: L.Routing.mapbox('access-token'),
routeWhileDragging: false,
showAlternatives: true,
lineOptions: {
addWaypoints: false,
},
altLineOptions: {
addWaypoints: false,
},
show: false,
}).addTo(map);
L.Routing.errorControl(control).addTo(map);
control.on('routesfound', function (e) {
console.log('control._formatter.formatDistance', control._formatter.formatDistance(e.routes[0].summary.totalDistance, -1));
console.log('control._formatter.formatTime', control._formatter.formatTime(e.routes[0].summary.totalTime));
}.bind(this));
}
}
Hi!
I am sorry to say that unfortunately I do not have the time to dig into your code. Please simplify the example and make it clear what the problem is, as it is now I am not sure what you are trying to achieve, and what problems you are seeing.
As you might have seen from the issue template, I am not paid for LRM work, so answering complex questions is not something I can do in my free time.
Hello, I think I have the same problem here. I use LRM to display several routes on my OSM map and it works great (thanks for this).
But I add an option to display (or not) the routes on my map. To do so, I remove the layers on my map and I create again the routes I need. It seems to work but if I zoom or move on my map, sometimes a route that I decided not to show appear again as it's selected (but it's not).
It seems that remove the layer is not enough to get rid of the old display. Do you know a way to do it properly ?
Thanks :)