getGetLegendRequestUrl accepts a LAYER parameter now

This commit is contained in:
simonseyock
2019-08-07 15:15:53 +02:00
committed by Simon Seyock
parent b2885e86fb
commit 89e8d6d693
4 changed files with 36 additions and 18 deletions

View File

@@ -197,15 +197,15 @@ class ImageWMS extends ImageSource {
* *
* @param {number} [resolution] Resolution. If set to undefined, `SCALE` * @param {number} [resolution] Resolution. If set to undefined, `SCALE`
* will not be calculated and included in URL. * will not be calculated and included in URL.
* @param {Object} [params] GetLegendGraphic params. Default `FORMAT` is * @param {Object} [params] GetLegendGraphic params. If `LAYER` is set, the
* `image/png`. `VERSION` should not be specified here. * request is generated for this wms layer, else it will try to use the
* configured wms layer. Default `FORMAT` is `image/png`.
* `VERSION` should not be specified here.
* @return {string|undefined} GetLegendGraphic URL. * @return {string|undefined} GetLegendGraphic URL.
* @api * @api
*/ */
getLegendUrl(resolution, params) { getLegendUrl(resolution, params) {
const layers = this.params_.LAYERS; if (this.url_ === undefined) {
const isSingleLayer = !Array.isArray(layers) || this.params_['LAYERS'].length === 1;
if (this.url_ === undefined || !isSingleLayer) {
return undefined; return undefined;
} }
@@ -213,10 +213,18 @@ class ImageWMS extends ImageSource {
'SERVICE': 'WMS', 'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION, 'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetLegendGraphic', 'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png', 'FORMAT': 'image/png'
'LAYER': layers
}; };
if (params === undefined || params['LAYER'] === undefined) {
const layers = this.params_.LAYERS;
const isSingleLayer = !Array.isArray(layers) || layers.length === 1;
if (!isSingleLayer) {
return undefined;
}
baseParams['LAYER'] = layers;
}
if (resolution !== undefined) { if (resolution !== undefined) {
const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1; const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1;
const dpi = 25.4 / 0.28; const dpi = 25.4 / 0.28;

View File

@@ -219,15 +219,15 @@ class TileWMS extends TileImage {
* *
* @param {number} [resolution] Resolution. If set to undefined, `SCALE` * @param {number} [resolution] Resolution. If set to undefined, `SCALE`
* will not be calculated and included in URL. * will not be calculated and included in URL.
* @param {Object} [params] GetLegendGraphic params. Default `FORMAT` is * @param {Object} [params] GetLegendGraphic params. If `LAYER` is set, the
* `image/png`. `VERSION` should not be specified here. * request is generated for this wms layer, else it will try to use the
* configured wms layer. Default `FORMAT` is `image/png`.
* `VERSION` should not be specified here.
* @return {string|undefined} GetLegendGraphic URL. * @return {string|undefined} GetLegendGraphic URL.
* @api * @api
*/ */
getLegendUrl(resolution, params) { getLegendUrl(resolution, params) {
const layers = this.params_.LAYERS; if (this.urls[0] === undefined) {
const isSingleLayer = !Array.isArray(layers) || this.params_['LAYERS'].length === 1;
if (this.urls[0] === undefined || !isSingleLayer) {
return undefined; return undefined;
} }
@@ -235,10 +235,18 @@ class TileWMS extends TileImage {
'SERVICE': 'WMS', 'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION, 'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetLegendGraphic', 'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png', 'FORMAT': 'image/png'
'LAYER': layers
}; };
if (params === undefined || params['LAYER'] === undefined) {
const layers = this.params_.LAYERS;
const isSingleLayer = !Array.isArray(layers) || layers.length === 1;
if (!isSingleLayer) {
return undefined;
}
baseParams['LAYER'] = layers;
}
if (resolution !== undefined) { if (resolution !== undefined) {
const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1; const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1;
const dpi = 25.4 / 0.28; const dpi = 25.4 / 0.28;

View File

@@ -368,7 +368,8 @@ describe('ol.source.ImageWMS', function() {
WIDTH: 'WIDTH_VALUE', WIDTH: 'WIDTH_VALUE',
HEIGHT: 'HEIGHT_VALUE', HEIGHT: 'HEIGHT_VALUE',
EXCEPTIONS: 'EXCEPTIONS_VALUE', EXCEPTIONS: 'EXCEPTIONS_VALUE',
LANGUAGE: 'LANGUAGE_VALUE' LANGUAGE: 'LANGUAGE_VALUE',
LAYER: 'LAYER_VALUE'
}); });
const uri = new URL(url); const uri = new URL(url);
expect(uri.protocol).to.be('http:'); expect(uri.protocol).to.be('http:');
@@ -376,7 +377,7 @@ describe('ol.source.ImageWMS', function() {
expect(uri.pathname).to.be('/wms'); expect(uri.pathname).to.be('/wms');
const queryData = uri.searchParams; const queryData = uri.searchParams;
expect(queryData.get('FORMAT')).to.be('FORMAT_VALUE'); expect(queryData.get('FORMAT')).to.be('FORMAT_VALUE');
expect(queryData.get('LAYER')).to.be('layer'); expect(queryData.get('LAYER')).to.be('LAYER_VALUE');
expect(queryData.get('REQUEST')).to.be('GetLegendGraphic'); expect(queryData.get('REQUEST')).to.be('GetLegendGraphic');
expect(queryData.get('SERVICE')).to.be('WMS'); expect(queryData.get('SERVICE')).to.be('WMS');
expect(queryData.get('VERSION')).to.be('1.3.0'); expect(queryData.get('VERSION')).to.be('1.3.0');

View File

@@ -337,7 +337,8 @@ describe('ol.source.TileWMS', function() {
WIDTH: 'WIDTH_VALUE', WIDTH: 'WIDTH_VALUE',
HEIGHT: 'HEIGHT_VALUE', HEIGHT: 'HEIGHT_VALUE',
EXCEPTIONS: 'EXCEPTIONS_VALUE', EXCEPTIONS: 'EXCEPTIONS_VALUE',
LANGUAGE: 'LANGUAGE_VALUE' LANGUAGE: 'LANGUAGE_VALUE',
LAYER: 'LAYER_VALUE'
}); });
const uri = new URL(url); const uri = new URL(url);
expect(uri.protocol).to.be('http:'); expect(uri.protocol).to.be('http:');
@@ -345,7 +346,7 @@ describe('ol.source.TileWMS', function() {
expect(uri.pathname).to.be('/wms'); expect(uri.pathname).to.be('/wms');
const queryData = uri.searchParams; const queryData = uri.searchParams;
expect(queryData.get('FORMAT')).to.be('FORMAT_VALUE'); expect(queryData.get('FORMAT')).to.be('FORMAT_VALUE');
expect(queryData.get('LAYER')).to.be('layer'); expect(queryData.get('LAYER')).to.be('LAYER_VALUE');
expect(queryData.get('REQUEST')).to.be('GetLegendGraphic'); expect(queryData.get('REQUEST')).to.be('GetLegendGraphic');
expect(queryData.get('SERVICE')).to.be('WMS'); expect(queryData.get('SERVICE')).to.be('WMS');
expect(queryData.get('VERSION')).to.be('1.3.0'); expect(queryData.get('VERSION')).to.be('1.3.0');