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 the GetLegendGraphic URL for the passed resolution.
|
||||||
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
|
* 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
|
* @param {!Object} params GetLegendGraphic params. Default `FORMAT` is
|
||||||
* `image/png`. `VERSION` should not be specified here.
|
* `image/png`. `VERSION` should not be specified here.
|
||||||
* @return {string|undefined} GetLegendGraphic URL.
|
* @return {string|undefined} GetLegendGraphic URL.
|
||||||
@@ -207,19 +208,21 @@ class ImageWMS extends ImageSource {
|
|||||||
return undefined;
|
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 = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_WMS_VERSION,
|
||||||
'REQUEST': 'GetLegendGraphic',
|
'REQUEST': 'GetLegendGraphic',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'LAYER': layers,
|
'LAYER': layers
|
||||||
'SCALE': scale
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
assign(baseParams, params);
|
||||||
|
|
||||||
return appendParams(/** @type {string} */ (this.url_), baseParams);
|
return appendParams(/** @type {string} */ (this.url_), baseParams);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {assert} from '../asserts.js';
|
|||||||
import {buffer, createEmpty} from '../extent.js';
|
import {buffer, createEmpty} from '../extent.js';
|
||||||
import {assign} from '../obj.js';
|
import {assign} from '../obj.js';
|
||||||
import {modulo} from '../math.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 {calculateSourceResolution} from '../reproj.js';
|
||||||
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
|
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
|
||||||
import TileImage from './TileImage.js';
|
import TileImage from './TileImage.js';
|
||||||
@@ -214,7 +214,8 @@ class TileWMS extends TileImage {
|
|||||||
/**
|
/**
|
||||||
* Return the GetLegendGraphic URL for the passed resolution.
|
* Return the GetLegendGraphic URL for the passed resolution.
|
||||||
* Return `undefined` if the GetLegendGraphic URL cannot be constructed.
|
* 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
|
* @param {!Object} params GetLegendGraphic params. Default `FORMAT` is
|
||||||
* `image/png`. `VERSION` should not be specified here.
|
* `image/png`. `VERSION` should not be specified here.
|
||||||
* @return {string|undefined} GetLegendGraphic URL.
|
* @return {string|undefined} GetLegendGraphic URL.
|
||||||
@@ -227,20 +228,21 @@ class TileWMS extends TileImage {
|
|||||||
return undefined;
|
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 = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_WMS_VERSION,
|
||||||
'REQUEST': 'GetLegendGraphic',
|
'REQUEST': 'GetLegendGraphic',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'LAYER': this.params_['LAYERS'],
|
'LAYER': layers
|
||||||
'SCALE': scale
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
assign(baseParams, params);
|
||||||
|
|
||||||
return appendParams(/** @type {string} */ (this.urls[0]), baseParams);
|
return appendParams(/** @type {string} */ (this.urls[0]), baseParams);
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
|
|
||||||
describe('#getGetLegendGraphicUrl', 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 source = new ImageWMS(options);
|
||||||
const url = source.getGetLegendGraphicUrl(resolution);
|
const url = source.getGetLegendGraphicUrl(resolution);
|
||||||
const uri = new URL(url);
|
const uri = new URL(url);
|
||||||
@@ -348,6 +348,14 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
expect(queryData.get('SCALE')).to.be('357.14214285714274');
|
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() {
|
it('adds additional params as expected', function() {
|
||||||
const source = new ImageWMS(options);
|
const source = new ImageWMS(options);
|
||||||
const url = source.getGetLegendGraphicUrl(resolution, {
|
const url = source.getGetLegendGraphicUrl(resolution, {
|
||||||
|
|||||||
@@ -317,6 +317,14 @@ describe('ol.source.TileWMS', function() {
|
|||||||
expect(queryData.get('SCALE')).to.be('357.14214285714274');
|
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() {
|
it('adds additional params as expected', function() {
|
||||||
const source = new TileWMS(options);
|
const source = new TileWMS(options);
|
||||||
const url = source.getGetLegendGraphicUrl(0.1, {
|
const url = source.getGetLegendGraphicUrl(0.1, {
|
||||||
|
|||||||
Reference in New Issue
Block a user