OpenLayers OpenLayers

Ticket #1032 (closed bug: fixed)

Opened 1 year ago

Last modified 1 year ago

removing a base layer with more resolutions than the next layer causes problems

Reported by: tschaub Assigned to: tschaub
Priority: minor Milestone: 2.6 Release
Component: Map Version: 2.5 RC3
Keywords: Cc:
State:

Description

If layer0 has 5 resolutions and layer1 has 4 resolutions and the map is zoomed to level 4, removing layer0 causes problems. getExtent returns null and getResolution returns null. Any operations that check for properties of the extent trigger an exception.

This example demonstrates:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 512px;
            height: 256px;
            border: 1px solid gray;
        }
    </style>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">

        var map, layer0, layer1;
        function init(){
            
            map = new OpenLayers.Map('map');
            layer0 = new OpenLayers.Layer.WMS(
                "Layer 0", 
                "http://labs.metacarta.com/wms/vmap0",
                {layers: 'basic'},
                {numZoomLevels: 5}
            );

            var options = {numZoomLevels: 4};            
            var layer1 = new OpenLayers.Layer.Image(
                'City Lights',
                'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
                new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
                new OpenLayers.Size(580, 288),
                options
            );
            map.addLayers([layer0, layer1]);
            map.zoomToMaxExtent();
            map.zoomTo(4);
        }
        
    </script>
  </head>
  <body onload="init()">
    <div id="map"></div>
    <a href="javascript: void map.removeLayer(layer0)">click to break</a>
  </body>
</html>

Attachments

resolution.patch (2.7 kB) - added by tschaub on 09/30/07 13:18:33.
rely on resolution instead of zoom

Change History

09/30/07 03:22:46 changed by tschaub

  • keywords set to review.
  • owner set to tschaub.
  • status changed from new to assigned.

Turns out this is a symptom of #1030. Basically, we should be relying on map center and resolution (not zoom and/or extent). This is all related to the stuff in #824.

In the meantime, the resolution patch here fixes this and #1030.

09/30/07 12:00:48 changed by crschmidt

  • keywords changed from review to commit.
  • milestone changed from 2.5 Release to 2.6 Release.

You call getZoomForResolution on map.resolution instead of this.resolution, which works so long as you have a variable named map, but can't (obviously) be depended on. Please change that to 'this'.

Other than that, the patch looks good, and can be put in when you're ready.

However, I'm pushing this to 2.6 -- It's not a regression, and I feel it's a slightly disruptive change that I'd rather have more testing on.

09/30/07 13:11:57 changed by tschaub

Thanks for the review. I've attached a better patch (no map reference and no alert - ack).

09/30/07 13:18:33 changed by tschaub

  • attachment resolution.patch added.

rely on resolution instead of zoom

09/30/07 14:11:29 changed by tschaub

  • keywords deleted.
  • status changed from assigned to closed.
  • resolution set to fixed.

(In [4682]) In changing base layers, we now rely on the old map resolution instead of the old map zoom. This means that for layers with different resolutions arrays, we try to keep the map resolution as consistent as possible (instead of keeping an arbitrary zoom level consistent). This change also fixes a bug that comes up in changing base layers for layers with different length resolution arrays (closes #1032).