OpenLayers OpenLayers

Ticket #1628: patch-1628-r7554-A0.diff

File patch-1628-r7554-A0.diff, 7.3 kB (added by elemoine, 6 months ago)
  • tests/Map.html

    old new  
    676676    } 
    677677 
    678678    function test_Map_removeLayer_zindex(t) { 
    679         t.plan(2); 
     679        t.plan(3); 
    680680         
    681681        map = new OpenLayers.Map('map'); 
    682682 
    683683        var layer0 = new OpenLayers.Layer('Test Layer 0', {isBaseLayer:true}); 
    684684        var layer1 = new OpenLayers.Layer('Test Layer 1', {isBaseLayer:true}); 
    685         var layer2 = new OpenLayers.Layer('Test Layer 2', {isBaseLayer:false}); 
     685        var layer2 = new OpenLayers.Layer.Vector('Test layer 2', {isBalseLayer: false, noZIndexReset: 1}); 
     686        var layer3 = new OpenLayers.Layer('Test Layer 3', {isBaseLayer:false}); 
    686687 
    687         map.addLayers([layer0, layer1, layer2]); 
     688        map.addLayers([layer0, layer1, layer2, layer3]); 
     689 
     690        layer2.div.style.zIndex = map.Z_INDEX_BASE['Popup'] - 1; 
     691 
    688692        map.removeLayer(layer0); 
    689693 
    690694        t.eq(parseInt(layer1.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'], 
    691695             "correct z-index after removeLayer"); 
    692         t.eq(parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['Overlay'] + 5
     696        t.eq(parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['Popup'] - 1
    693697             "correct z-index after removeLayer"); 
     698        t.eq(parseInt(layer3.div.style.zIndex), map.Z_INDEX_BASE['Overlay'] + 10, 
     699             "correct z-index after removeLayer"); 
    694700    } 
    695701 
    696702    function test_Map_setBaseLayer_after_pan (t) { 
  • tests/manual/vector-layer-zindex.html

    old new  
     1<html xmlns="http://www.w3.org/1999/xhtml"> 
     2  <head> 
     3    <title>Vector Layer ZIndex Test</title> 
     4    <style type="text/css"> 
     5        body { 
     6            font-size: 0.8em; 
     7        } 
     8        p { 
     9            padding-top: 1em; 
     10        } 
     11        #map { 
     12            margin: 1em; 
     13            width: 512px; 
     14            height: 512px; 
     15        } 
     16    </style> 
     17 
     18    <script src="../../lib/OpenLayers.js"></script> 
     19    <script type="text/javascript"> 
     20        var map, layerA, layerB, layerV; 
     21 
     22        function init() { 
     23            map = new OpenLayers.Map('map'); 
     24            var wmsLayer = new OpenLayers.Layer.WMS( 
     25                "OpenLayers WMS",  
     26                "http://labs.metacarta.com/wms/vmap0", 
     27                {layers: 'basic'} 
     28            ); 
     29 
     30            layerV = new OpenLayers.Layer.Vector('v'); 
     31            var feature = new OpenLayers.Feature.Vector( 
     32                new OpenLayers.Geometry.Polygon([ 
     33                    new OpenLayers.Geometry.LinearRing([ 
     34                        new OpenLayers.Geometry.Point(-110, 60), 
     35                        new OpenLayers.Geometry.Point(-110, 30), 
     36                        new OpenLayers.Geometry.Point(-80, 30), 
     37                        new OpenLayers.Geometry.Point(-110, 60) 
     38                    ]) 
     39                ]) 
     40            ); 
     41            layerV.addFeatures([feature]); 
     42            var selectControl = new OpenLayers.Control.SelectFeature(layerV); 
     43 
     44            layerA = new OpenLayers.Layer('a', {'isBaseLayer': false}); 
     45            layerB = new OpenLayers.Layer.WMS( 
     46                'b', 'http://www2.dmsolutions.ca/cgi-bin/mswms_gmap', { 
     47                    'layers': [ 
     48                        'bathymetry', 'land_fn', 'park', 'drain_fn', 'drainage', 
     49                        'prov_bound', 'fedlimit', 'rail', 'road', 'popplace' 
     50                    ], 
     51                    'transparent': 'true', 
     52                    'format': 'image/png' 
     53                }, { 
     54                    'reproject': false 
     55            }); 
     56 
     57            map.addLayers([wmsLayer, layerV, layerA, layerB]); 
     58            map.addControl(selectControl); 
     59            map.addControl(new OpenLayers.Control.MousePosition()); 
     60            selectControl.activate(); 
     61 
     62            map.setCenter(new OpenLayers.LonLat(-90, 20), 2); 
     63        } 
     64 
     65        function removeLayerA() { 
     66            if (OpenLayers.Util.indexOf(map.layers, layerA) > -1) { 
     67                map.removeLayer(layerA); 
     68            } 
     69        } 
     70    </script> 
     71  </head> 
     72  <body onload="init()"> 
     73    <h1 id="title">Vector Layer ZIndex Test</h1> 
     74    <div id="map"></div> 
     75    <p> 
     76 
     77    The map includes one base layer (vmap0) and three overlays, namely a vector 
     78    layer, a fake layer with no images, and a dmsolutions layer. The overlays are 
     79    added to the map in this order: the vector layer, the fake layer, and the 
     80    dmsolutions layer. The map also includes a select feature control, which 
     81    when activated bumped the vector layer z-index to some high value. This 
     82    makes feature selection work, even though other overlays were added after 
     83    the vector layer. 
     84        
     85    </p> 
     86    <p> 
     87 
     88    If the fake layer is removed from the map (link below), the vector layer's 
     89    z-index must not be reset, so the vector layer must not go under the 
     90    dmsolutions layer and feature selection must continue to function as 
     91    expected. 
     92 
     93    </p> 
     94 
     95    <p> 
     96      <a href="javascript:removeLayerA()">Remove the fake layer</a> 
     97    </p> 
     98  </body> 
     99</html> 
  • lib/OpenLayers/Map.js

    old new  
    769769    resetLayersZIndex: function() { 
    770770        for (var i = 0; i < this.layers.length; i++) { 
    771771            var layer = this.layers[i]; 
    772             this.setLayerZIndex(layer, i); 
     772            if (layer.noZIndexReset <= 0) { 
     773                this.setLayerZIndex(layer, i); 
     774            } 
    773775        } 
    774776    }, 
    775777 
  • lib/OpenLayers/Layer.js

    old new  
    277277     *     transitionEffect values. 
    278278     */ 
    279279    SUPPORTED_TRANSITIONS: ['resize'], 
    280      
     280 
    281281    /** 
     282     * Property: noZIndexReset 
     283     * {Number} If noZIndexReset is greater than 0 the layer z-index won't 
     284     * be reset by the map. Defaults to 0. 
     285     */ 
     286    noZIndexReset: 0, 
     287 
     288    /** 
    282289     * Constructor: OpenLayers.Layer 
    283290     * 
    284291     * Parameters: 
  • lib/OpenLayers/Handler/Feature.js

    old new  
    299299        if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 
    300300            this.layerIndex = this.layer.div.style.zIndex; 
    301301            this.layer.div.style.zIndex = this.map.Z_INDEX_BASE['Popup'] - 1; 
     302            this.layer.noZIndexReset++; 
    302303            activated = true; 
    303304        } 
    304305        return activated; 
     
    314315    deactivate: function() { 
    315316        var deactivated = false; 
    316317        if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 
    317             if (this.layer && this.layer.div) { 
    318                 this.layer.div.style.zIndex = this.layerIndex; 
     318            if (this.layer) { 
     319                if (this.layer.div) { 
     320                    this.layer.div.style.zIndex = this.layerIndex; 
     321                } 
     322                this.layer.noZIndexReset--; 
    319323            } 
    320324            this.feature = null; 
    321325            this.lastFeature = null;