Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet: Set initial zoom based on device / resolution

Is there a way to set the initial zoom of a map in Leaflet based on the device / scree resolution?

I'm asking because I'm using Leaflet to display an image instead of a regular map, and need to set a smaller zoom so that the whole "initial screen" is visible on tablets.

Or is there another way to do it besides setting a different zoom?

Thank you!

like image 990
thosetinydreams Avatar asked Oct 24 '25 19:10

thosetinydreams


1 Answers

Use fitBounds instead of setView to center your map, and you can guarantee that the same geographic area will be visible regardless of screen size.

like image 190
tmcw Avatar answered Oct 27 '25 00:10

tmcw