Changeset 1604
- Timestamp:
- 10/05/06 15:07:19 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (2 diffs)
- trunk/openlayers/tests/test_Map.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Map.js
r1596 r1604 258 258 /** 259 259 * @param {OpenLayers.Layer} layer 260 * @param {int} zIdx 261 * @private 262 */ 263 setLayerZIndex: function (layer, zIdx) { 264 layer.div.style.zIndex = 265 this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] 266 + zIdx * 5; 267 }, 268 269 /** 270 * @param {OpenLayers.Layer} layer 260 271 */ 261 272 addLayer: function (layer) { 262 273 layer.div.style.overflow = ""; 263 layer.div.style.zIndex = 264 this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay'] 265 + this.layers.length * 5; 274 this.setLayerZIndex(layer, this.layers.length); 266 275 267 276 if (layer.isFixed) { … … 346 355 } 347 356 this.events.triggerEvent("removelayer"); 357 }, 358 359 /** 360 * @returns The number of layers attached to the map. 361 * @type int 362 */ 363 getNumLayers: function () { 364 return this.layers.length; 365 }, 366 367 /** 368 * @returns The current (zero-based) index of the given layer in the map's 369 * layer stack. Returns -1 if the layer isn't on the map. 370 * 371 * @param {OpenLayers.Layer} layer 372 * @type int 373 */ 374 getLayerIndex: function (layer) { 375 return OpenLayers.Util.indexOf(this.layers, layer); 376 }, 377 378 /** Move the given layer to the specified (zero-based) index in the layer 379 * list, changing its z-index in the map display. Use 380 * map.getLayerIndex() to find out the current index of a layer. Note 381 * that this cannot (or at least should not) be effectively used to 382 * raise base layers above overlays. 383 * 384 * @param {OpenLayers.Layer} layer 385 * @param {int} idx 386 */ 387 setLayerIndex: function (layer, idx) { 388 var base = this.getLayerIndex(layer); 389 if (idx < 0) 390 idx = 0; 391 else if (idx > this.layers.length) 392 idx = this.layers.length; 393 if (base != idx) { 394 this.layers.splice(base, 1); 395 this.layers.splice(idx, 0, layer); 396 for (var i = 0; i < this.layers.length; i++) 397 this.setLayerZIndex(this.layers[i], i); 398 this.events.triggerEvent("changelayer"); 399 } 400 }, 401 402 /** Change the index of the given layer by delta. If delta is positive, 403 * the layer is moved up the map's layer stack; if delta is negative, 404 * the layer is moved down. Again, note that this cannot (or at least 405 * should not) be effectively used to raise base layers above overlays. 406 * 407 * @param {OpenLayers.Layer} layer 408 * @param {int} idx 409 */ 410 raiseLayer: function (layer, delta) { 411 var idx = this.getLayerIndex(layer) + delta; 412 this.setLayerIndex(layer, idx); 348 413 }, 349 414 trunk/openlayers/tests/test_Map.html
r1596 r1604 249 249 250 250 } 251 252 function test_12_Map_moveLayer (t) { 253 t.plan(10); 254 var ct = 0; 255 map = new OpenLayers.Map($('map')); 256 var wmslayer = new OpenLayers.Layer.WMS('Test Layer', 257 "http://octo.metacarta.com/cgi-bin/mapserv", 258 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, 259 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } ); 260 261 var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2', 262 "http://octo.metacarta.com/cgi-bin/mapserv", 263 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, 264 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } ); 265 266 var wmslayer3 = new OpenLayers.Layer.WMS('Test Layer2', 267 "http://octo.metacarta.com/cgi-bin/mapserv", 268 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, 269 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } ); 270 271 map.addLayers([wmslayer, wmslayer2, wmslayer3]); 272 map.events.register("changelayer", map, function (e) { ct++; }); 273 t.eq( map.getNumLayers(), 3, "getNumLayers returns the number of layers" ); 274 t.eq( map.getLayerIndex(wmslayer3), 2, "getLayerIndex returns the right index" ); 275 map.raiseLayer(wmslayer3, 1); 276 t.eq( map.getLayerIndex(wmslayer3), 2, "can't moveLayer up past the top of the stack" ); 277 map.raiseLayer(wmslayer, -1); 278 t.eq( map.getLayerIndex(wmslayer), 0, "can't moveLayer down past the bottom of the stack" ); 279 map.raiseLayer(wmslayer3, -1); 280 t.eq( map.getLayerIndex(wmslayer3), 1, "can moveLayer down from the top" ); 281 t.eq( parseInt(wmslayer3.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5, 282 "layer div has the right zIndex after moving down" ); 283 map.raiseLayer(wmslayer, 2); 284 t.eq( map.getLayerIndex(wmslayer), 2, "can moveLayer up from the bottom" ); 285 t.eq( parseInt(wmslayer.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 2 * 5, 286 "layer div has the right zIndex after moving up" ); 287 t.eq( map.getLayerIndex(wmslayer3), 0, "top layer is now on the bottom" ); 288 t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" ); 289 } 251 290 252 function test_08 8_Map_setCenter(t) {291 function test_08_Map_setCenter(t) { 253 292 t.plan(1); 254 293 map = new OpenLayers.Map($('map'));
