Cope with axis orientation for tiled WMS sources
This commit is contained in:
@@ -52,19 +52,22 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
|
||||
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
|
||||
goog.object.extend(baseParams, tiledWMSOptions.params);
|
||||
|
||||
var axisOrientation = projection.getAxisOrientation();
|
||||
var tileUrlFunction;
|
||||
if (tiledWMSOptions.urls) {
|
||||
var tileUrlFunctions = goog.array.map(
|
||||
tiledWMSOptions.urls, function(url) {
|
||||
url = goog.uri.utils.appendParamsFromMap(url, baseParams);
|
||||
return ol.TileUrlFunction.createBboxParam(url, tileGrid);
|
||||
return ol.TileUrlFunction.createBboxParam(
|
||||
url, tileGrid, axisOrientation);
|
||||
});
|
||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
tileUrlFunctions);
|
||||
} else if (tiledWMSOptions.url) {
|
||||
var url = goog.uri.utils.appendParamsFromMap(
|
||||
tiledWMSOptions.url, baseParams);
|
||||
tileUrlFunction = ol.TileUrlFunction.createBboxParam(url, tileGrid);
|
||||
tileUrlFunction =
|
||||
ol.TileUrlFunction.createBboxParam(url, tileGrid, axisOrientation);
|
||||
} else {
|
||||
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||
}
|
||||
|
||||
@@ -73,19 +73,20 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||
/**
|
||||
* @param {string} baseUrl Base URL (may have query data).
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @param {string} axisOrientation Axis orientation.
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
ol.TileUrlFunction.createBboxParam = function(baseUrl, tileGrid) {
|
||||
ol.TileUrlFunction.createBboxParam =
|
||||
function(baseUrl, tileGrid, axisOrientation) {
|
||||
return function(tileCoord) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
|
||||
// FIXME Projection dependant axis order.
|
||||
var bboxValue = [
|
||||
tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY
|
||||
].join(',');
|
||||
return goog.uri.utils.appendParam(baseUrl, 'BBOX', bboxValue);
|
||||
var bboxValues = axisOrientation.substr(0, 2) == 'ne' ?
|
||||
[tileExtent.minY, tileExtent.minX, tileExtent.maxY, tileExtent.maxX] :
|
||||
[tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY];
|
||||
return goog.uri.utils.appendParam(baseUrl, 'BBOX', bboxValues.join(','));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -69,14 +69,25 @@ describe('ol.TileUrlFunction', function() {
|
||||
});
|
||||
});
|
||||
it('creates expected URL', function() {
|
||||
var epsg3857 = ol.Projection.getFromCode('EPSG:3857');
|
||||
var tileUrlFunction = ol.TileUrlFunction.createBboxParam(
|
||||
'http://wms?foo=bar', tileGrid);
|
||||
'http://wms?foo=bar', tileGrid, epsg3857.getAxisOrientation());
|
||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||
var tileUrl = tileUrlFunction(tileCoord);
|
||||
var expected = 'http://wms?foo=bar&BBOX=-20037508.342789244' +
|
||||
'%2C20037508.342789244%2C0%2C40075016.68557849';
|
||||
expect(tileUrl).toEqual(expected);
|
||||
});
|
||||
it('creates expected URL respecting axis orientation', function() {
|
||||
var epsg4326 = ol.Projection.getFromCode('EPSG:4326');
|
||||
var tileUrlFunction = ol.TileUrlFunction.createBboxParam(
|
||||
'http://wms?foo=bar', tileGrid, epsg4326.getAxisOrientation());
|
||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||
var tileUrl = tileUrlFunction(tileCoord);
|
||||
var expected = 'http://wms?foo=bar&BBOX=20037508.342789244' +
|
||||
'%2C-20037508.342789244%2C40075016.68557849%2C0';
|
||||
expect(tileUrl).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user