Ticket #328 (closed bug: fixed)

Opened 7 years ago

Last modified 7 years ago

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)

Attachments

layerclone.patch Download (10.5 KB) - added by euzuro 7 years ago.
suggested patch to fix layer.clone() including updated and new tests
layerclone.2.patch Download (10.5 KB) - added by euzuro 7 years ago.
updated…

Change History

Changed 7 years ago by euzuro

  • status changed from new to assigned
  • description modified (diff)

Changed 7 years ago by euzuro

suggested patch to fix layer.clone() including updated and new tests

Changed 7 years ago by euzuro

updated...

Changed 7 years ago by euzuro

patch added... please review this ticket

Changed 7 years ago by crschmidt

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

Reviewed. Looks good, all tests pass, solves bug. Committed, r1662 .

Note: See TracTickets for help on using tickets.