Use union type instead of enum for WMS server type
This commit is contained in:
committed by
Andreas Hocevar
parent
d05204f50b
commit
05f9b35eeb
+14
-18
@@ -2,12 +2,10 @@
|
|||||||
* @module ol/source/ImageWMS
|
* @module ol/source/ImageWMS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DEFAULT_WMS_VERSION} from './common.js';
|
|
||||||
|
|
||||||
import EventType from '../events/EventType.js';
|
import EventType from '../events/EventType.js';
|
||||||
import ImageSource, {defaultImageLoadFunction} from './Image.js';
|
import ImageSource, {defaultImageLoadFunction} from './Image.js';
|
||||||
import ImageWrapper from '../Image.js';
|
import ImageWrapper from '../Image.js';
|
||||||
import WMSServerType from './WMSServerType.js';
|
import {DEFAULT_VERSION} from './wms.js';
|
||||||
import {appendParams} from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
import {assert} from '../asserts.js';
|
import {assert} from '../asserts.js';
|
||||||
import {assign} from '../obj.js';
|
import {assign} from '../obj.js';
|
||||||
@@ -43,8 +41,9 @@ const GETFEATUREINFO_IMAGE_SIZE = [101, 101];
|
|||||||
* See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.
|
* See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.
|
||||||
* @property {boolean} [hidpi=true] Use the `ol/Map#pixelRatio` value when requesting
|
* @property {boolean} [hidpi=true] Use the `ol/Map#pixelRatio` value when requesting
|
||||||
* the image from the remote server.
|
* the image from the remote server.
|
||||||
* @property {import("./WMSServerType.js").default|string} [serverType] The type of
|
* @property {import("./wms.js").ServerType} [serverType] The type of
|
||||||
* the remote WMS server: `mapserver`, `geoserver` or `qgis`. Only needed if `hidpi` is `true`.
|
* the remote WMS server: `mapserver`, `geoserver`, `carmentaserver`, or `qgis`.
|
||||||
|
* Only needed if `hidpi` is `true`.
|
||||||
* @property {import("../Image.js").LoadFunction} [imageLoadFunction] Optional function to load an image given a URL.
|
* @property {import("../Image.js").LoadFunction} [imageLoadFunction] Optional function to load an image given a URL.
|
||||||
* @property {boolean} [imageSmoothing=true] Deprecated. Use the `interpolate` option instead.
|
* @property {boolean} [imageSmoothing=true] Deprecated. Use the `interpolate` option instead.
|
||||||
* @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
|
* @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
|
||||||
@@ -126,12 +125,9 @@ class ImageWMS extends ImageSource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {import("./WMSServerType.js").default|undefined}
|
* @type {import("./wms.js").ServerType}
|
||||||
*/
|
*/
|
||||||
this.serverType_ =
|
this.serverType_ = options.serverType;
|
||||||
/** @type {import("./WMSServerType.js").default|undefined} */ (
|
|
||||||
options.serverType
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -204,7 +200,7 @@ class ImageWMS extends ImageSource {
|
|||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetFeatureInfo',
|
'REQUEST': 'GetFeatureInfo',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'TRANSPARENT': true,
|
'TRANSPARENT': true,
|
||||||
@@ -247,7 +243,7 @@ class ImageWMS extends ImageSource {
|
|||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetLegendGraphic',
|
'REQUEST': 'GetLegendGraphic',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
};
|
};
|
||||||
@@ -337,7 +333,7 @@ class ImageWMS extends ImageSource {
|
|||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetMap',
|
'REQUEST': 'GetMap',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'TRANSPARENT': true,
|
'TRANSPARENT': true,
|
||||||
@@ -409,7 +405,7 @@ class ImageWMS extends ImageSource {
|
|||||||
|
|
||||||
if (pixelRatio != 1) {
|
if (pixelRatio != 1) {
|
||||||
switch (this.serverType_) {
|
switch (this.serverType_) {
|
||||||
case WMSServerType.GEOSERVER:
|
case 'geoserver':
|
||||||
const dpi = (90 * pixelRatio + 0.5) | 0;
|
const dpi = (90 * pixelRatio + 0.5) | 0;
|
||||||
if ('FORMAT_OPTIONS' in params) {
|
if ('FORMAT_OPTIONS' in params) {
|
||||||
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
||||||
@@ -417,11 +413,11 @@ class ImageWMS extends ImageSource {
|
|||||||
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WMSServerType.MAPSERVER:
|
case 'mapserver':
|
||||||
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
||||||
break;
|
break;
|
||||||
case WMSServerType.CARMENTA_SERVER:
|
case 'carmentaserver':
|
||||||
case WMSServerType.QGIS:
|
case 'qgis':
|
||||||
params['DPI'] = 90 * pixelRatio;
|
params['DPI'] = 90 * pixelRatio;
|
||||||
break;
|
break;
|
||||||
default: // Unknown `serverType` configured
|
default: // Unknown `serverType` configured
|
||||||
@@ -494,7 +490,7 @@ class ImageWMS extends ImageSource {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
updateV13_() {
|
updateV13_() {
|
||||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
const version = this.params_['VERSION'] || DEFAULT_VERSION;
|
||||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-20
@@ -2,10 +2,8 @@
|
|||||||
* @module ol/source/TileWMS
|
* @module ol/source/TileWMS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DEFAULT_WMS_VERSION} from './common.js';
|
|
||||||
|
|
||||||
import TileImage from './TileImage.js';
|
import TileImage from './TileImage.js';
|
||||||
import WMSServerType from './WMSServerType.js';
|
import {DEFAULT_VERSION} from './wms.js';
|
||||||
import {appendParams} from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
import {assert} from '../asserts.js';
|
import {assert} from '../asserts.js';
|
||||||
import {assign} from '../obj.js';
|
import {assign} from '../obj.js';
|
||||||
@@ -52,10 +50,10 @@ import {hash as tileCoordHash} from '../tilecoord.js';
|
|||||||
* tilesize and extent supported by the server.
|
* tilesize and extent supported by the server.
|
||||||
* If this is not defined, a default grid will be used: if there is a projection
|
* If this is not defined, a default grid will be used: if there is a projection
|
||||||
* extent, the grid will be based on that; if not, a grid based on a global
|
* extent, the grid will be based on that; if not, a grid based on a global
|
||||||
* extent with origin at 0,0 will be used..
|
* extent with origin at 0,0 will be used.
|
||||||
* @property {import("./WMSServerType.js").default|string} [serverType]
|
* @property {import("./wms.js").ServerType} [serverType] The type of
|
||||||
* The type of the remote WMS server. Currently only used when `hidpi` is
|
* the remote WMS server: `mapserver`, `geoserver`, `carmentaserver`, or `qgis`.
|
||||||
* `true`.
|
* Only needed if `hidpi` is `true`.
|
||||||
* @property {import("../Tile.js").LoadFunction} [tileLoadFunction] Optional function to load a tile given a URL. The default is
|
* @property {import("../Tile.js").LoadFunction} [tileLoadFunction] Optional function to load a tile given a URL. The default is
|
||||||
* ```js
|
* ```js
|
||||||
* function(imageTile, src) {
|
* function(imageTile, src) {
|
||||||
@@ -137,12 +135,9 @@ class TileWMS extends TileImage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {import("./WMSServerType.js").default|undefined}
|
* @type {import("./wms.js").ServerType}
|
||||||
*/
|
*/
|
||||||
this.serverType_ =
|
this.serverType_ = options.serverType;
|
||||||
/** @type {import("./WMSServerType.js").default|undefined} */ (
|
|
||||||
options.serverType
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -217,7 +212,7 @@ class TileWMS extends TileImage {
|
|||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetFeatureInfo',
|
'REQUEST': 'GetFeatureInfo',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'TRANSPARENT': true,
|
'TRANSPARENT': true,
|
||||||
@@ -262,7 +257,7 @@ class TileWMS extends TileImage {
|
|||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetLegendGraphic',
|
'REQUEST': 'GetLegendGraphic',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
};
|
};
|
||||||
@@ -340,7 +335,7 @@ class TileWMS extends TileImage {
|
|||||||
|
|
||||||
if (pixelRatio != 1) {
|
if (pixelRatio != 1) {
|
||||||
switch (this.serverType_) {
|
switch (this.serverType_) {
|
||||||
case WMSServerType.GEOSERVER:
|
case 'geoserver':
|
||||||
const dpi = (90 * pixelRatio + 0.5) | 0;
|
const dpi = (90 * pixelRatio + 0.5) | 0;
|
||||||
if ('FORMAT_OPTIONS' in params) {
|
if ('FORMAT_OPTIONS' in params) {
|
||||||
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
||||||
@@ -348,11 +343,11 @@ class TileWMS extends TileImage {
|
|||||||
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WMSServerType.MAPSERVER:
|
case 'mapserver':
|
||||||
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
||||||
break;
|
break;
|
||||||
case WMSServerType.CARMENTA_SERVER:
|
case 'carmentaserver':
|
||||||
case WMSServerType.QGIS:
|
case 'qgis':
|
||||||
params['DPI'] = 90 * pixelRatio;
|
params['DPI'] = 90 * pixelRatio;
|
||||||
break;
|
break;
|
||||||
default: // Unknown `serverType` configured
|
default: // Unknown `serverType` configured
|
||||||
@@ -421,7 +416,7 @@ class TileWMS extends TileImage {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
updateV13_() {
|
updateV13_() {
|
||||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
const version = this.params_['VERSION'] || DEFAULT_VERSION;
|
||||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +457,7 @@ class TileWMS extends TileImage {
|
|||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': DEFAULT_WMS_VERSION,
|
'VERSION': DEFAULT_VERSION,
|
||||||
'REQUEST': 'GetMap',
|
'REQUEST': 'GetMap',
|
||||||
'FORMAT': 'image/png',
|
'FORMAT': 'image/png',
|
||||||
'TRANSPARENT': true,
|
'TRANSPARENT': true,
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* @module ol/source/WMSServerType
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Available server types: `'carmentaserver'`, `'geoserver'`, `'mapserver'`,
|
|
||||||
* `'qgis'`. These are servers that have vendor parameters beyond the WMS
|
|
||||||
* specification that OpenLayers can make use of.
|
|
||||||
* @enum {string}
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
/**
|
|
||||||
* HiDPI support for [Carmenta Server](https://www.carmenta.com/en/products/carmenta-server)
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
CARMENTA_SERVER: 'carmentaserver',
|
|
||||||
/**
|
|
||||||
* HiDPI support for [GeoServer](https://geoserver.org/)
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
GEOSERVER: 'geoserver',
|
|
||||||
/**
|
|
||||||
* HiDPI support for [MapServer](https://mapserver.org/)
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
MAPSERVER: 'mapserver',
|
|
||||||
/**
|
|
||||||
* HiDPI support for [QGIS](https://qgis.org/)
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
QGIS: 'qgis',
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* @module ol/source/wms
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default WMS version.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const DEFAULT_VERSION = '1.3.0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api
|
||||||
|
* @typedef {'carmentaserver' | 'geoserver' | 'mapserver' | 'qgis'} ServerType
|
||||||
|
* Set the server type to use implementation-specific parameters beyond the WMS specification.
|
||||||
|
* - `'carmentaserver'`: HiDPI support for [Carmenta Server](https://www.carmenta.com/en/products/carmenta-server)
|
||||||
|
* - `'geoserver'`: HiDPI support for [GeoServer](https://geoserver.org/)
|
||||||
|
* - `'mapserver'`: HiDPI support for [MapServer](https://mapserver.org/)
|
||||||
|
* - `'qgis'`: HiDPI support for [QGIS](https://qgis.org/)
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user