OpenLayers OpenLayers

Ticket #1448 (new bug)

Opened 4 months ago

Last modified 3 weeks ago

zoomToScale does not exactly zoom to the given scale

Reported by: bartvde Assigned to:
Priority: major Milestone: 2.8 Release
Component: Map Version: 2.5
Keywords: Cc:
State:

Description

You can try the following example to reproduce. zoomToScale 1:100000 will actually zoom to 1:250000.

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
    <style type="text/css">
        #map {
            width: 512px;
            height: 512px;
            border: 1px solid black;
        }
    </style>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var lon = 5;
        var lat = 40;
        var zoom = 5;
        var map, layer;

        function init(){
          map = new OpenLayers.Map( 'map', { 'controls': [], fractionalZoom: true, 'projection': 'EPSG:28992', 'units':'m',
            'maxExtent': new OpenLayers.Bounds(-200000,0,600000,900000),
            'scales': [10000000, 5000000, 2000000, 1500000, 1000000, 750000, 500000, 375000, 250000, 100000, 50000,
              25000, 10000, 5000, 2500, 1000, 500, 100]});
          var graphic = new OpenLayers.Layer.Image('Dummy', '../img/blank.gif', new OpenLayers.Bounds(0,300000,300000,600000),
              map.getSize(), {isBaseLayer: true, displayInLayerSwitcher: false});
          map.addLayer(graphic);
          map.zoomToMaxExtent();
          map.addControl(new OpenLayers.Control.Scale());
          map.zoomToScale(100000);
          alert(map.getScale());
        }
    </script>
  </head>
  <body onload="init()">
    <div id="map"></div>
  </body>
</html>

Change History

03/19/08 09:30:37 changed by bartvde

This seems to be a significant digits problem in getZoomForResolution in Layer.js.

Resolution: 35.27775872778807
And map.resolutions[9]: 35.27775872778806

03/19/08 17:09:26 changed by tschaub

I assume this would be a problem with or without fractionalZoom. The scale -> resolution conversions would all suffer from this significant digits problem. Didn't we open another ticket with scale sig.dig. related issues?

04/08/08 10:41:07 changed by pgiraud

I can confirm that this is not related to fractionalZoom. I'm facing the same problem when zooming to scale 2'500'000 in similar example.

04/08/08 10:46:18 changed by bartvde

  • summary changed from zoomToScale does not exactly zoom to the given scale (fractionalZoom) to zoomToScale does not exactly zoom to the given scale.

Updating the summary since this does not relate to fractionalZoom.

07/04/08 02:25:04 changed by euzuro

  • milestone set to 2.8 Release.