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:
ahocevar
2013-03-05 00:46:58 +01:00
parent cad215e0cc
commit 586f393492
24 changed files with 320 additions and 206 deletions

View File

@@ -14,10 +14,6 @@ describe('ol.source.TileSource', function() {
describe('#findLoadedTiles()', function() {
function isLoaded(tile) {
return !goog.isNull(tile) && tile.getState() === ol.TileState.LOADED;
}
it('adds no tiles if none are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
@@ -25,7 +21,13 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 3, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
source.findLoadedTiles(loadedTilesByZ, getTileIfLoaded, 3, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(0);
@@ -41,7 +43,13 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 0, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
source.findLoadedTiles(loadedTilesByZ, getTileIfLoaded, 0, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['0']['0/0/0'];
@@ -59,7 +67,13 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
source.findLoadedTiles(loadedTilesByZ, getTileIfLoaded, 1, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['1']['1/0/0'];
@@ -79,7 +93,13 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
var loaded = source.findLoadedTiles(
loadedTilesByZ, getTileIfLoaded, 1, range);
expect(loaded).toBe(true);
});
@@ -98,7 +118,14 @@ describe('ol.source.TileSource', function() {
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
var loaded = source.findLoadedTiles(
loadedTilesByZ, getTileIfLoaded, 1, range);
expect(loaded).toBe(true);
});
@@ -114,7 +141,14 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
var loaded = source.findLoadedTiles(
loadedTilesByZ, getTileIfLoaded, 1, range);
expect(loaded).toBe(false);
});
@@ -132,7 +166,14 @@ describe('ol.source.TileSource', function() {
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var loaded = source.findLoadedTiles(loadedTilesByZ, isLoaded, 1, range);
function getTileIfLoaded(tileCoord) {
var tile = source.getTile(tileCoord, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null;
}
var loaded = source.findLoadedTiles(
loadedTilesByZ, getTileIfLoaded, 1, range);
expect(loaded).toBe(false);
});

View File

@@ -2,7 +2,7 @@ goog.provide('ol.test.source.XYZ');
describe('ol.source.XYZ', function() {
describe('getTileCoordUrl', function() {
describe('tileUrlFunction', function() {
var xyzTileSource, tileGrid;
@@ -18,59 +18,59 @@ describe('ol.source.XYZ', function() {
var coordinate = new ol.Coordinate(829330.2064098881, 5933916.615134273);
var tileUrl;
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
expect(tileUrl).toEqual('0/0/0');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
expect(tileUrl).toEqual('1/1/0');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
expect(tileUrl).toEqual('2/2/1');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
expect(tileUrl).toEqual('3/4/2');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
expect(tileUrl).toEqual('4/8/5');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
expect(tileUrl).toEqual('5/16/11');
tileUrl = xyzTileSource.getTileCoordUrl(
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
expect(tileUrl).toEqual('6/33/22');
});
describe('wrap x', function() {
it('returns the expected URL', function() {
var tileUrl = xyzTileSource.getTileCoordUrl(
var tileUrl = xyzTileSource.tileUrlFunction(
new ol.TileCoord(6, -31, -23));
expect(tileUrl).toEqual('6/33/22');
tileUrl = xyzTileSource.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
tileUrl = xyzTileSource.tileUrlFunction(new ol.TileCoord(6, 33, -23));
expect(tileUrl).toEqual('6/33/22');
tileUrl = xyzTileSource.getTileCoordUrl(new ol.TileCoord(6, 97, -23));
tileUrl = xyzTileSource.tileUrlFunction(new ol.TileCoord(6, 97, -23));
expect(tileUrl).toEqual('6/33/22');
});
});
describe('crop y', function() {
it('returns the expected URL', function() {
var tileUrl = xyzTileSource.getTileCoordUrl(
var tileUrl = xyzTileSource.tileUrlFunction(
new ol.TileCoord(6, 33, -87));
expect(tileUrl).toBeUndefined();
tileUrl = xyzTileSource.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
tileUrl = xyzTileSource.tileUrlFunction(new ol.TileCoord(6, 33, -23));
expect(tileUrl).toEqual('6/33/22');
tileUrl = xyzTileSource.getTileCoordUrl(new ol.TileCoord(6, 33, 41));
tileUrl = xyzTileSource.tileUrlFunction(new ol.TileCoord(6, 33, 41));
expect(tileUrl).toBeUndefined();
});
});