2
votes

I'm using leaflet to generate a route and display the route on the map. When I make another route, I want to delete the previous from the map and add the new one, but when I start to move the map, with the mouse and zoom controls I get the following error;

leaflet-routing-machine.min.js:3 Uncaught TypeError: Cannot read property 'getZoom' of null

here is my code;

if (routeControl != null){
routeControl.removeFrom(map);}

routeControl = new L.Routing.Control({
waypoints: setWaypoints,
show:false,
}).addTo(map);

thanks in advance

1

1 Answers

0
votes

I solved it by using routeControl.setWaypoints(setWaypoints); instead of trying to remove the control and adding a new one.