Merge pull request #821 from bartvde/singletile
ability to switch between singleTile true and false on the fly (r=@ahocevar)
This commit is contained in:
@@ -311,14 +311,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
this.tileQueue = [];
|
this.tileQueue = [];
|
||||||
this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this);
|
this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this);
|
||||||
|
|
||||||
if (this.removeBackBufferDelay === null) {
|
this.initProperties();
|
||||||
this.removeBackBufferDelay = this.singleTile ? 0 : 2500;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.className === null) {
|
|
||||||
this.className = this.singleTile ? 'olLayerGridSingleTile' :
|
|
||||||
'olLayerGrid';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!OpenLayers.Animation.isNative) {
|
if (!OpenLayers.Animation.isNative) {
|
||||||
this.deferMoveGriddedTiles = OpenLayers.Function.bind(function() {
|
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;
|
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
|
* Method: setMap
|
||||||
*
|
*
|
||||||
@@ -394,6 +403,28 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
var singleTileChanged = newOptions.singleTile !== undefined &&
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: clone
|
* APIMethod: clone
|
||||||
* Create a clone of this layer
|
* Create a clone of this layer
|
||||||
|
|||||||
@@ -1542,6 +1542,32 @@
|
|||||||
map.destroy();
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user