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:
@@ -19,8 +19,10 @@ var epsg21781 = new ol.Projection('EPSG:21781', ol.ProjectionUnits.METERS,
|
|||||||
new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864));
|
new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864));
|
||||||
ol.projection.addProjection(epsg21781);
|
ol.projection.addProjection(epsg21781);
|
||||||
|
|
||||||
// We give the single image source a set of resolutions. This prevents the
|
// We could give the single image source a set of resolutions. This prevents the
|
||||||
// source from requesting images of arbitrary resolutions.
|
// source from requesting images of arbitrary resolutions. To try it, uncomment
|
||||||
|
// the block below and the resolutions option in the SingleImageWMS config.
|
||||||
|
/*
|
||||||
var projectionExtent = epsg21781.getExtent();
|
var projectionExtent = epsg21781.getExtent();
|
||||||
var maxResolution = Math.max(projectionExtent.getWidth(),
|
var maxResolution = Math.max(projectionExtent.getWidth(),
|
||||||
projectionExtent.getHeight()) / 256;
|
projectionExtent.getHeight()) / 256;
|
||||||
@@ -28,6 +30,7 @@ var resolutions = new Array(10);
|
|||||||
for (var i = 0; i < 10; ++i) {
|
for (var i = 0; i < 10; ++i) {
|
||||||
resolutions[i] = maxResolution / Math.pow(2.0, i);
|
resolutions[i] = maxResolution / Math.pow(2.0, i);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
var extent = new ol.Extent(420000, 30000, 900000, 350000);
|
var extent = new ol.Extent(420000, 30000, 900000, 350000);
|
||||||
var layers = new ol.Collection([
|
var layers = new ol.Collection([
|
||||||
@@ -42,20 +45,18 @@ var layers = new ol.Collection([
|
|||||||
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
|
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
|
||||||
'FORMAT': 'image/jpeg'
|
'FORMAT': 'image/jpeg'
|
||||||
},
|
},
|
||||||
projection: epsg21781,
|
|
||||||
extent: extent
|
extent: extent
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
new ol.layer.ImageLayer({
|
new ol.layer.ImageLayer({
|
||||||
source: new ol.source.SingleImageWMS({
|
source: new ol.source.SingleImageWMS({
|
||||||
|
//resolutions: resolutions,
|
||||||
url: 'http://wms.geo.admin.ch/',
|
url: 'http://wms.geo.admin.ch/',
|
||||||
attributions: [new ol.Attribution(
|
attributions: [new ol.Attribution(
|
||||||
'© ' +
|
'© ' +
|
||||||
'<a href="http://www.geo.admin.ch/internet/geoportal/en/home.html">' +
|
'<a href="http://www.geo.admin.ch/internet/geoportal/en/home.html">' +
|
||||||
'National parks / geo.admin.ch</a>')],
|
'National parks / geo.admin.ch</a>')],
|
||||||
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'}
|
||||||
projection: epsg21781,
|
|
||||||
resolutions: resolutions
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,31 +1,28 @@
|
|||||||
goog.provide('ol.ImageUrlFunction');
|
goog.provide('ol.ImageUrlFunction');
|
||||||
goog.provide('ol.ImageUrlFunctionType');
|
goog.provide('ol.ImageUrlFunctionType');
|
||||||
|
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.Size');
|
goog.require('ol.Size');
|
||||||
|
goog.require('ol.source.wms');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function(ol.Extent, ol.Size): (string|undefined)}
|
* @typedef {function(ol.Extent, ol.Size, ol.Projection): (string|undefined)}
|
||||||
*/
|
*/
|
||||||
ol.ImageUrlFunctionType;
|
ol.ImageUrlFunctionType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} baseUrl Base URL (may have query data).
|
* @param {string} baseUrl Base URL (may have query data).
|
||||||
* @param {string} axisOrientation Axis orientation.
|
* @param {Object.<string, string|number>} params WMS parameters.
|
||||||
|
* @param {string=} opt_version WMS version.
|
||||||
* @return {ol.ImageUrlFunctionType} Image URL function.
|
* @return {ol.ImageUrlFunctionType} Image URL function.
|
||||||
*/
|
*/
|
||||||
ol.ImageUrlFunction.createBboxParam = function(baseUrl, axisOrientation) {
|
ol.ImageUrlFunction.createWMSParams =
|
||||||
return function(extent, size) {
|
function(baseUrl, params, opt_version) {
|
||||||
var bboxValues = axisOrientation.substr(0, 2) == 'ne' ?
|
return function(extent, size, projection) {
|
||||||
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
|
return ol.source.wms.getUrl(
|
||||||
[extent.minX, extent.minY, extent.maxX, extent.maxY];
|
baseUrl, params, extent, size, projection, opt_version);
|
||||||
return goog.uri.utils.appendParams(baseUrl,
|
|
||||||
'BBOX', bboxValues.join(','),
|
|
||||||
'HEIGHT', size.height,
|
|
||||||
'WIDTH', size.width);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ ol.Projection = function(code, units, extent, opt_axisOrientation) {
|
|||||||
this.axisOrientation_ = goog.isDef(opt_axisOrientation) ?
|
this.axisOrientation_ = goog.isDef(opt_axisOrientation) ?
|
||||||
opt_axisOrientation : 'enu';
|
opt_axisOrientation : 'enu';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.tilegrid.TileGrid}
|
||||||
|
*/
|
||||||
|
this.defaultTileGrid_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -110,6 +116,22 @@ ol.Projection.prototype.getAxisOrientation = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.tilegrid.TileGrid} The default tile grid.
|
||||||
|
*/
|
||||||
|
ol.Projection.prototype.getDefaultTileGrid = function() {
|
||||||
|
return this.defaultTileGrid_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.tilegrid.TileGrid} tileGrid The default tile grid.
|
||||||
|
*/
|
||||||
|
ol.Projection.prototype.setDefaultTileGrid = function(tileGrid) {
|
||||||
|
this.defaultTileGrid_ = tileGrid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
|
|||||||
var hints = frameState.viewHints;
|
var hints = frameState.viewHints;
|
||||||
|
|
||||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
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)) {
|
if (!goog.isNull(image)) {
|
||||||
var imageState = image.getState();
|
var imageState = image.getState();
|
||||||
if (imageState == ol.ImageState.IDLE) {
|
if (imageState == ol.ImageState.IDLE) {
|
||||||
|
|||||||
@@ -86,11 +86,15 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
function(frameState, layerState) {
|
function(frameState, layerState) {
|
||||||
|
|
||||||
var view2DState = frameState.view2DState;
|
var view2DState = frameState.view2DState;
|
||||||
|
var projection = view2DState.projection;
|
||||||
|
|
||||||
var tileLayer = this.getTileLayer();
|
var tileLayer = this.getTileLayer();
|
||||||
var tileSource = tileLayer.getTileSource();
|
var tileSource = tileLayer.getTileSource();
|
||||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||||
var tileGrid = tileSource.getTileGrid();
|
var tileGrid = tileSource.getTileGrid();
|
||||||
|
if (goog.isNull(tileGrid)) {
|
||||||
|
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||||
|
}
|
||||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||||
var tileSize = tileGrid.getTileSize(z);
|
var tileSize = tileGrid.getTileSize(z);
|
||||||
var tileResolution = tileGrid.getResolution(z);
|
var tileResolution = tileGrid.getResolution(z);
|
||||||
@@ -129,11 +133,11 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
var tilesToDrawByZ = {};
|
var tilesToDrawByZ = {};
|
||||||
tilesToDrawByZ[z] = {};
|
tilesToDrawByZ[z] = {};
|
||||||
|
|
||||||
var isLoaded = function(tile) {
|
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||||
};
|
}, tileSource, tileGrid, projection);
|
||||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||||
tilesToDrawByZ, isLoaded);
|
tilesToDrawByZ, getTileIfLoaded);
|
||||||
|
|
||||||
var allTilesLoaded = true;
|
var allTilesLoaded = true;
|
||||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
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) {
|
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||||
|
|
||||||
tileCoord = new ol.TileCoord(z, x, y);
|
tileCoord = new ol.TileCoord(z, x, y);
|
||||||
tile = tileSource.getTile(tileCoord);
|
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||||
if (goog.isNull(tile)) {
|
if (goog.isNull(tile)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -200,7 +204,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||||
this.scheduleExpireCache(frameState, tileSource);
|
this.scheduleExpireCache(frameState, tileSource);
|
||||||
|
|
||||||
var transform = this.transform_;
|
var transform = this.transform_;
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ ol.renderer.dom.ImageLayer.prototype.renderFrame =
|
|||||||
var hints = frameState.viewHints;
|
var hints = frameState.viewHints;
|
||||||
|
|
||||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
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_)) {
|
if (!goog.isNull(image_)) {
|
||||||
var imageState = image_.getState();
|
var imageState = image_.getState();
|
||||||
if (imageState == ol.ImageState.IDLE) {
|
if (imageState == ol.ImageState.IDLE) {
|
||||||
|
|||||||
@@ -79,11 +79,15 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
}
|
}
|
||||||
|
|
||||||
var view2DState = frameState.view2DState;
|
var view2DState = frameState.view2DState;
|
||||||
|
var projection = view2DState.projection;
|
||||||
|
|
||||||
var tileLayer = this.getTileLayer();
|
var tileLayer = this.getTileLayer();
|
||||||
var tileSource = tileLayer.getTileSource();
|
var tileSource = tileLayer.getTileSource();
|
||||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||||
var tileGrid = tileSource.getTileGrid();
|
var tileGrid = tileSource.getTileGrid();
|
||||||
|
if (goog.isNull(tileGrid)) {
|
||||||
|
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||||
|
}
|
||||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||||
var tileResolution = tileGrid.getResolution(z);
|
var tileResolution = tileGrid.getResolution(z);
|
||||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||||
@@ -93,11 +97,11 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
var tilesToDrawByZ = {};
|
var tilesToDrawByZ = {};
|
||||||
tilesToDrawByZ[z] = {};
|
tilesToDrawByZ[z] = {};
|
||||||
|
|
||||||
var isLoaded = function(tile) {
|
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||||
};
|
}, tileSource, tileGrid, projection);
|
||||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||||
tilesToDrawByZ, isLoaded);
|
tilesToDrawByZ, getTileIfLoaded);
|
||||||
|
|
||||||
var allTilesLoaded = true;
|
var allTilesLoaded = true;
|
||||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
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) {
|
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||||
|
|
||||||
tileCoord = new ol.TileCoord(z, x, y);
|
tileCoord = new ol.TileCoord(z, x, y);
|
||||||
tile = tileSource.getTile(tileCoord);
|
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||||
if (goog.isNull(tile)) {
|
if (goog.isNull(tile)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -216,7 +220,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||||
this.scheduleExpireCache(frameState, tileSource);
|
this.scheduleExpireCache(frameState, tileSource);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -258,3 +258,20 @@ ol.renderer.Layer.prototype.updateWantedTiles =
|
|||||||
}
|
}
|
||||||
wantedTiles[tileSourceKey][coordKey] = true;
|
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;
|
var hints = frameState.viewHints;
|
||||||
|
|
||||||
if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING]) {
|
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_)) {
|
if (!goog.isNull(image_)) {
|
||||||
var imageState = image_.getState();
|
var imageState = image_.getState();
|
||||||
if (imageState == ol.ImageState.IDLE) {
|
if (imageState == ol.ImageState.IDLE) {
|
||||||
|
|||||||
@@ -281,12 +281,16 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
var gl = mapRenderer.getGL();
|
var gl = mapRenderer.getGL();
|
||||||
|
|
||||||
var view2DState = frameState.view2DState;
|
var view2DState = frameState.view2DState;
|
||||||
|
var projection = view2DState.projection;
|
||||||
var center = view2DState.center;
|
var center = view2DState.center;
|
||||||
|
|
||||||
var tileLayer = this.getTileLayer();
|
var tileLayer = this.getTileLayer();
|
||||||
var tileSource = tileLayer.getTileSource();
|
var tileSource = tileLayer.getTileSource();
|
||||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||||
var tileGrid = tileSource.getTileGrid();
|
var tileGrid = tileSource.getTileGrid();
|
||||||
|
if (goog.isNull(tileGrid)) {
|
||||||
|
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||||
|
}
|
||||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||||
var tileResolution = tileGrid.getResolution(z);
|
var tileResolution = tileGrid.getResolution(z);
|
||||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||||
@@ -365,12 +369,12 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
var tilesToDrawByZ = {};
|
var tilesToDrawByZ = {};
|
||||||
tilesToDrawByZ[z] = {};
|
tilesToDrawByZ[z] = {};
|
||||||
|
|
||||||
var isLoaded = function(tile) {
|
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED &&
|
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED &&
|
||||||
mapRenderer.isTileTextureLoaded(tile);
|
mapRenderer.isTileTextureLoaded(tile);
|
||||||
};
|
}, tileSource, tileGrid, projection);
|
||||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||||
tilesToDrawByZ, isLoaded);
|
tilesToDrawByZ, getTileIfLoaded);
|
||||||
|
|
||||||
var tilesToLoad = new goog.structs.PriorityQueue();
|
var tilesToLoad = new goog.structs.PriorityQueue();
|
||||||
|
|
||||||
@@ -380,7 +384,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||||
|
|
||||||
tileCoord = new ol.TileCoord(z, x, y);
|
tileCoord = new ol.TileCoord(z, x, y);
|
||||||
tile = tileSource.getTile(tileCoord);
|
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||||
if (goog.isNull(tile)) {
|
if (goog.isNull(tile)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -459,7 +463,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||||
tileSource.useLowResolutionTiles(z, frameState.extent);
|
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||||
this.scheduleExpireCache(frameState, tileSource);
|
this.scheduleExpireCache(frameState, tileSource);
|
||||||
|
|
||||||
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
|
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
|
||||||
|
|||||||
@@ -76,12 +76,13 @@ goog.inherits(ol.source.ImageSource, ol.source.Source);
|
|||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
* @return {ol.Image} Single image.
|
* @return {ol.Image} Single image.
|
||||||
*/
|
*/
|
||||||
ol.source.ImageSource.prototype.createImage =
|
ol.source.ImageSource.prototype.createImage =
|
||||||
function(extent, resolution, size) {
|
function(extent, resolution, size, projection) {
|
||||||
var image = null;
|
var image = null;
|
||||||
var imageUrl = this.imageUrlFunction(extent, size);
|
var imageUrl = this.imageUrlFunction(extent, size, projection);
|
||||||
if (goog.isDef(imageUrl)) {
|
if (goog.isDef(imageUrl)) {
|
||||||
image = new ol.Image(
|
image = new ol.Image(
|
||||||
extent, resolution, imageUrl, this.crossOrigin_,
|
extent, resolution, imageUrl, this.crossOrigin_,
|
||||||
@@ -109,6 +110,7 @@ ol.source.ImageSource.prototype.findNearestResolution =
|
|||||||
/**
|
/**
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
* @return {ol.Image} Single image.
|
* @return {ol.Image} Single image.
|
||||||
*/
|
*/
|
||||||
ol.source.ImageSource.prototype.getImage = goog.abstractMethod;
|
ol.source.ImageSource.prototype.getImage = goog.abstractMethod;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ goog.require('ol.ImageTile');
|
|||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
goog.require('ol.Tile');
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.TileCache');
|
goog.require('ol.TileCache');
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.TileUrlFunctionType');
|
goog.require('ol.TileUrlFunctionType');
|
||||||
goog.require('ol.source.TileSource');
|
goog.require('ol.source.TileSource');
|
||||||
@@ -84,12 +83,15 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
|
ol.source.ImageTileSource.prototype.getTile =
|
||||||
|
function(tileCoord, tileGrid, projection) {
|
||||||
var key = tileCoord.toString();
|
var key = tileCoord.toString();
|
||||||
if (this.tileCache_.containsKey(key)) {
|
if (this.tileCache_.containsKey(key)) {
|
||||||
return /** @type {ol.Tile} */ (this.tileCache_.get(key));
|
return /** @type {ol.Tile} */ (this.tileCache_.get(key));
|
||||||
} else {
|
} else {
|
||||||
var tileUrl = this.getTileCoordUrl(tileCoord);
|
goog.asserts.assert(tileGrid);
|
||||||
|
goog.asserts.assert(projection);
|
||||||
|
var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection);
|
||||||
var tile;
|
var tile;
|
||||||
if (goog.isDef(tileUrl)) {
|
if (goog.isDef(tileUrl)) {
|
||||||
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
|
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
|
||||||
@@ -102,15 +104,6 @@ ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
|
||||||
* @return {string|undefined} Tile URL.
|
|
||||||
*/
|
|
||||||
ol.source.ImageTileSource.prototype.getTileCoordUrl = function(tileCoord) {
|
|
||||||
return this.tileUrlFunction(tileCoord);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
goog.provide('ol.source.SingleImageWMS');
|
goog.provide('ol.source.SingleImageWMS');
|
||||||
|
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.ImageUrlFunction');
|
goog.require('ol.ImageUrlFunction');
|
||||||
goog.require('ol.Size');
|
goog.require('ol.Size');
|
||||||
goog.require('ol.projection');
|
|
||||||
goog.require('ol.source.ImageSource');
|
goog.require('ol.source.ImageSource');
|
||||||
|
|
||||||
|
|
||||||
@@ -16,45 +14,16 @@ goog.require('ol.source.ImageSource');
|
|||||||
* @param {ol.source.SingleImageWMSOptions} options Options.
|
* @param {ol.source.SingleImageWMSOptions} options Options.
|
||||||
*/
|
*/
|
||||||
ol.source.SingleImageWMS = function(options) {
|
ol.source.SingleImageWMS = function(options) {
|
||||||
|
var imageUrlFunction = goog.isDef(options.url) ?
|
||||||
var projection = ol.projection.createProjection(
|
ol.ImageUrlFunction.createWMSParams(
|
||||||
options.projection, 'EPSG:3857');
|
options.url, options.params, options.version) :
|
||||||
var projectionExtent = projection.getExtent();
|
|
||||||
|
|
||||||
var extent = goog.isDef(options.extent) ?
|
|
||||||
options.extent : projectionExtent;
|
|
||||||
|
|
||||||
var version = goog.isDef(options.version) ?
|
|
||||||
options.version : '1.3';
|
|
||||||
|
|
||||||
var baseParams = {
|
|
||||||
'SERVICE': 'WMS',
|
|
||||||
'VERSION': version,
|
|
||||||
'REQUEST': 'GetMap',
|
|
||||||
'STYLES': '',
|
|
||||||
'FORMAT': 'image/png',
|
|
||||||
'TRANSPARENT': true
|
|
||||||
};
|
|
||||||
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
|
|
||||||
goog.object.extend(baseParams, options.params);
|
|
||||||
|
|
||||||
var axisOrientation = projection.getAxisOrientation();
|
|
||||||
var imageUrlFunction;
|
|
||||||
if (options.url) {
|
|
||||||
var url = goog.uri.utils.appendParamsFromMap(
|
|
||||||
options.url, baseParams);
|
|
||||||
imageUrlFunction =
|
|
||||||
ol.ImageUrlFunction.createBboxParam(url, axisOrientation);
|
|
||||||
} else {
|
|
||||||
imageUrlFunction =
|
|
||||||
ol.ImageUrlFunction.nullImageUrlFunction;
|
ol.ImageUrlFunction.nullImageUrlFunction;
|
||||||
}
|
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
crossOrigin: options.crossOrigin,
|
crossOrigin: options.crossOrigin,
|
||||||
extent: extent,
|
extent: options.extent,
|
||||||
projection: projection,
|
projection: options.projection,
|
||||||
resolutions: options.resolutions,
|
resolutions: options.resolutions,
|
||||||
imageUrlFunction: imageUrlFunction
|
imageUrlFunction: imageUrlFunction
|
||||||
});
|
});
|
||||||
@@ -80,7 +49,7 @@ goog.inherits(ol.source.SingleImageWMS, ol.source.ImageSource);
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.SingleImageWMS.prototype.getImage =
|
ol.source.SingleImageWMS.prototype.getImage =
|
||||||
function(extent, resolution) {
|
function(extent, resolution, projection) {
|
||||||
resolution = this.findNearestResolution(resolution);
|
resolution = this.findNearestResolution(resolution);
|
||||||
|
|
||||||
var image = this.image_;
|
var image = this.image_;
|
||||||
@@ -97,6 +66,6 @@ ol.source.SingleImageWMS.prototype.getImage =
|
|||||||
var height = extent.getHeight() / resolution;
|
var height = extent.getHeight() / resolution;
|
||||||
var size = new ol.Size(width, height);
|
var size = new ol.Size(width, height);
|
||||||
|
|
||||||
this.image_ = this.createImage(extent, resolution, size);
|
this.image_ = this.createImage(extent, resolution, size, projection);
|
||||||
return this.image_;
|
return this.image_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ ol.source.Source = function(sourceOptions) {
|
|||||||
* @type {ol.Extent}
|
* @type {ol.Extent}
|
||||||
*/
|
*/
|
||||||
this.extent_ = goog.isDef(sourceOptions.extent) ?
|
this.extent_ = goog.isDef(sourceOptions.extent) ?
|
||||||
sourceOptions.extent : sourceOptions.projection.getExtent();
|
sourceOptions.extent : goog.isDef(sourceOptions.projection) ?
|
||||||
|
sourceOptions.projection.getExtent() : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ ol.source.StaticImage = function(options) {
|
|||||||
var imageExtent = options.imageExtent;
|
var imageExtent = options.imageExtent;
|
||||||
var imageSize = options.imageSize;
|
var imageSize = options.imageSize;
|
||||||
var imageResolution = imageExtent.getHeight() / imageSize.height;
|
var imageResolution = imageExtent.getHeight() / imageSize.height;
|
||||||
|
var projection = goog.isDef(options.projection) ? options.projection : null;
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
@@ -33,7 +34,8 @@ ol.source.StaticImage = function(options) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.Image}
|
* @type {ol.Image}
|
||||||
*/
|
*/
|
||||||
this.image_ = this.createImage(imageExtent, imageResolution, imageSize);
|
this.image_ = this.createImage(
|
||||||
|
imageExtent, imageResolution, imageSize, projection);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
|
goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
|
||||||
@@ -42,7 +44,8 @@ goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.StaticImage.prototype.getImage = function(extent, resolution) {
|
ol.source.StaticImage.prototype.getImage =
|
||||||
|
function(extent, resolution, projection) {
|
||||||
if (extent.intersects(this.image_.getExtent())) {
|
if (extent.intersects(this.image_.getExtent())) {
|
||||||
return this.image_;
|
return this.image_;
|
||||||
}
|
}
|
||||||
@@ -55,7 +58,7 @@ ol.source.StaticImage.prototype.getImage = function(extent, resolution) {
|
|||||||
* @return {ol.ImageUrlFunctionType} Function.
|
* @return {ol.ImageUrlFunctionType} Function.
|
||||||
*/
|
*/
|
||||||
ol.source.StaticImage.createImageFunction = function(url) {
|
ol.source.StaticImage.createImageFunction = function(url) {
|
||||||
return function(extent, size) {
|
return function(extent, size, projection) {
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ goog.provide('ol.source.TiledWMS');
|
|||||||
|
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.object');
|
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.projection');
|
|
||||||
goog.require('ol.source.ImageTileSource');
|
goog.require('ol.source.ImageTileSource');
|
||||||
|
|
||||||
|
|
||||||
@@ -20,64 +17,40 @@ goog.require('ol.source.ImageTileSource');
|
|||||||
* @param {ol.source.TiledWMSOptions} tiledWMSOptions options.
|
* @param {ol.source.TiledWMSOptions} tiledWMSOptions options.
|
||||||
*/
|
*/
|
||||||
ol.source.TiledWMS = function(tiledWMSOptions) {
|
ol.source.TiledWMS = function(tiledWMSOptions) {
|
||||||
var projection = ol.projection.createProjection(
|
|
||||||
tiledWMSOptions.projection, 'EPSG:3857');
|
|
||||||
var projectionExtent = projection.getExtent();
|
|
||||||
|
|
||||||
var extent = goog.isDef(tiledWMSOptions.extent) ?
|
|
||||||
tiledWMSOptions.extent : projectionExtent;
|
|
||||||
|
|
||||||
var version = goog.isDef(tiledWMSOptions.version) ?
|
|
||||||
tiledWMSOptions.version : '1.3';
|
|
||||||
|
|
||||||
var tileGrid;
|
var tileGrid;
|
||||||
if (goog.isDef(tiledWMSOptions.tileGrid)) {
|
if (goog.isDef(tiledWMSOptions.tileGrid)) {
|
||||||
tileGrid = tiledWMSOptions.tileGrid;
|
tileGrid = tiledWMSOptions.tileGrid;
|
||||||
} else {
|
|
||||||
tileGrid = ol.tilegrid.createForProjection(projection,
|
|
||||||
tiledWMSOptions.maxZoom);
|
|
||||||
}
|
}
|
||||||
|
var version = tiledWMSOptions.version;
|
||||||
|
|
||||||
var baseParams = {
|
|
||||||
'SERVICE': 'WMS',
|
|
||||||
'VERSION': version,
|
|
||||||
'REQUEST': 'GetMap',
|
|
||||||
'STYLES': '',
|
|
||||||
'FORMAT': 'image/png',
|
|
||||||
'TRANSPARENT': true
|
|
||||||
};
|
|
||||||
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
|
|
||||||
goog.object.extend(baseParams, tiledWMSOptions.params);
|
|
||||||
|
|
||||||
var axisOrientation = projection.getAxisOrientation();
|
|
||||||
var tileUrlFunction;
|
var tileUrlFunction;
|
||||||
if (tiledWMSOptions.urls) {
|
if (tiledWMSOptions.urls) {
|
||||||
var tileUrlFunctions = goog.array.map(
|
var tileUrlFunctions = goog.array.map(
|
||||||
tiledWMSOptions.urls, function(url) {
|
tiledWMSOptions.urls, function(url) {
|
||||||
url = goog.uri.utils.appendParamsFromMap(url, baseParams);
|
return ol.TileUrlFunction.createWMSParams(
|
||||||
return ol.TileUrlFunction.createBboxParam(
|
url, tiledWMSOptions.params, version);
|
||||||
url, tileGrid, axisOrientation);
|
|
||||||
});
|
});
|
||||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||||
tileUrlFunctions);
|
tileUrlFunctions);
|
||||||
} else if (tiledWMSOptions.url) {
|
} else if (tiledWMSOptions.url) {
|
||||||
var url = goog.uri.utils.appendParamsFromMap(
|
tileUrlFunction = ol.TileUrlFunction.createWMSParams(
|
||||||
tiledWMSOptions.url, baseParams);
|
tiledWMSOptions.url, tiledWMSOptions.params, version);
|
||||||
tileUrlFunction =
|
|
||||||
ol.TileUrlFunction.createBboxParam(url, tileGrid, axisOrientation);
|
|
||||||
} else {
|
} else {
|
||||||
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tileCoordTransform = function(tileCoord) {
|
var extent = tiledWMSOptions.extent;
|
||||||
|
|
||||||
|
var tileCoordTransform = function(tileCoord, tileGrid, projection) {
|
||||||
if (tileGrid.getResolutions().length <= tileCoord.z) {
|
if (tileGrid.getResolutions().length <= tileCoord.z) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var x = tileCoord.x;
|
var x = tileCoord.x;
|
||||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
|
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
|
||||||
|
var projectionExtent = projection.getExtent();
|
||||||
// FIXME do we want a wrapDateLine param? The code below will break maps
|
// FIXME do we want a wrapDateLine param? The code below will break maps
|
||||||
// with projections that do not span the whole world width.
|
// with projections that do not span the whole world width.
|
||||||
if (extent.minX === projectionExtent.minX &&
|
if (extent && extent.minX === projectionExtent.minX &&
|
||||||
extent.maxX === projectionExtent.maxX) {
|
extent.maxX === projectionExtent.maxX) {
|
||||||
var numCols = Math.ceil(
|
var numCols = Math.ceil(
|
||||||
(extent.maxX - extent.minX) / (tileExtent.maxX - tileExtent.minX));
|
(extent.maxX - extent.minX) / (tileExtent.maxX - tileExtent.minX));
|
||||||
@@ -96,8 +69,8 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
|
|||||||
attributions: tiledWMSOptions.attributions,
|
attributions: tiledWMSOptions.attributions,
|
||||||
crossOrigin: tiledWMSOptions.crossOrigin,
|
crossOrigin: tiledWMSOptions.crossOrigin,
|
||||||
extent: extent,
|
extent: extent,
|
||||||
tileGrid: tileGrid,
|
tileGrid: tiledWMSOptions.tileGrid,
|
||||||
projection: projection,
|
projection: tiledWMSOptions.projection,
|
||||||
tileUrlFunction: ol.TileUrlFunction.withTileCoordTransform(
|
tileUrlFunction: ol.TileUrlFunction.withTileCoordTransform(
|
||||||
tileCoordTransform, tileUrlFunction)
|
tileCoordTransform, tileUrlFunction)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -65,14 +65,14 @@ ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
|
|||||||
*
|
*
|
||||||
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
|
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
|
||||||
* loaded tiles by zoom level.
|
* loaded tiles by zoom level.
|
||||||
* @param {function(ol.Tile): boolean} isLoaded A function to determine if a
|
* @param {function(ol.TileCoord): ol.Tile} getTileIfLoaded A function that
|
||||||
* tile is fully loaded.
|
* returns the tile only if it is fully loaded.
|
||||||
* @param {number} z Zoom level.
|
* @param {number} z Zoom level.
|
||||||
* @param {ol.TileRange} tileRange Tile range.
|
* @param {ol.TileRange} tileRange Tile range.
|
||||||
* @return {boolean} The tile range is fully covered with loaded tiles.
|
* @return {boolean} The tile range is fully covered with loaded tiles.
|
||||||
*/
|
*/
|
||||||
ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
|
ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
|
||||||
isLoaded, z, tileRange) {
|
getTileIfLoaded, z, tileRange) {
|
||||||
// FIXME this could be more efficient about filling partial holes
|
// FIXME this could be more efficient about filling partial holes
|
||||||
var fullyCovered = true;
|
var fullyCovered = true;
|
||||||
var tile, tileCoord, tileCoordKey, x, y;
|
var tile, tileCoord, tileCoordKey, x, y;
|
||||||
@@ -83,8 +83,8 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
|
|||||||
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
|
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tile = this.getTile(tileCoord);
|
tile = getTileIfLoaded(tileCoord);
|
||||||
if (isLoaded(tile)) {
|
if (!goog.isNull(tile)) {
|
||||||
if (!loadedTilesByZ[z]) {
|
if (!loadedTilesByZ[z]) {
|
||||||
loadedTilesByZ[z] = {};
|
loadedTilesByZ[z] = {};
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,8 @@ ol.source.TileSource.prototype.getResolutions = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
|
* @param {ol.tilegrid.TileGrid=} opt_tileGrid Tile grid.
|
||||||
|
* @param {ol.Projection=} opt_projection Projection.
|
||||||
* @return {ol.Tile} Tile.
|
* @return {ol.Tile} Tile.
|
||||||
*/
|
*/
|
||||||
ol.source.TileSource.prototype.getTile = goog.abstractMethod;
|
ol.source.TileSource.prototype.getTile = goog.abstractMethod;
|
||||||
@@ -124,9 +126,10 @@ ol.source.TileSource.prototype.getTileGrid = function() {
|
|||||||
/**
|
/**
|
||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
|
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||||
*/
|
*/
|
||||||
ol.source.TileSource.prototype.useLowResolutionTiles = function(z, extent) {
|
ol.source.TileSource.prototype.useLowResolutionTiles =
|
||||||
var tileGrid = this.getTileGrid();
|
function(z, extent, tileGrid) {
|
||||||
var tileRange, x, y, zKey;
|
var tileRange, x, y, zKey;
|
||||||
// FIXME this should loop up to tileGrid's minZ when implemented
|
// FIXME this should loop up to tileGrid's minZ when implemented
|
||||||
for (; z >= 0; --z) {
|
for (; z >= 0; --z) {
|
||||||
|
|||||||
37
src/ol/source/wms.js
Normal file
37
src/ol/source/wms.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
goog.provide('ol.source.wms');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} baseUrl WMS base url.
|
||||||
|
* @param {Object.<string, string|number>} params Request parameters.
|
||||||
|
* @param {ol.Extent} extent Extent.
|
||||||
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
|
* @param {string=} opt_version WMS version. Default is '1.3.0'.
|
||||||
|
* @return {string} WMS GetMap request URL.
|
||||||
|
*/
|
||||||
|
ol.source.wms.getUrl =
|
||||||
|
function(baseUrl, params, extent, size, projection, opt_version) {
|
||||||
|
var version = goog.isDef(opt_version) ? opt_version : '1.3.0';
|
||||||
|
var wms13 = version >= '1.3';
|
||||||
|
var axisOrientation = projection.getAxisOrientation();
|
||||||
|
var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
|
||||||
|
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
|
||||||
|
[extent.minX, extent.minY, extent.maxX, extent.maxY];
|
||||||
|
var baseParams = {
|
||||||
|
'SERVICE': 'WMS',
|
||||||
|
'VERSION': version,
|
||||||
|
'REQUEST': 'GetMap',
|
||||||
|
'FORMAT': 'image/png',
|
||||||
|
'TRANSPARENT': true,
|
||||||
|
'WIDTH': size.width,
|
||||||
|
'HEIGHT': size.height,
|
||||||
|
'BBOX': bboxValues.join(',')
|
||||||
|
};
|
||||||
|
goog.object.extend(baseParams, params);
|
||||||
|
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
|
||||||
|
//TODO: Provide our own appendParams function to avoid this empty string hack
|
||||||
|
var stylesParam = 'STYLES';
|
||||||
|
baseParams[stylesParam] = params[stylesParam] || new String('');
|
||||||
|
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
||||||
|
};
|
||||||
@@ -20,6 +20,12 @@ goog.require('ol.array');
|
|||||||
ol.DEFAULT_TILE_SIZE = 256;
|
ol.DEFAULT_TILE_SIZE = 256;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @define {number} Default maximum zoom for default tile grids.
|
||||||
|
*/
|
||||||
|
ol.DEFAULT_MAX_ZOOM = 42;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -89,8 +95,7 @@ ol.tilegrid.TileGrid = function(tileGridOptions) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @param {function(this: T, number, ol.TileRange): boolean} callback
|
* @param {function(this: T, number, ol.TileRange): boolean} callback Callback.
|
||||||
* Callback.
|
|
||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
@@ -328,7 +333,21 @@ ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Projection} projection Projection.
|
* @param {ol.Projection} projection Projection.
|
||||||
* @param {number=} opt_maxZoom Maximum zoom level (optional). Default is 18.
|
* @return {ol.tilegrid.TileGrid} Default tile grid for the passed projection.
|
||||||
|
*/
|
||||||
|
ol.tilegrid.getForProjection = function(projection) {
|
||||||
|
var tileGrid = projection.getDefaultTileGrid();
|
||||||
|
if (goog.isNull(tileGrid)) {
|
||||||
|
tileGrid = ol.tilegrid.createForProjection(projection);
|
||||||
|
projection.setDefaultTileGrid(tileGrid);
|
||||||
|
}
|
||||||
|
return tileGrid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
|
* @param {number=} opt_maxZoom Maximum zoom level.
|
||||||
* @param {ol.Size=} opt_tileSize Tile size.
|
* @param {ol.Size=} opt_tileSize Tile size.
|
||||||
* @return {ol.tilegrid.TileGrid} TileGrid instance.
|
* @return {ol.tilegrid.TileGrid} TileGrid instance.
|
||||||
*/
|
*/
|
||||||
@@ -339,7 +358,7 @@ ol.tilegrid.createForProjection =
|
|||||||
projectionExtent.maxX - projectionExtent.minX,
|
projectionExtent.maxX - projectionExtent.minX,
|
||||||
projectionExtent.maxY - projectionExtent.minY);
|
projectionExtent.maxY - projectionExtent.minY);
|
||||||
var maxZoom = goog.isDef(opt_maxZoom) ?
|
var maxZoom = goog.isDef(opt_maxZoom) ?
|
||||||
opt_maxZoom : 18;
|
opt_maxZoom : ol.DEFAULT_MAX_ZOOM;
|
||||||
var tileSize = goog.isDef(opt_tileSize) ?
|
var tileSize = goog.isDef(opt_tileSize) ?
|
||||||
opt_tileSize : new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE);
|
opt_tileSize : new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE);
|
||||||
var resolutions = new Array(maxZoom + 1);
|
var resolutions = new Array(maxZoom + 1);
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ goog.provide('ol.TileUrlFunctionType');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.source.wms');
|
||||||
goog.require('ol.tilegrid.TileGrid');
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function(ol.TileCoord): (string|undefined)}
|
* @typedef {function(ol.TileCoord, ol.tilegrid.TileGrid, ol.Projection):
|
||||||
|
* (string|undefined)}
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunctionType;
|
ol.TileUrlFunctionType;
|
||||||
|
|
||||||
@@ -59,12 +60,12 @@ ol.TileUrlFunction.createFromTemplates = function(templates) {
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord, tileGrid, projection) {
|
||||||
if (goog.isNull(tileCoord)) {
|
if (goog.isNull(tileCoord)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
||||||
return tileUrlFunctions[index](tileCoord);
|
return tileUrlFunctions[index](tileCoord, tileGrid, projection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -72,25 +73,20 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} baseUrl Base URL (may have query data).
|
* @param {string} baseUrl Base URL (may have query data).
|
||||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
* @param {Object.<string, string|number>} params WMS parameters.
|
||||||
* @param {string} axisOrientation Axis orientation.
|
* @param {string=} opt_version WMS version.
|
||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createBboxParam =
|
ol.TileUrlFunction.createWMSParams =
|
||||||
function(baseUrl, tileGrid, axisOrientation) {
|
function(baseUrl, params, opt_version) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord, tileGrid, projection) {
|
||||||
if (goog.isNull(tileCoord)) {
|
if (goog.isNull(tileCoord)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
|
var size = tileGrid.getTileSize();
|
||||||
var bboxValues = axisOrientation.substr(0, 2) == 'ne' ?
|
var extent = tileGrid.getTileCoordExtent(tileCoord);
|
||||||
[tileExtent.minY, tileExtent.minX, tileExtent.maxY, tileExtent.maxX] :
|
return ol.source.wms.getUrl(
|
||||||
[tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY];
|
baseUrl, params, extent, size, projection, opt_version);
|
||||||
var tileSize = tileGrid.getTileSize(tileCoord.z);
|
|
||||||
return goog.uri.utils.appendParams(baseUrl,
|
|
||||||
'BBOX', bboxValues.join(','),
|
|
||||||
'HEIGHT', tileSize.height,
|
|
||||||
'WIDTH', tileSize.width);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -106,18 +102,19 @@ ol.TileUrlFunction.nullTileUrlFunction = function(tileCoord) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function(ol.TileCoord): ol.TileCoord} transformFn
|
* @param {function(ol.TileCoord, ol.tilegrid.TileGrid, ol.Projection):
|
||||||
* Transform.function.
|
* ol.TileCoord} transformFn Transform.function.
|
||||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.withTileCoordTransform =
|
ol.TileUrlFunction.withTileCoordTransform =
|
||||||
function(transformFn, tileUrlFunction) {
|
function(transformFn, tileUrlFunction) {
|
||||||
return function(tileCoord) {
|
return function(tileCoord, tileGrid, projection) {
|
||||||
if (goog.isNull(tileCoord)) {
|
if (goog.isNull(tileCoord)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
return tileUrlFunction(transformFn(tileCoord));
|
return tileUrlFunction(
|
||||||
|
transformFn(tileCoord, tileGrid, projection), tileGrid, projection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ describe('ol.source.TileSource', function() {
|
|||||||
|
|
||||||
describe('#findLoadedTiles()', 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() {
|
it('adds no tiles if none are already loaded', function() {
|
||||||
// a source with no loaded tiles
|
// a source with no loaded tiles
|
||||||
var source = new ol.test.source.MockTileSource({});
|
var source = new ol.test.source.MockTileSource({});
|
||||||
@@ -25,7 +21,13 @@ describe('ol.source.TileSource', function() {
|
|||||||
var loadedTilesByZ = {};
|
var loadedTilesByZ = {};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3);
|
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);
|
var keys = goog.object.getKeys(loadedTilesByZ);
|
||||||
expect(keys.length).toBe(0);
|
expect(keys.length).toBe(0);
|
||||||
@@ -41,7 +43,13 @@ describe('ol.source.TileSource', function() {
|
|||||||
var loadedTilesByZ = {};
|
var loadedTilesByZ = {};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0);
|
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);
|
var keys = goog.object.getKeys(loadedTilesByZ);
|
||||||
expect(keys.length).toBe(1);
|
expect(keys.length).toBe(1);
|
||||||
var tile = loadedTilesByZ['0']['0/0/0'];
|
var tile = loadedTilesByZ['0']['0/0/0'];
|
||||||
@@ -59,7 +67,13 @@ describe('ol.source.TileSource', function() {
|
|||||||
var loadedTilesByZ = {};
|
var loadedTilesByZ = {};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
|
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);
|
var keys = goog.object.getKeys(loadedTilesByZ);
|
||||||
expect(keys.length).toBe(1);
|
expect(keys.length).toBe(1);
|
||||||
var tile = loadedTilesByZ['1']['1/0/0'];
|
var tile = loadedTilesByZ['1']['1/0/0'];
|
||||||
@@ -79,7 +93,13 @@ describe('ol.source.TileSource', function() {
|
|||||||
var loadedTilesByZ = {};
|
var loadedTilesByZ = {};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
|
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);
|
expect(loaded).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,7 +118,14 @@ describe('ol.source.TileSource', function() {
|
|||||||
};
|
};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
|
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);
|
expect(loaded).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -114,7 +141,14 @@ describe('ol.source.TileSource', function() {
|
|||||||
var loadedTilesByZ = {};
|
var loadedTilesByZ = {};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
|
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);
|
expect(loaded).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,7 +166,14 @@ describe('ol.source.TileSource', function() {
|
|||||||
};
|
};
|
||||||
var grid = source.getTileGrid();
|
var grid = source.getTileGrid();
|
||||||
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
|
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);
|
expect(loaded).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ goog.provide('ol.test.source.XYZ');
|
|||||||
|
|
||||||
describe('ol.source.XYZ', function() {
|
describe('ol.source.XYZ', function() {
|
||||||
|
|
||||||
describe('getTileCoordUrl', function() {
|
describe('tileUrlFunction', function() {
|
||||||
|
|
||||||
var xyzTileSource, tileGrid;
|
var xyzTileSource, tileGrid;
|
||||||
|
|
||||||
@@ -18,59 +18,59 @@ describe('ol.source.XYZ', function() {
|
|||||||
var coordinate = new ol.Coordinate(829330.2064098881, 5933916.615134273);
|
var coordinate = new ol.Coordinate(829330.2064098881, 5933916.615134273);
|
||||||
var tileUrl;
|
var tileUrl;
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
||||||
expect(tileUrl).toEqual('0/0/0');
|
expect(tileUrl).toEqual('0/0/0');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
||||||
expect(tileUrl).toEqual('1/1/0');
|
expect(tileUrl).toEqual('1/1/0');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
||||||
expect(tileUrl).toEqual('2/2/1');
|
expect(tileUrl).toEqual('2/2/1');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
||||||
expect(tileUrl).toEqual('3/4/2');
|
expect(tileUrl).toEqual('3/4/2');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
||||||
expect(tileUrl).toEqual('4/8/5');
|
expect(tileUrl).toEqual('4/8/5');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
||||||
expect(tileUrl).toEqual('5/16/11');
|
expect(tileUrl).toEqual('5/16/11');
|
||||||
|
|
||||||
tileUrl = xyzTileSource.getTileCoordUrl(
|
tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
||||||
expect(tileUrl).toEqual('6/33/22');
|
expect(tileUrl).toEqual('6/33/22');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('wrap x', function() {
|
describe('wrap x', function() {
|
||||||
it('returns the expected URL', function() {
|
it('returns the expected URL', function() {
|
||||||
var tileUrl = xyzTileSource.getTileCoordUrl(
|
var tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
new ol.TileCoord(6, -31, -23));
|
new ol.TileCoord(6, -31, -23));
|
||||||
expect(tileUrl).toEqual('6/33/22');
|
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');
|
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');
|
expect(tileUrl).toEqual('6/33/22');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('crop y', function() {
|
describe('crop y', function() {
|
||||||
it('returns the expected URL', function() {
|
it('returns the expected URL', function() {
|
||||||
var tileUrl = xyzTileSource.getTileCoordUrl(
|
var tileUrl = xyzTileSource.tileUrlFunction(
|
||||||
new ol.TileCoord(6, 33, -87));
|
new ol.TileCoord(6, 33, -87));
|
||||||
expect(tileUrl).toBeUndefined();
|
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');
|
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();
|
expect(tileUrl).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -169,16 +169,16 @@ describe('ol.tilegrid.TileGrid', function() {
|
|||||||
expect(grid).toBeA(ol.tilegrid.TileGrid);
|
expect(grid).toBeA(ol.tilegrid.TileGrid);
|
||||||
|
|
||||||
var resolutions = grid.getResolutions();
|
var resolutions = grid.getResolutions();
|
||||||
expect(resolutions.length).toBe(19);
|
expect(resolutions.length).toBe(ol.DEFAULT_MAX_ZOOM + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts a number of zoom levels', function() {
|
it('accepts a number of zoom levels', function() {
|
||||||
var projection = ol.projection.getFromCode('EPSG:3857');
|
var projection = ol.projection.getFromCode('EPSG:3857');
|
||||||
var grid = ol.tilegrid.createForProjection(projection, 22);
|
var grid = ol.tilegrid.createForProjection(projection, 18);
|
||||||
expect(grid).toBeA(ol.tilegrid.TileGrid);
|
expect(grid).toBeA(ol.tilegrid.TileGrid);
|
||||||
|
|
||||||
var resolutions = grid.getResolutions();
|
var resolutions = grid.getResolutions();
|
||||||
expect(resolutions.length).toBe(23);
|
expect(resolutions.length).toBe(19);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts a big number of zoom levels', function() {
|
it('accepts a big number of zoom levels', function() {
|
||||||
@@ -192,6 +192,28 @@ describe('ol.tilegrid.TileGrid', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getForProjection', function() {
|
||||||
|
|
||||||
|
it('gets the default tile grid for a projection', function() {
|
||||||
|
var projection = ol.projection.getFromCode('EPSG:3857');
|
||||||
|
var grid = ol.tilegrid.getForProjection(projection);
|
||||||
|
expect(grid).toBeA(ol.tilegrid.TileGrid);
|
||||||
|
|
||||||
|
var resolutions = grid.getResolutions();
|
||||||
|
expect(resolutions.length).toBe(ol.DEFAULT_MAX_ZOOM + 1);
|
||||||
|
expect(grid.getTileSize().toString()).toBe('(256 x 256)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stores the default tile grid on a projection', function() {
|
||||||
|
var projection = ol.projection.getFromCode('EPSG:3857');
|
||||||
|
var grid = ol.tilegrid.getForProjection(projection);
|
||||||
|
var gridAgain = ol.tilegrid.getForProjection(projection);
|
||||||
|
|
||||||
|
expect(grid).toBe(gridAgain);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('getTileCoordFromCoordAndZ', function() {
|
describe('getTileCoordFromCoordAndZ', function() {
|
||||||
|
|
||||||
describe('Y North, X East', function() {
|
describe('Y North, X East', function() {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ describe('ol.TileUrlFunction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createBboxParam', function() {
|
describe('createWMSParams', function() {
|
||||||
var tileGrid;
|
var tileGrid;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
tileGrid = new ol.tilegrid.XYZ({
|
tileGrid = new ol.tilegrid.XYZ({
|
||||||
@@ -70,24 +70,26 @@ describe('ol.TileUrlFunction', function() {
|
|||||||
});
|
});
|
||||||
it('creates expected URL', function() {
|
it('creates expected URL', function() {
|
||||||
var epsg3857 = ol.projection.getFromCode('EPSG:3857');
|
var epsg3857 = ol.projection.getFromCode('EPSG:3857');
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createBboxParam(
|
var tileUrlFunction = ol.TileUrlFunction.createWMSParams(
|
||||||
'http://wms?foo=bar', tileGrid, epsg3857.getAxisOrientation());
|
'http://wms?foo=bar', {});
|
||||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||||
var tileUrl = tileUrlFunction(tileCoord);
|
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857);
|
||||||
var expected = 'http://wms?foo=bar&BBOX=-20037508.342789244' +
|
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
|
||||||
'%2C20037508.342789244%2C0%2C40075016.68557849' +
|
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
|
||||||
'&HEIGHT=256&WIDTH=256';
|
'HEIGHT=256&BBOX=-20037508.342789244%2C20037508.342789244%2C0%2C' +
|
||||||
|
'40075016.68557849&CRS=EPSG%3A3857&STYLES=';
|
||||||
expect(tileUrl).toEqual(expected);
|
expect(tileUrl).toEqual(expected);
|
||||||
});
|
});
|
||||||
it('creates expected URL respecting axis orientation', function() {
|
it('creates expected URL respecting axis orientation', function() {
|
||||||
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
|
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createBboxParam(
|
var tileUrlFunction = ol.TileUrlFunction.createWMSParams(
|
||||||
'http://wms?foo=bar', tileGrid, epsg4326.getAxisOrientation());
|
'http://wms?foo=bar', {});
|
||||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||||
var tileUrl = tileUrlFunction(tileCoord);
|
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326);
|
||||||
var expected = 'http://wms?foo=bar&BBOX=20037508.342789244' +
|
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
|
||||||
'%2C-20037508.342789244%2C40075016.68557849%2C0' +
|
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
|
||||||
'&HEIGHT=256&WIDTH=256';
|
'HEIGHT=256&BBOX=20037508.342789244%2C-20037508.342789244%2C' +
|
||||||
|
'40075016.68557849%2C0&CRS=EPSG%3A4326&STYLES=';
|
||||||
expect(tileUrl).toEqual(expected);
|
expect(tileUrl).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user