1

I would like to set the zoom on a Leaflet map based on an area (in km^2).

I am looking for a simple function that would approximately convert an area of 510,064,472 km to zoom level 0 and (if I read the table of zoom level at https://wiki.openstreetmap.org/wiki/Zoom_levels correctly) an area of 12,321 to zoom level of about 8.5 and so on.

  • 1
    Shall this function take the aspect ratio of the map container into account as well? The same area in a square map and a rectangular map might need different scales/zoom levels. – IvanSanchez Jul 9 at 6:59
  • If it could take into account the map shape that would be great but I wasn't originally imagining something that sophisticated. – SuprMan Jul 9 at 19:19
0

An approximation of a solution that works up to about zoom level 10:

Math.round(Math.abs(Math.pow(area,1/8.5) - 12))

(Since OSM uses a mercator projection the surface area of the OSM world seems to be closer to 1,500,000,000 KM^2 then 510,064,472)

I don't consider this a good solution and I am still hoping to find a better one.

  • May I remind you that EPSG:3857 (the CRS commonly used to display OSM) is based off a spherical mercator projection, and not on a conical projection. – IvanSanchez Jul 9 at 6:58
  • Thanks for pointing out that error @IvanSanchez. I'm not sure where I got the idea that it was a conical projection but it certainly isn't. – SuprMan Jul 9 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.