Ticket #3485 (closed bug: fixed)

Opened 21 months ago

Last modified 21 months ago

Zoom level mismatch with Layer.Bing and overlays

Reported by: nrenner Owned by: ahocever
Priority: major Milestone: 2.12 Release
Component: Layer.Bing Version: 2.11 RC3
Keywords: Cc:
State: Commit

Description

When adding an overlay to a map with Bing tiles as base layer, the two layers have different zoom levels. Tile request URLs for the overlay are calculated with the wrong zoom level and therefore the overlay doesn't align with the base map.

A live example can viewed at:
 http://sautter.com/map/?zoom=4&lat=50.82333&lon=4.59951&layers=0000B00TFFFFFFFF

To reproduce, add the following lines to examples/bing-tiles.js (tested with 2.11 RC3 on Windows XP with Firefox 6.0.1):

  var osm = new OpenLayers.Layer.OSM();
  osm.isBaseLayer = false;
  osm.opacity = 0.5;
  map.addLayer(osm);

The OSM overlay gets initialized properly when debugging XYZ.getXYZ with a breakpoint at line 151:

  this.map.getResolution() = 76.43702827453613
  this.map.getZoom() = 11

By adding the condition "z == 10" to the breakpoint, you can see that a refresh after the Bing initialization goes wrong because the zoom and resolution don't match:

  this.map.getResolution() = 76.43702827453613
  this.map.getZoom() = 10

The reason seems to be, that within Bing.initLayer Layer.getZoomForResolution gets called, which determines the current zoom level based on the resolutions array. The Bing layer has a zoomOffset of 1, so in this case resolutions is only a subset of serverResolutions, thus the determined zoom level is relative to zoomOffset/maxResolution and doesn't fit to other layers with different settings.

I think this was introduced with changeset:12106; with RC1 Bing worked OK with overlays, which are broken since RC2.

Attachments

openlayers-3485.patch Download (0.7 KB) - added by ahocevar 21 months ago.

Change History

Changed 21 months ago by bartvde

I can confirm this issue is indeed introduced somewhere in the OL 2.11 RC process, in RC1 it was still working.

Changed 21 months ago by bartvde

It seems to me that the minResolution gets set wrong on the Bing layer, in the latest 2.11 RC it's 0.29858214169740677 but it RC1 it's 0.07464553542435169. Same goes for maxResolution, also different.

Changed 21 months ago by bartvde

The following change removes the offset, however when zooming to max extent it now gets one level too far:

Index: ../lib/OpenLayers/Layer/Bing.js
===================================================================
--- ../lib/OpenLayers/Layer/Bing.js	(revision 12328)
+++ ../lib/OpenLayers/Layer/Bing.js	(working copy)
@@ -142,7 +142,7 @@
         };
         this.addOptions({
             maxResolution: Math.min(
-                this.serverResolutions[res.zoomMin], this.maxResolution
+                this.serverResolutions[0], this.maxResolution
             ),
             zoomOffset: res.zoomMin,
             numZoomLevels: Math.min(

Changed 21 months ago by bartvde

I guess since we are providing serverResolutions now, it is not necessary anymore to supply zoomOffset right? Also, numZoomLevels seems to be off as well (19 instead of 22), I wonder why it was not kept at the original value of res.zoomMax + 1?

Andreas/Tim, are you able to shed some light on this issue? TIA.

Changed 21 months ago by ahocevar

This issue was introduced with r12106.

Changed 21 months ago by ahocevar

@bartvde: minResolution and maxResolution are correct after r12106.

Changed 21 months ago by ahocevar

Changed 21 months ago by ahocevar

  • state set to Review

openlayers-3485.patch Download makes the getXYZ method also consider the resolutions array if no zoomOffset is provided. This saves us from needing to specify serverResolutions if they are the same as the resolutions array. All tests still pass. Thanks for any review.

Changed 21 months ago by ahocevar

  • milestone changed from 2.11 Release to 2.12 Release

Changed 21 months ago by bartvde

  • state changed from Review to Commit

Great solution Andreas, I've confirmed this fixes the issue reported and verified that it did not break any test in Safari 5.1. Please commit.

Changed 21 months ago by ahocevar

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

(In [12357]) also consider the resolutions array if no zoomOffset is provided. r=bartvde (closes #3485)

Changed 21 months ago by ahocevar

r12357 contained some accidently committed changes, which were reverted with r12358.

Note: See TracTickets for help on using tickets.