Support tile sources without configured projection
This change adds a lot of flexibility to working with tile layers: Sources where the server projection or tile grid do not matter can now be constructed without specifying a projection or tile grid. The tileUrlFunction/imageUrlFunction now also creates updated URLs when the params of the layer change, so things like mergeNewParams in ol2 will be possible. A nice side effect of this whole change is that there is no more duplicated code between tiled and single image WMS layers. While I was at it, I also fixed a WMS 1.1.1 axis order issue and incorrect STYLES params (STYLES=& instead of STYLES&).
This commit is contained in:
@@ -79,7 +79,8 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
|
||||
var hints = frameState.viewHints;
|
||||
|
||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
||||
image = imageSource.getImage(frameState.extent, viewResolution);
|
||||
image = imageSource.getImage(
|
||||
frameState.extent, viewResolution, view2DState.projection);
|
||||
if (!goog.isNull(image)) {
|
||||
var imageState = image.getState();
|
||||
if (imageState == ol.ImageState.IDLE) {
|
||||
|
||||
@@ -86,11 +86,15 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
function(frameState, layerState) {
|
||||
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
}
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileSize = tileGrid.getTileSize(z);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
@@ -129,11 +133,11 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
var tilesToDrawByZ = {};
|
||||
tilesToDrawByZ[z] = {};
|
||||
|
||||
var isLoaded = function(tile) {
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||
};
|
||||
}, tileSource, tileGrid, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, isLoaded);
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
var allTilesLoaded = true;
|
||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
||||
@@ -141,7 +145,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tileCoord = new ol.TileCoord(z, x, y);
|
||||
tile = tileSource.getTile(tileCoord);
|
||||
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||
if (goog.isNull(tile)) {
|
||||
continue;
|
||||
}
|
||||
@@ -200,7 +204,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
var transform = this.transform_;
|
||||
|
||||
@@ -67,7 +67,8 @@ ol.renderer.dom.ImageLayer.prototype.renderFrame =
|
||||
var hints = frameState.viewHints;
|
||||
|
||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
||||
var image_ = imageSource.getImage(frameState.extent, viewResolution);
|
||||
var image_ = imageSource.getImage(
|
||||
frameState.extent, viewResolution, view2DState.projection);
|
||||
if (!goog.isNull(image_)) {
|
||||
var imageState = image_.getState();
|
||||
if (imageState == ol.ImageState.IDLE) {
|
||||
|
||||
@@ -79,11 +79,15 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
}
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||
@@ -93,11 +97,11 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
var tilesToDrawByZ = {};
|
||||
tilesToDrawByZ[z] = {};
|
||||
|
||||
var isLoaded = function(tile) {
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||
};
|
||||
}, tileSource, tileGrid, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, isLoaded);
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
var allTilesLoaded = true;
|
||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
||||
@@ -105,7 +109,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tileCoord = new ol.TileCoord(z, x, y);
|
||||
tile = tileSource.getTile(tileCoord);
|
||||
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||
if (goog.isNull(tile)) {
|
||||
continue;
|
||||
}
|
||||
@@ -216,7 +220,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
};
|
||||
|
||||
@@ -258,3 +258,20 @@ ol.renderer.Layer.prototype.updateWantedTiles =
|
||||
}
|
||||
wantedTiles[tileSourceKey][coordKey] = true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {function(ol.Tile): boolean} isLoadedFunction Function to
|
||||
* determine if the tile is loaded.
|
||||
* @param {ol.source.TileSource} tileSource Tile source.
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @param {ol.Projection} projection Projection.
|
||||
* @return {function(ol.TileCoord): ol.Tile} Returns a tile if it is loaded.
|
||||
*/
|
||||
ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
||||
function(isLoadedFunction, tileSource, tileGrid, projection) {
|
||||
return function(tileCoord) {
|
||||
var tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||
return isLoadedFunction(tile) ? tile : null;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -160,7 +160,8 @@ ol.renderer.webgl.ImageLayer.prototype.renderFrame =
|
||||
var hints = frameState.viewHints;
|
||||
|
||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
||||
var image_ = imageSource.getImage(frameState.extent, viewResolution);
|
||||
var image_ = imageSource.getImage(
|
||||
frameState.extent, viewResolution, view2DState.projection);
|
||||
if (!goog.isNull(image_)) {
|
||||
var imageState = image_.getState();
|
||||
if (imageState == ol.ImageState.IDLE) {
|
||||
|
||||
@@ -281,12 +281,16 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
var gl = mapRenderer.getGL();
|
||||
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
var center = view2DState.center;
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
}
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||
@@ -365,12 +369,12 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
var tilesToDrawByZ = {};
|
||||
tilesToDrawByZ[z] = {};
|
||||
|
||||
var isLoaded = function(tile) {
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED &&
|
||||
mapRenderer.isTileTextureLoaded(tile);
|
||||
};
|
||||
}, tileSource, tileGrid, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, isLoaded);
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
var tilesToLoad = new goog.structs.PriorityQueue();
|
||||
|
||||
@@ -380,7 +384,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tileCoord = new ol.TileCoord(z, x, y);
|
||||
tile = tileSource.getTile(tileCoord);
|
||||
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||
if (goog.isNull(tile)) {
|
||||
continue;
|
||||
}
|
||||
@@ -459,7 +463,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
|
||||
|
||||
Reference in New Issue
Block a user