add tests and finish off the functionality for switching between singleTile true and false

This commit is contained in:
Bart van den Eijnden
2013-01-04 15:10:48 +01:00
parent 5114ecbaee
commit 1e1ce54e5b
2 changed files with 45 additions and 9 deletions

View File

@@ -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();

View File

@@ -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();
}
</script>
</head>