Ticket #1628: 1628-r7874.B2.patch
| File 1628-r7874.B2.patch, 11.8 kB (added by ahocevar, 4 months ago) |
|---|
-
tests/Handler/Feature.html
old new 30 30 } 31 31 32 32 function test_Handler_Feature_activate(t) { 33 t.plan( 4);33 t.plan(3); 34 34 var map = new OpenLayers.Map('map'); 35 35 var control = new OpenLayers.Control(); 36 36 map.addControl(control); … … 47 47 activated = handler.activate(); 48 48 t.ok(activated, 49 49 "activate returns true if the handler was not already active"); 50 t.eq(handler.layerIndex, zIndex,51 "layerIndex property properly set");52 50 t.eq(parseInt(layer.div.style.zIndex), 53 map.Z_INDEX_BASE[' Popup'] - 1,51 map.Z_INDEX_BASE['Feature'], 54 52 "layer z-index properly adjusted"); 55 53 56 54 } … … 227 225 map.addControl(control); 228 226 var layer = new OpenLayers.Layer(); 229 227 map.addLayer(layer); 228 var layerIndex = parseInt(layer.div.style.zIndex); 229 230 230 var handler = new OpenLayers.Handler.Feature(control, layer); 231 231 handler.active = false; 232 232 var deactivated = handler.deactivate(); … … 234 234 "deactivate returns false if the handler was not already active"); 235 235 236 236 handler.active = true; 237 handler.layerIndex = Math.floor(Math.random() * 10);238 237 239 238 deactivated = handler.deactivate(); 240 239 t.ok(deactivated, 241 240 "deactivate returns true if the handler was active already"); 242 241 t.eq(parseInt(layer.div.style.zIndex), 243 handler.layerIndex,242 layerIndex, 244 243 "deactivate sets the layer z-index back"); 245 244 } 246 245 -
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, selectControl1, selectControl2; 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 selectControl1 = new OpenLayers.Control.SelectFeature(layerV); 43 selectControl2 = new OpenLayers.Control.SelectFeature(layerV, { 44 hover: true, 45 selectStyle: OpenLayers.Util.applyDefaults({fillColor: "red"}, OpenLayers.Feature.Vector.style["select"]), 46 onSelect: function(feature) { 47 selectControl2.unselect(feature); 48 layerV.drawFeature(feature, selectControl2.selectStyle); 49 } 50 }); 51 selectControl2.events.register("beforefeatureselected", null, function(feature) { 52 layerV.drawFeature(feature, selectControl2.selectStyle); 53 return false; 54 }) 55 56 layerA = new OpenLayers.Layer('a', {'isBaseLayer': false}); 57 layerB = new OpenLayers.Layer.WMS( 58 'b', 'http://www2.dmsolutions.ca/cgi-bin/mswms_gmap', { 59 'layers': [ 60 'bathymetry', 'land_fn', 'park', 'drain_fn', 'drainage', 61 'prov_bound', 'fedlimit', 'rail', 'road', 'popplace' 62 ], 63 'transparent': 'true', 64 'format': 'image/png' 65 }, { 66 'reproject': false 67 }); 68 69 map.addLayers([wmsLayer, layerV, layerA, layerB]); 70 map.addControl(selectControl2); 71 map.addControl(selectControl1); 72 map.addControl(new OpenLayers.Control.MousePosition()); 73 selectControl2.activate(); 74 selectControl1.activate(); 75 76 map.setCenter(new OpenLayers.LonLat(-90, 20), 2); 77 } 78 79 function removeLayerA() { 80 if (OpenLayers.Util.indexOf(map.layers, layerA) > -1) { 81 map.removeLayer(layerA); 82 } 83 } 84 85 function toggleSelectControl1() { 86 if (selectControl1.active) { 87 selectControl1.deactivate(); 88 alert("SelectFeature control for clicks deactivated."); 89 } else { 90 selectControl1.activate(); 91 alert("SelectFeature control for clicks activated."); 92 } 93 } 94 95 function toggleSelectControl2() { 96 if (selectControl2.active) { 97 selectControl2.deactivate(); 98 alert("SelectFeature control for hover deactivated."); 99 } else { 100 selectControl2.activate(); 101 alert("SelectFeature control for hover activated."); 102 } 103 } 104 </script> 105 </head> 106 <body onload="init()"> 107 <h1 id="title">Vector Layer ZIndex Test</h1> 108 <div id="map"></div> 109 <p> 110 111 The map includes one base layer (vmap0) and three overlays, namely a vector 112 layer, a fake layer with no images, and a dmsolutions layer. The overlays are 113 added to the map in this order: the vector layer, the fake layer, and the 114 dmsolutions layer. The map also includes a select feature control, which 115 when activated bumped the vector layer z-index to some high value. This 116 makes feature selection work, even though other overlays were added after 117 the vector layer. 118 119 </p> 120 <p> 121 122 If the fake layer is removed from the map (first link below), the vector layer's 123 z-index must not be reset, so the vector layer must not go under the 124 dmsolutions layer and feature selection must continue to function as 125 expected. 126 127 </p> 128 <p> 129 130 If one of the SelectFeature controls is deactivated or activated (second 131 and third link below), the vector layer should change it's position in the 132 layer stack: on top if at least one of the controls is activated, covered 133 by other layers if both are deactivated. 134 135 </p> 136 137 <p> 138 <a href="javascript:removeLayerA()">Remove the fake layer</a> 139 <br/><a href="javascript:toggleSelectControl1()">Toggle the click SelectFeature control's active status</a> 140 <br/><a href="javascript:toggleSelectControl2()">Toggle the hover SelectFeature control's active status</a> 141 </p> 142 </body> 143 </html> -
lib/OpenLayers/Map.js
old new 23 23 * Constant: Z_INDEX_BASE 24 24 * {Object} Base z-indexes for different classes of thing 25 25 */ 26 Z_INDEX_BASE: { BaseLayer: 100, Overlay: 325, Popup: 750, Control: 1000 }, 26 Z_INDEX_BASE: { 27 BaseLayer: 100, 28 Overlay: 325, 29 Feature: 725, 30 Popup: 750, 31 Control: 1000 32 }, 27 33 28 34 /** 29 35 * Constant: EVENT_TYPES -
lib/OpenLayers/Layer.js
old new 1099 1099 }, 1100 1100 1101 1101 /** 1102 * Method: getZIndex 1103 * 1104 * Returns: 1105 * {Integer} the z-index of this layer 1106 */ 1107 getZIndex: function () { 1108 return this.div.style.zIndex; 1109 }, 1110 1111 /** 1102 1112 * Method: setZIndex 1103 1113 * 1104 1114 * Parameters: -
lib/OpenLayers/Handler/Feature.js
old new 99 99 * value of stopUp. Defaults to false. 100 100 */ 101 101 stopUp: false, 102 103 /**104 * Property: layerIndex105 * {Int}106 */107 layerIndex: null,108 102 109 103 /** 110 104 * Constructor: OpenLayers.Handler.Feature … … 300 294 activate: function() { 301 295 var activated = false; 302 296 if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 303 this.layerIndex = this.layer.div.style.zIndex; 304 this.layer.div.style.zIndex = this.map.Z_INDEX_BASE['Popup'] - 1; 297 this.moveLayerToTop(); 298 this.map.events.on({ 299 "removelayer": this.moveLayerToTop, 300 "changelayer": this.moveLayerToTop, 301 scope: this 302 }); 305 303 activated = true; 306 304 } 307 305 return activated; 308 306 }, 309 307 310 308 /** 311 * Method: activate312 * Turn of the handler. Returns false if the handler was already active.309 * Method: deactivate 310 * Turn off the handler. Returns false if the handler was already active. 313 311 * 314 312 * Returns: 315 313 * {Boolean} … … 317 315 deactivate: function() { 318 316 var deactivated = false; 319 317 if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 320 if (this.layer && this.layer.div) { 321 this.layer.div.style.zIndex = this.layerIndex; 322 } 318 this.moveLayerBack(); 323 319 this.feature = null; 324 320 this.lastFeature = null; 325 321 this.down = null; 326 322 this.up = null; 323 this.map.events.un({ 324 "removelayer": this.moveLayerToTop, 325 "changelayer": this.moveLayerToTop, 326 scope: this 327 }); 327 328 deactivated = true; 328 329 } 329 330 return deactivated; 330 331 }, 332 333 /** 334 * Method: moveLayerToTop 335 * Moves the layer for this handler to the top, so mouse events can reach 336 * it. 337 */ 338 moveLayerToTop: function() { 339 var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, 340 this.layer.getZIndex()) + 1; 341 this.layer.setZIndex(index); 342 }, 343 344 /** 345 * Method: moveLayerBack 346 * Moves the layer back to the position determined by the map's layers 347 * array. If used as event handler for the changelayer event, this will 348 * only happen when the layer order has changed. 349 * 350 * Parameters: 351 * evt - {Object} Optional. 352 */ 353 moveLayerBack: function(evt) { 354 if (!evt || evt.property == "order") { 355 var index = this.layer.getZIndex() - 1; 356 if (index >= this.map.Z_INDEX_BASE['Feature']) { 357 this.layer.setZIndex(index); 358 } else { 359 this.map.setLayerZIndex(this.layer, 360 this.map.getLayerIndex(this.layer)); 361 } 362 } 363 }, 331 364 332 365 CLASS_NAME: "OpenLayers.Handler.Feature" 333 366 });
