perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.06k stars 347 forks source link

<Question> Change zoom level #680

Open Chiller999 opened 1 year ago

Chiller999 commented 1 year ago

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.

curtisy1 commented 1 year ago

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);
Chiller999 commented 1 year ago

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())?

curtisy1 commented 1 year ago

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

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

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