make resolution in getGetLegendGraphicUrl optional
This commit is contained in:
@@ -194,7 +194,8 @@ class ImageWMS extends ImageSource {
|
||||
/**
|
||||
* Return the GetLegendGraphic URL for the passed resolution.
|
||||
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
|
||||
* @param {number} resolution Resolution.
|
||||
* @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.
|
||||
@@ -207,19 +208,21 @@ class ImageWMS extends ImageSource {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const mpu = this.getProjection() ? this.getProjection().getMetersPerUnit() : 1;
|
||||
const dpi = 25.4 / 0.28;
|
||||
const inchesPerMeter = 39.37;
|
||||
const scale = resolution * mpu * inchesPerMeter * dpi;
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'REQUEST': 'GetLegendGraphic',
|
||||
'FORMAT': 'image/png',
|
||||
'LAYER': layers,
|
||||
'SCALE': scale
|
||||
'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);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {assert} from '../asserts.js';
|
||||
import {buffer, createEmpty} from '../extent.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {modulo} from '../math.js';
|
||||
import {get as getProjection, transform, transformExtent, METERS_PER_UNIT} from '../proj.js';
|
||||
import {get as getProjection, transform, transformExtent} from '../proj.js';
|
||||
import {calculateSourceResolution} from '../reproj.js';
|
||||
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
|
||||
import TileImage from './TileImage.js';
|
||||
@@ -214,7 +214,8 @@ class TileWMS extends TileImage {
|
||||
/**
|
||||
* Return the GetLegendGraphic URL for the passed resolution.
|
||||
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
|
||||
* @param {number} resolution Resolution.
|
||||
* @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.
|
||||
@@ -227,20 +228,21 @@ class TileWMS extends TileImage {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const units = this.getProjection() && this.getProjection().getUnits();
|
||||
const dpi = 25.4 / 0.28;
|
||||
const mpu = METERS_PER_UNIT[units || 'm'];
|
||||
const inchesPerMeter = 39.37;
|
||||
const scale = resolution * mpu * inchesPerMeter * dpi;
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'REQUEST': 'GetLegendGraphic',
|
||||
'FORMAT': 'image/png',
|
||||
'LAYER': this.params_['LAYERS'],
|
||||
'SCALE': scale
|
||||
'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);
|
||||
|
||||
@@ -332,7 +332,7 @@ describe('ol.source.ImageWMS', function() {
|
||||
|
||||
describe('#getGetLegendGraphicUrl', function() {
|
||||
|
||||
it('returns the getLegenGraphic url as expected', function() {
|
||||
it('returns the getLegendGraphic url as expected', function() {
|
||||
const source = new ImageWMS(options);
|
||||
const url = source.getGetLegendGraphicUrl(resolution);
|
||||
const uri = new URL(url);
|
||||
@@ -348,6 +348,14 @@ describe('ol.source.ImageWMS', function() {
|
||||
expect(queryData.get('SCALE')).to.be('357.14214285714274');
|
||||
});
|
||||
|
||||
it('does not include SCALE if no resolution was provided', function() {
|
||||
const source = new ImageWMS(options);
|
||||
const url = source.getGetLegendGraphicUrl();
|
||||
const uri = new URL(url);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('SCALE')).to.be(null);
|
||||
});
|
||||
|
||||
it('adds additional params as expected', function() {
|
||||
const source = new ImageWMS(options);
|
||||
const url = source.getGetLegendGraphicUrl(resolution, {
|
||||
|
||||
@@ -317,6 +317,14 @@ describe('ol.source.TileWMS', function() {
|
||||
expect(queryData.get('SCALE')).to.be('357.14214285714274');
|
||||
});
|
||||
|
||||
it('does not include SCALE if no resolution was provided', function() {
|
||||
const source = new TileWMS(options);
|
||||
const url = source.getGetLegendGraphicUrl();
|
||||
const uri = new URL(url);
|
||||
const queryData = uri.searchParams;
|
||||
expect(queryData.get('SCALE')).to.be(null);
|
||||
});
|
||||
|
||||
it('adds additional params as expected', function() {
|
||||
const source = new TileWMS(options);
|
||||
const url = source.getGetLegendGraphicUrl(0.1, {
|
||||
|
||||
Reference in New Issue
Block a user