Changeset 7879
- Timestamp:
- 08/27/08 10:02:21 (3 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Handler/Feature.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Layer.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (1 diff)
- trunk/openlayers/tests/Handler/Feature.html (modified) (5 diffs)
- trunk/openlayers/tests/manual/vector-layer-zindex.html (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Handler/Feature.js
r7873 r7879 100 100 */ 101 101 stopUp: false, 102 103 /**104 * Property: layerIndex105 * {Int}106 */107 layerIndex: null,108 102 109 103 /** … … 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.handleMapEvents, 300 "changelayer": this.handleMapEvents, 301 scope: this 302 }); 305 303 activated = true; 306 304 } … … 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: … … 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.handleMapEvents, 325 "changelayer": this.handleMapEvents, 326 scope: this 327 }); 327 328 deactivated = true; 328 329 } 329 330 return deactivated; 331 }, 332 333 /** 334 * Method handleMapEvents 335 * 336 * Parameters: 337 * evt - {Object} 338 */ 339 handleMapEvents: function(evt) { 340 if (!evt.property || evt.property == "order") { 341 this.moveLayerToTop(); 342 } 343 }, 344 345 /** 346 * Method: moveLayerToTop 347 * Moves the layer for this handler to the top, so mouse events can reach 348 * it. 349 */ 350 moveLayerToTop: function() { 351 var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, 352 this.layer.getZIndex()) + 1; 353 this.layer.setZIndex(index); 354 355 }, 356 357 /** 358 * Method: moveLayerBack 359 * Moves the layer back to the position determined by the map's layers 360 * array. 361 */ 362 moveLayerBack: function() { 363 var index = this.layer.getZIndex() - 1; 364 if (index >= this.map.Z_INDEX_BASE['Feature']) { 365 this.layer.setZIndex(index); 366 } else { 367 this.map.setLayerZIndex(this.layer, 368 this.map.getLayerIndex(this.layer)); 369 } 330 370 }, 331 371 trunk/openlayers/lib/OpenLayers/Layer.js
r7874 r7879 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 * trunk/openlayers/lib/OpenLayers/Map.js
r7874 r7879 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 /** trunk/openlayers/tests/Handler/Feature.html
r7682 r7879 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(); … … 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 … … 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; … … 235 235 236 236 handler.active = true; 237 handler.layerIndex = Math.floor(Math.random() * 10);238 237 239 238 deactivated = handler.deactivate(); … … 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 }
