WMS GetMap request parameters shall be params
To avoid surprises, we configure everything that is a WMS GetMap request parameter in the params object, and not as direct configuration option. This affects the VERSION and TRANSPARENT params.
This commit is contained in:
@@ -111,7 +111,6 @@
|
|||||||
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined
|
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined
|
||||||
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
|
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
|
||||||
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
|
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
|
||||||
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.version string|undefined
|
|
||||||
|
|
||||||
@exportObjectLiteral ol.source.StamenOptions
|
@exportObjectLiteral ol.source.StamenOptions
|
||||||
@exportObjectLiteralProperty ol.source.StamenOptions.flavor string|undefined
|
@exportObjectLiteralProperty ol.source.StamenOptions.flavor string|undefined
|
||||||
@@ -129,11 +128,9 @@
|
|||||||
@exportObjectLiteral ol.source.TiledWMSOptions
|
@exportObjectLiteral ol.source.TiledWMSOptions
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.<ol.Attribution>|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.<ol.Attribution>|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.params Object
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.params Object
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.version string|undefined
|
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.crossOrigin null|string|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.crossOrigin null|string|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.transparent boolean|undefined
|
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined
|
||||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
|
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
|
||||||
|
|||||||
@@ -15,14 +15,13 @@ ol.ImageUrlFunctionType;
|
|||||||
/**
|
/**
|
||||||
* @param {string} baseUrl Base URL (may have query data).
|
* @param {string} baseUrl Base URL (may have query data).
|
||||||
* @param {Object.<string, string|number>} params WMS parameters.
|
* @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.createWMSParams =
|
ol.ImageUrlFunction.createWMSParams =
|
||||||
function(baseUrl, params, opt_version) {
|
function(baseUrl, params) {
|
||||||
return function(extent, size, projection) {
|
return function(extent, size, projection) {
|
||||||
return ol.source.wms.getUrl(
|
return ol.source.wms.getUrl(
|
||||||
baseUrl, params, extent, size, projection, opt_version);
|
baseUrl, params, extent, size, projection);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ goog.require('ol.source.ImageSource');
|
|||||||
*/
|
*/
|
||||||
ol.source.SingleImageWMS = function(options) {
|
ol.source.SingleImageWMS = function(options) {
|
||||||
var imageUrlFunction = goog.isDef(options.url) ?
|
var imageUrlFunction = goog.isDef(options.url) ?
|
||||||
ol.ImageUrlFunction.createWMSParams(
|
ol.ImageUrlFunction.createWMSParams(options.url, options.params) :
|
||||||
options.url, options.params, options.version) :
|
|
||||||
ol.ImageUrlFunction.nullImageUrlFunction;
|
ol.ImageUrlFunction.nullImageUrlFunction;
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
|
|||||||
@@ -21,25 +21,24 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
|
|||||||
if (goog.isDef(tiledWMSOptions.tileGrid)) {
|
if (goog.isDef(tiledWMSOptions.tileGrid)) {
|
||||||
tileGrid = tiledWMSOptions.tileGrid;
|
tileGrid = tiledWMSOptions.tileGrid;
|
||||||
}
|
}
|
||||||
var version = tiledWMSOptions.version;
|
|
||||||
|
|
||||||
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) {
|
||||||
return ol.TileUrlFunction.createWMSParams(
|
return ol.TileUrlFunction.createWMSParams(
|
||||||
url, tiledWMSOptions.params, version);
|
url, tiledWMSOptions.params);
|
||||||
});
|
});
|
||||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||||
tileUrlFunctions);
|
tileUrlFunctions);
|
||||||
} else if (tiledWMSOptions.url) {
|
} else if (tiledWMSOptions.url) {
|
||||||
tileUrlFunction = ol.TileUrlFunction.createWMSParams(
|
tileUrlFunction = ol.TileUrlFunction.createWMSParams(
|
||||||
tiledWMSOptions.url, tiledWMSOptions.params, version);
|
tiledWMSOptions.url, tiledWMSOptions.params);
|
||||||
} else {
|
} else {
|
||||||
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
}
|
}
|
||||||
var transparent = goog.isDef(tiledWMSOptions.transparent) ?
|
var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ?
|
||||||
tiledWMSOptions.transparent : true;
|
tiledWMSOptions.params['TRANSPARENT'] : true;
|
||||||
var extent = tiledWMSOptions.extent;
|
var extent = tiledWMSOptions.extent;
|
||||||
|
|
||||||
var tileCoordTransform = function(tileCoord, tileGrid, projection) {
|
var tileCoordTransform = function(tileCoord, tileGrid, projection) {
|
||||||
|
|||||||
+14
-12
@@ -7,31 +7,33 @@ goog.provide('ol.source.wms');
|
|||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size} size Size.
|
||||||
* @param {ol.Projection} projection Projection.
|
* @param {ol.Projection} projection Projection.
|
||||||
* @param {string=} opt_version WMS version. Default is '1.3.0'.
|
|
||||||
* @return {string} WMS GetMap request URL.
|
* @return {string} WMS GetMap request URL.
|
||||||
*/
|
*/
|
||||||
ol.source.wms.getUrl =
|
ol.source.wms.getUrl =
|
||||||
function(baseUrl, params, extent, size, projection, opt_version) {
|
function(baseUrl, params, extent, size, projection) {
|
||||||
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 = {
|
var baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': version,
|
'VERSION': '1.3.0',
|
||||||
'REQUEST': 'GetMap',
|
'REQUEST': 'GetMap',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'TRANSPARENT': true,
|
'TRANSPARENT': true,
|
||||||
'WIDTH': size.width,
|
'WIDTH': size.width,
|
||||||
'HEIGHT': size.height,
|
'HEIGHT': size.height
|
||||||
'BBOX': bboxValues.join(',')
|
|
||||||
};
|
};
|
||||||
goog.object.extend(baseParams, params);
|
goog.object.extend(baseParams, params);
|
||||||
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
|
|
||||||
//TODO: Provide our own appendParams function to avoid this empty string hack
|
//TODO: Provide our own appendParams function to avoid this empty string hack
|
||||||
var stylesParam = 'STYLES';
|
var stylesParam = 'STYLES';
|
||||||
baseParams[stylesParam] = params[stylesParam] || new String('');
|
baseParams[stylesParam] = params[stylesParam] || new String('');
|
||||||
|
|
||||||
|
var wms13 = baseParams['VERSION'] > '1.3';
|
||||||
|
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
|
||||||
|
|
||||||
|
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];
|
||||||
|
baseParams['BBOX'] = bboxValues.join(',');
|
||||||
|
|
||||||
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,11 +74,10 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
|||||||
/**
|
/**
|
||||||
* @param {string} baseUrl Base URL (may have query data).
|
* @param {string} baseUrl Base URL (may have query data).
|
||||||
* @param {Object.<string, string|number>} params WMS parameters.
|
* @param {Object.<string, string|number>} params WMS parameters.
|
||||||
* @param {string=} opt_version WMS version.
|
|
||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createWMSParams =
|
ol.TileUrlFunction.createWMSParams =
|
||||||
function(baseUrl, params, opt_version) {
|
function(baseUrl, params) {
|
||||||
return function(tileCoord, tileGrid, projection) {
|
return function(tileCoord, tileGrid, projection) {
|
||||||
if (goog.isNull(tileCoord)) {
|
if (goog.isNull(tileCoord)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -86,7 +85,7 @@ ol.TileUrlFunction.createWMSParams =
|
|||||||
var size = tileGrid.getTileSize(tileCoord.z);
|
var size = tileGrid.getTileSize(tileCoord.z);
|
||||||
var extent = tileGrid.getTileCoordExtent(tileCoord);
|
var extent = tileGrid.getTileCoordExtent(tileCoord);
|
||||||
return ol.source.wms.getUrl(
|
return ol.source.wms.getUrl(
|
||||||
baseUrl, params, extent, size, projection, opt_version);
|
baseUrl, params, extent, size, projection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,10 +74,10 @@ describe('ol.TileUrlFunction', function() {
|
|||||||
'http://wms?foo=bar', {});
|
'http://wms?foo=bar', {});
|
||||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||||
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857);
|
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857);
|
||||||
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
|
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
|
||||||
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
|
'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
|
||||||
'HEIGHT=256&BBOX=-20037508.342789244%2C20037508.342789244%2C0%2C' +
|
'STYLES=&CRS=EPSG%3A3857&BBOX=-20037508.342789244%2C2' +
|
||||||
'40075016.68557849&CRS=EPSG%3A3857&STYLES=';
|
'0037508.342789244%2C0%2C40075016.68557849';
|
||||||
expect(tileUrl).toEqual(expected);
|
expect(tileUrl).toEqual(expected);
|
||||||
});
|
});
|
||||||
it('creates expected URL respecting axis orientation', function() {
|
it('creates expected URL respecting axis orientation', function() {
|
||||||
@@ -86,10 +86,10 @@ describe('ol.TileUrlFunction', function() {
|
|||||||
'http://wms?foo=bar', {});
|
'http://wms?foo=bar', {});
|
||||||
var tileCoord = new ol.TileCoord(1, 0, 0);
|
var tileCoord = new ol.TileCoord(1, 0, 0);
|
||||||
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326);
|
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326);
|
||||||
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' +
|
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
|
||||||
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' +
|
'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
|
||||||
'HEIGHT=256&BBOX=20037508.342789244%2C-20037508.342789244%2C' +
|
'STYLES=&CRS=EPSG%3A4326&BBOX=20037508.342789244%2C' +
|
||||||
'40075016.68557849%2C0&CRS=EPSG%3A4326&STYLES=';
|
'-20037508.342789244%2C40075016.68557849%2C0';
|
||||||
expect(tileUrl).toEqual(expected);
|
expect(tileUrl).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user