# How to calculate the scale of current Zoom Level with parameters like extent, resolution?

I got the following parameters:

``````Width and height of Map: 450px, 560px

units : 'meters'

maxExtent : new OpenLayers.Bounds(806677.9759,802420.9858,8876817.5647,853497.8186405064)

resolutions: [199.51887828322785, 99.75943914161392, 49.87971957080696,
24.93985978540348, 12.46992989270174, 6.23496494635087, 3.117482473175435,
1.5587412365877176, 0.7793706182938588, 0.3896853091469294, 0.1948426545734647,
0.09742132728673235, 0.048710663643366174, 0.024355331821683087, 0.012177665910841544,
0.006088832955420772, 0.003044416477710386, 0.001522208238855193]

numZoomLevels: 18

OpenLayers.DOTS_PER_INCH = 90.71428571428572;
``````

Who inspire me how to calculate the scale of current Zoom Level?

-

There is a good information on Peter Robins website which may help you easily with openlayers.

To find the scale a resolution represents, you have to know how big a pixel is; OL doesn't know that for sure, but makes some reasonable assumptions. If you look at Util.js, and search for getScaleFromResolution(), you will find that it uses 2 constants, INCHES_PER_UNIT and DOTS_PER_INCH, and the calculation is "resolution * OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH". For degrees this is resolution*4374754*72 (314,982,288), so the maximum scale is 1:442,943,843. In metres, the maximum scale is 156543.0339*39.3701*72 (2,834.6472) or 1:443,744,273.

so the formule :

`````` map.getResolutions * OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH
``````

i hope it helps you...

-
Thanks a lot. Aragon – Brady Jul 19 '12 at 7:30

Map scale is defined as a ratio of `displayed units / measured units`. Your specific case is a bit harder given that we have to traverse through two scales and two different units in order to arrive at the real world units.

Assuming horizontal scale is equivalent to vertical scale, we first look at the horizontal pixel resolution. By this we're attempting to find the displayed units pixel:

``````scale = display / measured

= feature / pixels

= |(806677m - 876817m)| / 450px // I'm assuming you've made a typo with 8876817

= 70140 / 450

= 166.66 metres per pixel (inversely 0.006 pixels per metre)
``````

Secondly, converting the pixel scale to find the screen distance per pixel:

``````      = real distance / pixel distance

= 2.54cm (1 inch) / 90 pixels

= 0.028 ~0.03
``````

Bringing it all together:

``````   0.028 cm per pixel = 166.66 metres / x

x * 0.028 = 166.66

x = 166.66 / 0.028

x = 5952.1
``````

Therefore, your map scale is roughly 1:6000.

-