perliedman/leaflet-routing-machine

<Question> Change zoom level

Chiller999 opened this issue · 4 comments

Hi there,
I didn't find some option to customize the zoom level.

I don't wanne use manual zooming&centering. I would like to use the fitSelectedRoutes true defaults but zooming out one step.
Background: I am using custom markers and they are cutting of :(

Thanks for any help or suggestions.

Leaflet maps offer a zoomOut or setZoom function which you could use.

Suppose you have a simple map, you could do something like this

const map = new L.Map(); // your init logic goes here
const currentZoom = map.getZoom();
map.setZoom(currentZoom - 1);

Thanks for this suggestion! It is only working after L.Routing.control(...).addTo(map); is finished.
So I put zoomOut inside a setTimeout. But is there any better option? For example like ...addTo(map).finished(zoomOut())?

Leaflet maps fire a load event which tells you when the map is ready.

map.on('load', () => {
    map.setZoom(map.getZoom() - 1);
});

Thanks, that's what I was searching for. But sad, that it is not possible to modify the fitting directly.