Changeset 2234
- Timestamp:
- 02/16/07 16:10:02 (2 years ago)
- Files:
-
- branches/openlayers/2.3/lib/OpenLayers/Layer.js (modified) (1 diff)
- branches/openlayers/2.3/lib/OpenLayers/Map.js (modified) (6 diffs)
- branches/openlayers/2.3/lib/OpenLayers/Tile/Image.js (modified) (3 diffs)
- branches/openlayers/2.3/lib/OpenLayers/Util.js (modified) (3 diffs)
- branches/openlayers/2.3/tests/grid_inittiles.html (modified) (1 diff)
- branches/openlayers/2.3/tests/test_Util.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/openlayers/2.3/lib/OpenLayers/Layer.js
r2230 r2234 138 138 * Destroy is a destructor: this is to alleviate cyclic references which 139 139 * the Javascript garbage cleaner can not take care of on its own. 140 */ 141 destroy: function() { 140 * 141 * @param {Boolean} setNewBaseLayer Should a new baselayer be selected when 142 * this has been removed? 143 * Default is true 144 */ 145 destroy: function(setNewBaseLayer) { 146 if (setNewBaseLayer == null) { 147 setNewBaseLayer = true; 148 } 142 149 if (this.map != null) { 143 this.map.removeLayer(this );150 this.map.removeLayer(this, setNewBaseLayer); 144 151 } 145 152 this.map = null; branches/openlayers/2.3/lib/OpenLayers/Map.js
r2181 r2234 77 77 /** @type int */ 78 78 zoom: 0, 79 80 /** Used to store a unique identifier that changes when the map view 81 * changes. viewRequestID should be used when adding data asynchronously 82 * to the map: viewRequestID is incremented when you initiate your 83 * request (right now during changing of baselayers and changing of zooms). 84 * It is stored here in the map and also in the data that will be coming 85 * back asynchronously. Before displaying this data on request completion, 86 * we check that the viewRequestID of the data is still the same as that 87 * of the map. Fix for #480 88 * 89 * @type String */ 90 viewRequestID: 0, 79 91 80 92 // Options … … 202 214 if (this.layers != null) { 203 215 for(var i=0; i< this.layers.length; i++) { 204 this.layers[i].destroy(); 216 //pass 'false' to destroy so that map wont try to set a new 217 // baselayer after each baselayer is removed 218 this.layers[i].destroy(false); 205 219 } 206 220 this.layers = null; … … 345 359 * 346 360 * @param {OpenLayers.Layer} layer 347 */ 348 removeLayer: function(layer) { 361 * @param {Boolean} setNewBaseLayer Default is true 362 */ 363 removeLayer: function(layer, setNewBaseLayer) { 364 if (setNewBaseLayer == null) { 365 setNewBaseLayer = true; 366 } 367 349 368 if (layer.isFixed) { 350 369 this.viewPortDiv.removeChild(layer.div); … … 356 375 357 376 // if we removed the base layer, need to set a new one 358 if ( this.baseLayer == layer) {377 if (setNewBaseLayer && (this.baseLayer == layer)) { 359 378 this.baseLayer = null; 360 379 for(i=0; i < this.layers.length; i++) { … … 449 468 // set new baselayer and make it visible 450 469 this.baseLayer = newBaseLayer; 470 471 // Increment viewRequestID since the baseLayer is 472 // changing. This is used by tiles to check if they should 473 // draw themselves. 474 this.viewRequestID++; 451 475 this.baseLayer.setVisibility(true, noEvent); 452 476 … … 744 768 this.popups[i].updatePosition(); 745 769 } 770 771 // zoom level has changed, increment viewRequestID. 772 this.viewRequestID++; 746 773 } 747 774 branches/openlayers/2.3/lib/OpenLayers/Tile/Image.js
r2181 r2234 35 35 if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) { 36 36 this.layer.div.removeChild(this.imgDiv); 37 this.imgDiv.map = null; 37 38 } 38 39 this.imgDiv = null; … … 53 54 this.initImgDiv(); 54 55 } 56 57 this.imgDiv.viewRequestID = this.layer.map.viewRequestID; 55 58 56 59 this.url = this.layer.getURL(this.bounds); … … 133 136 this.layer.opacity); 134 137 } 138 139 // we need this reference to check back the viewRequestID 140 this.imgDiv.map = this.layer.map; 141 135 142 }, 136 143 branches/openlayers/2.3/lib/OpenLayers/Util.js
r2230 r2234 218 218 219 219 OpenLayers.Util.onImageLoad = function() { 220 this.style.backgroundColor = null; 221 this.style.display = ""; 220 // The complex check here is to solve issues described in #480. 221 // Every time a map view changes, it increments the 'viewRequestID' 222 // property. As the requests for the images for the new map view are sent 223 // out, they are tagged with this unique viewRequestID. 224 // 225 // If an image has no viewRequestID property set, we display it regardless, 226 // but if it does have a viewRequestID property, we check that it matches 227 // the viewRequestID set on the map. 228 // 229 // If the viewRequestID on the map has changed, that means that the user 230 // has changed the map view since this specific request was sent out, and 231 // therefore this tile does not need to be displayed (so we do not execute 232 // this code that turns its display on). 233 // 234 if (!this.viewRequestID || 235 (this.viewRequestID == this.map.viewRequestID)) { 236 this.style.backgroundColor = null; 237 this.style.display = ""; 238 } 222 239 }; 223 240 … … 378 395 * http parameter notation. 379 396 * (ex. <i>"key1=value1&key2=value2&key3=value3"</i>) 397 * If a parameter is actually a list, that parameter will then 398 * be set to a comma-seperated list of values (foo,bar) instead 399 * of being URL escaped (foo%3Abar). 380 400 * @type String 381 401 */ … … 384 404 385 405 for (var key in params) { 386 var value = params[key]; 387 if ((value != null) && (typeof value != 'function')) { 388 paramsArray.push(encodeURIComponent(key) + "=" + 389 encodeURIComponent(value)); 390 } 406 var value = params[key]; 407 if ((value != null) && (typeof value != 'function')) { 408 var encodedValue; 409 if (typeof value == 'object' && value.constructor == Array) { 410 /* value is an array; encode items and separate with "," */ 411 var encodedItemArray = new Array(); 412 for (var itemIndex=0; itemIndex<value.length; itemIndex++) { 413 encodedItemArray.push(encodeURIComponent(value[itemIndex])); 414 } 415 encodedValue = encodedItemArray.join(","); 416 } 417 else { 418 /* value is a string; simply encode */ 419 encodedValue = encodeURIComponent(value); 420 } 421 paramsArray.push(encodeURIComponent(key) + "=" + encodedValue); 422 } 391 423 } 392 424 branches/openlayers/2.3/tests/grid_inittiles.html
r2230 r2234 12 12 <!-- 13 13 function init(){ 14 map = new OpenLayers.Map('map', {'maxResolution': 1.40625/2, tileSize: new OpenLayers.Size(256,256)});14 var map = new OpenLayers.Map('map', {'maxResolution': 1.40625/2, tileSize: new OpenLayers.Size(256,256)}); 15 15 ww = new OpenLayers.Layer.WMS( "Basic", 16 16 "http://labs.metacarta.com/wms-c/Basic.py?", branches/openlayers/2.3/tests/test_Util.html
r2181 r2234 178 178 179 179 function test_07_Util_getParameterString(t) { 180 t.plan( 2);180 t.plan( 4 ); 181 181 182 182 var params = { foo: "bar", … … 186 186 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly"); 187 187 t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values"); 188 189 190 // Parameters which are a list should end up being a comma-seperated 191 // list of the URL encoded strings 192 var params = { foo: ["bar,baz"] }; 193 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays"); 194 195 var params = { foo: ["bar","baz,"] }; 196 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar,baz%2C", "getParameterString returns with list of CSVs when given a list. "); 188 197 } 189 198
