Ticket #1448 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

zoomToScale does not exactly zoom to the given scale

Reported by: bartvde Owned by:
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>

Attachments

ticket1448.patch Download (0.8 KB) - added by bartvde 5 years ago.
possible patch that works for me (in the fractionalZoom case)

Change History

Changed 5 years ago by bartvde

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

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

Changed 5 years ago 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?

Changed 5 years ago 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.

Changed 5 years ago 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.

Changed 5 years ago by euzuro

  • milestone set to 2.8 Release

Changed 5 years ago by bartvde

possible patch that works for me (in the fractionalZoom case)

Changed 5 years ago by bartvde

  • milestone changed from 2.8 Release to 2.7 Release

Erik, I am changing this back to the 2.7 release, since this is a serious issue IMHO. I am willing to help with this issue.

Changed 5 years ago by crschmidt

  • status changed from new to closed
  • resolution set to duplicate

Dupe of #1250

Changed 5 years ago by bartvde

  • status changed from closed to reopened
  • resolution duplicate deleted

Chris, I am reopening since this testcase still fails with OL 2.7.

Changed 5 years ago by crschmidt

Bart,

This test case should fail. Are you saying you're passing 'true' as the second argument to zoomToScale and it's still failing?

Changed 5 years ago by crschmidt

  • milestone changed from 2.7 Release to 2.8 Release

Changed 5 years ago by bartvde

Hey Chris, yes even with true it fails:

          map.zoomToScale(100000, true);
          alert(map.getScale());

I get back 250000.00000000003

Changed 4 years ago by bartvde

Ah right, I get it, Erik only implemented for fractionalZoom false .....

Changed 4 years ago by bartvde

I've investigated a bit more on this one, and if the patch to ticket:1863 is applied this should not be an issue anymore AFAICT.

Changed 4 years ago by bartvde

  • status changed from reopened to closed
  • resolution set to fixed

Even without that patch it seems to work fine, so I'm closing this one.

Note: See TracTickets for help on using tickets.