Merge pull request #402 from ahocevar/more-context

More convenient url functions for WMS. r=@elemoine,@twpayne
This commit is contained in:
ahocevar
2013-03-20 06:22:36 -07:00
6 changed files with 79 additions and 48 deletions

View File

@@ -3,24 +3,26 @@ goog.provide('ol.ImageUrlFunctionType');
goog.require('ol.Extent');
goog.require('ol.Size');
goog.require('ol.source.wms');
/**
* @typedef {function(ol.Extent, ol.Size, ol.Projection): (string|undefined)}
* @typedef {function(this:ol.source.Source, ol.Extent, ol.Size, ol.Projection):
* (string|undefined)}
*/
ol.ImageUrlFunctionType;
/**
* @param {string} baseUrl Base URL (may have query data).
* @param {Object.<string, string|number>} params WMS parameters.
* @param {Object.<string,*>} params to encode in the url.
* @param {function(string, Object.<string,*>, ol.Extent, ol.Size,
* ol.Projection)} paramsFunction params function.
* @return {ol.ImageUrlFunctionType} Image URL function.
*/
ol.ImageUrlFunction.createWMSParams =
function(baseUrl, params) {
ol.ImageUrlFunction.createFromParamsFunction =
function(baseUrl, params, paramsFunction) {
return function(extent, size, projection) {
return ol.source.wms.getUrl(
return paramsFunction(
baseUrl, params, extent, size, projection);
};
};

View File

@@ -5,6 +5,7 @@ goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.Size');
goog.require('ol.source.ImageSource');
goog.require('ol.source.wms');
@@ -15,7 +16,8 @@ goog.require('ol.source.ImageSource');
*/
ol.source.SingleImageWMS = function(options) {
var imageUrlFunction = goog.isDef(options.url) ?
ol.ImageUrlFunction.createWMSParams(options.url, options.params) :
ol.ImageUrlFunction.createFromParamsFunction(
options.url, options.params, ol.source.wms.getUrl) :
ol.ImageUrlFunction.nullImageUrlFunction;
goog.base(this, {

View File

@@ -8,6 +8,7 @@ goog.require('ol.Extent');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.source.ImageTileSource');
goog.require('ol.source.wms');
@@ -30,12 +31,13 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
if (goog.isDef(urls)) {
var tileUrlFunctions = goog.array.map(
urls, function(url) {
return ol.TileUrlFunction.createWMSParams(
url, tiledWMSOptions.params);
return ol.TileUrlFunction.createFromParamsFunction(
url, tiledWMSOptions.params, ol.source.wms.getUrl);
});
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
tileUrlFunctions);
}
var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ?
tiledWMSOptions.params['TRANSPARENT'] : true;
var extent = tiledWMSOptions.extent;

View File

@@ -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,18 +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 {Object.<string,*>} params to encode in the url.
* @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, params, 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(
return paramsFunction(
baseUrl, params, extent, size, projection);
}
};
@@ -102,7 +103,7 @@ ol.TileUrlFunction.withTileCoordTransform =
if (goog.isNull(tileCoord)) {
return undefined;
} else {
return tileUrlFunction(
return tileUrlFunction.call(this,
transformFn(tileCoord, tileGrid, projection), tileGrid, projection);
}
};