How to convert map scale to web map zoom level

8554
2
12-04-2014 11:56 PM
DavidAglietti
New Contributor III

Hello,

I would like to determine how to a convert specific map scale to the closest zoom scale used by the major web mapping players.  For example, I want to open a web map to whatever predefined scale is closest to 1:100,000 or whatever cached scale is closest.  How do I calculate the zoom level knowing that this is the established breakdown, and that the answer that I'm looking for is 10?:

20 : 1128.497220
19 : 2256.994440
18 : 4513.988880
17 : 9027.977761
16 : 18055.955520
15 : 36111.911040
14 : 72223.822090
13 : 144447.644200
12 : 288895.288400
11 : 577790.576700
10 : 1155581.153000
9  : 2311162.307000
8  : 4622324.614000
7  : 9244649.227000
6  : 18489298.450000
5  : 36978596.910000
4  : 73957193.820000
3  : 147914387.600000
2  : 295828775.300000
1  : 591657550.500000

There must be an elegant way to do this, but my math.foo is weak after all these years of being out of school and withering away in meetings.

Thanks for your help,

Ryan

Tags (1)
0 Kudos
2 Replies
DavidAglietti
New Contributor III

Ah ha!  I found the key to the answer by applying some google-foo, wine, and much confused panic recall of algebra i thought i would never use.    I'll post the answer so I become rich and famous, as all GIS old guys should do.

Here is where I found the logic for the cached map scale logic:

What ratio scales do Google Maps zoom levels correspond to? - Geographic Information Systems Stack E...

and this response led to the answer:

http://gis.stackexchange.com/a/81390

Many thanks to these folks as this would have been impossible for me to figure out on my own.

For posterity in javascript form:

alert(Math.round(Math.log(591657550.500000 /(<your map scale>/2))/Math.log(2)));

This should return an integer value that corresponds to the zoom level (rounded) once you supply the scale.

Try it in JsFiddle:

Edit fiddle - JSFiddle

Hope this helps someone else, I was lost on this one for a time and considered knitting as an alternative career.

D. Ryan

DerrickWestoby1
New Contributor III

This (5 year old) post helped me a lot.  Thanks David! 

calculateconvert_zoom1Testing         log(591657550.500000 div (${map_scale} div 2)) 
calculateconvert_zoom2testing         log(2) 
calculateconvert_zoom3testing         ${convert_zoom1} div ${convert_zoom2} 
calculateweb_zoomtesting         round(${convert_zoom3}, 0) 
0 Kudos