Merge pull request #9762 from KlausBenndorf/get-legend-request

Get legend request
This commit is contained in:
Marc Jansen
2019-07-22 13:54:01 +02:00
committed by GitHub
6 changed files with 267 additions and 1 deletions

View File

@@ -191,6 +191,43 @@ class ImageWMS extends ImageSource {
1, sourceProjectionObj || projectionObj, baseParams);
}
/**
* Return the GetLegendGraphic URL for the passed resolution.
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
* @param {!number} resolution Resolution. If set to undefined `SCALE`
* will not be calculated.
* @param {!Object} params GetLegendGraphic params. Default `FORMAT` is
* `image/png`. `VERSION` should not be specified here.
* @return {string|undefined} GetLegendGraphic URL.
* @api
*/
getGetLegendGraphicUrl(resolution, params) {
const layers = this.params_.LAYERS;
const isSingleLayer = !Array.isArray(layers) || this.params_['LAYERS'].length === 1;
if (this.url_ === undefined || !isSingleLayer) {
return undefined;
}
const baseParams = {
'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png',
'LAYER': layers
};
if (resolution !== undefined) {
const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1;
const dpi = 25.4 / 0.28;
const inchesPerMeter = 39.37;
baseParams['SCALE'] = resolution * mpu * inchesPerMeter * dpi;
}
assign(baseParams, params);
return appendParams(/** @type {string} */ (this.url_), baseParams);
}
/**
* Get the user-provided params, i.e. those passed to the constructor through
* the "params" option, and possibly updated using the updateParams method.

View File

@@ -211,6 +211,43 @@ class TileWMS extends TileImage {
1, sourceProjectionObj || projectionObj, baseParams);
}
/**
* Return the GetLegendGraphic URL for the passed resolution.
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
* @param {!number} resolution Resolution. If set to undefined `SCALE`
* will not be calculated.
* @param {!Object} params GetLegendGraphic params. Default `FORMAT` is
* `image/png`. `VERSION` should not be specified here.
* @return {string|undefined} GetLegendGraphic URL.
* @api
*/
getGetLegendGraphicUrl(resolution, params) {
const layers = this.params_.LAYERS;
const isSingleLayer = !Array.isArray(layers) || this.params_['LAYERS'].length === 1;
if (this.urls[0] === undefined || !isSingleLayer) {
return undefined;
}
const baseParams = {
'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png',
'LAYER': layers
};
if (resolution !== undefined) {
const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1;
const dpi = 25.4 / 0.28;
const inchesPerMeter = 39.37;
baseParams['SCALE'] = resolution * mpu * inchesPerMeter * dpi;
}
assign(baseParams, params);
return appendParams(/** @type {string} */ (this.urls[0]), baseParams);
}
/**
* @inheritDoc
*/