More context for url functions
With this change, url functions are called in the scope of the source they are configured for. This allows us to simplify the url function generation for WMS, using a more generic createFromParamsFunction factory, and the source's new params member. Note that there is also a new url member for WMS sources. This is the WMS base url (the first one in case there is an array of urls for faster tile access). This can be used for accessing other WMS services (especially GetFeatureInfo).
This commit is contained in:
@@ -4,13 +4,12 @@ goog.provide('ol.TileUrlFunctionType');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.source.wms');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function(ol.TileCoord, ol.tilegrid.TileGrid, ol.Projection):
|
||||
* (string|undefined)}
|
||||
* @typedef {function(this:ol.source.Source, ol.TileCoord, ol.tilegrid.TileGrid,
|
||||
* ol.Projection): (string|undefined)}
|
||||
*/
|
||||
ol.TileUrlFunctionType;
|
||||
|
||||
@@ -63,19 +62,20 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl Base URL (may have query data).
|
||||
* @param {Object.<string, string|number>} params WMS parameters.
|
||||
* @param {function(string, Object.<string,*>, ol.Extent, ol.Size,
|
||||
* ol.Projection)} paramsFunction params function.
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
ol.TileUrlFunction.createWMSParams =
|
||||
function(baseUrl, params) {
|
||||
ol.TileUrlFunction.createFromParamsFunction =
|
||||
function(baseUrl, paramsFunction) {
|
||||
return function(tileCoord, tileGrid, projection) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
var size = tileGrid.getTileSize(tileCoord.z);
|
||||
var extent = tileGrid.getTileCoordExtent(tileCoord);
|
||||
return ol.source.wms.getUrl(
|
||||
baseUrl, params, extent, size, projection);
|
||||
return paramsFunction(
|
||||
baseUrl, this.params, extent, size, projection);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -102,7 +102,7 @@ ol.TileUrlFunction.withTileCoordTransform =
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
return tileUrlFunction(
|
||||
return tileUrlFunction.call(this,
|
||||
transformFn(tileCoord, tileGrid, projection), tileGrid, projection);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user