Add ol.TileUrlFunction.createBboxParam

This commit is contained in:
Éric Lemoine
2012-11-03 22:42:37 +01:00
parent 3d84571043
commit 529c3e8b6a
3 changed files with 96 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ goog.provide('ol.TileUrlFunctionType');
goog.require('goog.math');
goog.require('ol.TileCoord');
goog.require('ol.tilegrid.TileGrid');
/**
@@ -67,6 +68,35 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
};
/**
* @param {string} baseUrl WMS base URL.
* @param {Object} baseParams Query string parameters.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createBboxParam = function(baseUrl, baseParams, tileGrid) {
return function(tileCoord) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
var params = goog.object.clone(baseParams);
// FIXME Projection dependant axis order.
var bboxValue = [
tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY
].join(',');
goog.object.extend(params, {'BBOX': bboxValue});
var url = baseUrl;
for (var p in params) {
url += (~url.indexOf('?') ? '&' : '?') +
p + '=' + encodeURIComponent(params[p]);
}
return url;
}
};
};
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @return {string|undefined} Tile URL.