From 5114ecbaeee88aeef2e57e58ac4d52045f057026 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 4 Jan 2013 14:29:07 +0100 Subject: [PATCH 1/4] ability to switch between singleTile true and false --- lib/OpenLayers/Layer/Grid.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 8791236cb6..871899c627 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -393,6 +393,30 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { this.gridLayout = null; } }, + + /** + * APIMethod: addOptions + * + * Parameters: + * newOptions - {Object} + * reinitialize - {Boolean} If set to true, and if resolution options of the + * current baseLayer were changed, the map will be recentered to make + * sure that it is displayed with a valid resolution, and a + * changebaselayer event will be triggered. + */ + addOptions: function (newOptions, reinitialize) { + OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); + if (newOptions.singleTile !== undefined) { + this.clearGrid(); + if (newOptions.singleTile === true) { + this.setTileSize(); + this.initSingleTile(this.map.getExtent()); + } else { + this.tileSize = this.options.tileSize || this.map.getTileSize(); + this.initGriddedTiles(this.map.getExtent()); + } + } + }, /** * APIMethod: clone From 1e1ce54e5b528e88af9478c228c8ef1f860cd165 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 4 Jan 2013 15:10:48 +0100 Subject: [PATCH 2/4] add tests and finish off the functionality for switching between singleTile true and false --- lib/OpenLayers/Layer/Grid.js | 28 +++++++++++++++++++--------- tests/Layer/Grid.html | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 871899c627..d7b6adb2c1 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -311,14 +311,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { this.tileQueue = []; this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); - if (this.removeBackBufferDelay === null) { - this.removeBackBufferDelay = this.singleTile ? 0 : 2500; - } - - if (this.className === null) { - this.className = this.singleTile ? 'olLayerGridSingleTile' : - 'olLayerGrid'; - } + this.initProperties(); if (!OpenLayers.Animation.isNative) { this.deferMoveGriddedTiles = OpenLayers.Function.bind(function() { @@ -330,6 +323,22 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; }, + /** + * Method: initProperties + * Set any properties that depend on the value of singleTile. + * Currently sets removeBackBufferDelay and className + */ + initProperties: function() { + if (this.options.removeBackBufferDelay === undefined) { + this.removeBackBufferDelay = this.singleTile ? 0 : 2500; + } + + if (this.options.className === undefined) { + this.className = this.singleTile ? 'olLayerGridSingleTile' : + 'olLayerGrid'; + } + }, + /** * Method: setMap * @@ -406,7 +415,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { */ addOptions: function (newOptions, reinitialize) { OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); - if (newOptions.singleTile !== undefined) { + if (this.map && newOptions.singleTile !== undefined) { + this.initProperties(); this.clearGrid(); if (newOptions.singleTile === true) { this.setTileSize(); diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 6e7d4181bf..ac59f43d4a 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -1541,6 +1541,32 @@ map.destroy(); } + + function test_addOptions(t) { + t.plan(15); + var map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS(name, url, params, {buffer:2}); + map.addLayer(layer); + t.eq(layer.tileSize, map.getTileSize(), "layer's tile size is equal to the map's tile size"); + t.ok(layer.removeBackBufferDelay !== 0, "removeBackBufferDelay should not be 0 since we are not singleTile"); + t.eq(layer.className, "olLayerGrid", "className correct for gridded mode"); + map.setCenter(new OpenLayers.LonLat(0,0),5); + t.eq(layer.grid.length, 8, "Grid rows is correct."); + t.eq(layer.grid[0].length, 7, "Grid cols is correct."); + t.eq(layer.singleTile, false, "singleTile is false by default"); + layer.addOptions({singleTile: true}); + t.eq(layer.removeBackBufferDelay, 0, "removeBackBufferDelay set to 0 since singleTile is true"); + t.eq(layer.singleTile, true, "singleTile set to true"); + t.eq(layer.className, "olLayerGridSingleTile", "className correct for singleTile mode"); + t.eq(layer.grid.length, 1, "Grid rows is correct."); + t.eq(layer.grid[0].length, 1, "Grid cols is correct."); + t.eq(layer.tileSize, new OpenLayers.Size(748, 823), "tile size changed"); + layer.addOptions({singleTile: false}); + t.eq(layer.grid.length, 8, "Grid rows is correct."); + t.eq(layer.grid[0].length, 7, "Grid cols is correct."); + t.eq(layer.tileSize, map.getTileSize(), "layer's tile size is equal to the map's tile size"); + map.destroy(); + } From de4b995616d3f86bb277862c8d0d849aee047da8 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 4 Jan 2013 17:05:03 +0100 Subject: [PATCH 3/4] incorporate @ahocevar's review --- lib/OpenLayers/Layer/Grid.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index d7b6adb2c1..5bd1e3be96 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -414,17 +414,14 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { * changebaselayer event will be triggered. */ addOptions: function (newOptions, reinitialize) { + var singleTileChanged = newOptions.singleTile !== undefined && + newOptions.singleTile !== this.singleTile; OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); - if (this.map && newOptions.singleTile !== undefined) { - this.initProperties(); - this.clearGrid(); - if (newOptions.singleTile === true) { + if (this.map && singleTileChanged) { + this.initProperties(); + this.tileSize = this.options.tileSize; this.setTileSize(); - this.initSingleTile(this.map.getExtent()); - } else { - this.tileSize = this.options.tileSize || this.map.getTileSize(); - this.initGriddedTiles(this.map.getExtent()); - } + this.moveTo(null, true); } }, From 5b5415d6b70f757d4356b5d1addf8707f7e87e6b Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 4 Jan 2013 17:09:38 +0100 Subject: [PATCH 4/4] fix indentation --- lib/OpenLayers/Layer/Grid.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 5bd1e3be96..ef8b41468f 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -418,10 +418,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { newOptions.singleTile !== this.singleTile; OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); if (this.map && singleTileChanged) { - this.initProperties(); - this.tileSize = this.options.tileSize; - this.setTileSize(); - this.moveTo(null, true); + this.initProperties(); + this.tileSize = this.options.tileSize; + this.setTileSize(); + this.moveTo(null, true); } },