9

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?

0

3 Answers 3

16

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.

5
  • Greatly appreciated for your extremely detailed description. I will calculate it follow your way. Thanks.
    – Brady
    Jul 19, 2012 at 4:27
  • No problem. If you're calculating the scale repeatedly, you may want to condense the equation. I've only layered it for you out of simplicity.
    – nagytech
    Jul 19, 2012 at 4:53
  • Haha, Yes! Actually, I want to know what the Zoom Level is for the scale value '1:3500'. Because some layer in my map display only when current scale is greater '1:3500'. BTW, I'm a new in GIS.
    – Brady
    Jul 19, 2012 at 5:07
  • 1
    There is (of course) a strong dependence on getting the right pixel distance. So it won't be the same "scale" on your notebook and the attached projector.
    – BradHards
    Jul 19, 2012 at 9:58
  • 4
    There is a mistake in the answer of nagytech, because he compares m per pixel to cm per pixel! At first you have to convert the 0.028cm to meter! So you have 0.00028 meters and a scale of x = 166.66 / 0.00028 = 595214!
    – marcel
    Nov 10, 2014 at 9:39
9

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...

1
  • In OpenLayers 2.14 map.getResolutions did not work for me, but getting the resolutions of the base layer did: map.baseLayer.resolutions. Keep in mind, however, this may result in more values than there are zoom levels...
    – abettermap
    Dec 21, 2017 at 17:46
0

scale and zoom level can be convert by following table.

regardless of extend and resolution

https://developers.arcgis.com/documentation/mapping-apis-and-services/reference/zoom-levels-and-scale/

enter image description here

https://wiki.openstreetmap.org/wiki/Zoom_levels

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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