Ticket #328 (closed bug: fixed)
Layer.clone() copies map div dependent resolution settings
| Reported by: | euzuro | Owned by: | euzuro |
|---|---|---|---|
| Priority: | major | Milestone: | 2.2 Release |
| Component: | Layer | Version: | SVN |
| Keywords: | Cc: | ||
| State: |
Description (last modified by euzuro) (diff)
Working in sandbox here branched from r1655
Problem:
Imagine a page with two map divs:
<div id="map1" style="height:500px;width:500px"></div>
<div id="map2" style="height:100px;width:100px"></div>
Now imagine we initialize the maps as follows:
var options = { 'maxResolution': 'auto' };
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'},
options);
var bigMap = new OpenLayers.Map("map1");
bigMap.addLayer(wms);
var smallMap = new OpenLayers.Map("map2");
smallMap.addLayer(wms.clone());
When we call bigMap.addLayer(wms);, OpenLayers.Layer.initResolutions() is called, and will set the wms.resolutions[] array to values based on the 500x500px mapdiv to which it is being added.
When we then call smallMap.addLayer(wms.clone());, OpenLayers.Layer.initResolutions() will be called again, but this time the wms.resolutions[] array will already be populated (from the previous call), and therefore the layer will not recalculate the resolutions array to be based on the new map's smaller 100x100px div.
Solution:
What we will do is the following
- Instead of OpenLayers.Layer.initResolutions() basing its calculations on the properties set directly on the Layer object itself (ie. this.scales, this.resolutions, etc) it will now call those on the layer's options parameter (ie. this.options.scales, this.options.resolutions, etc)

