Use union type instead of enum for WMS server type
This commit is contained in:
committed by
Andreas Hocevar
parent
d05204f50b
commit
05f9b35eeb
@@ -2,12 +2,10 @@
|
||||
* @module ol/source/ImageWMS
|
||||
*/
|
||||
|
||||
import {DEFAULT_WMS_VERSION} from './common.js';
|
||||
|
||||
import EventType from '../events/EventType.js';
|
||||
import ImageSource, {defaultImageLoadFunction} 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 {assert} from '../asserts.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.
|
||||
* @property {boolean} [hidpi=true] Use the `ol/Map#pixelRatio` value when requesting
|
||||
* the image from the remote server.
|
||||
* @property {import("./WMSServerType.js").default|string} [serverType] The type of
|
||||
* the remote WMS server: `mapserver`, `geoserver` or `qgis`. Only needed if `hidpi` is `true`.
|
||||
* @property {import("./wms.js").ServerType} [serverType] The type of
|
||||
* 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 {boolean} [imageSmoothing=true] Deprecated. Use the `interpolate` option instead.
|
||||
* @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
|
||||
@@ -126,12 +125,9 @@ class ImageWMS extends ImageSource {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./WMSServerType.js").default|undefined}
|
||||
* @type {import("./wms.js").ServerType}
|
||||
*/
|
||||
this.serverType_ =
|
||||
/** @type {import("./WMSServerType.js").default|undefined} */ (
|
||||
options.serverType
|
||||
);
|
||||
this.serverType_ = options.serverType;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -204,7 +200,7 @@ class ImageWMS extends ImageSource {
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetFeatureInfo',
|
||||
'FORMAT': 'image/png',
|
||||
'TRANSPARENT': true,
|
||||
@@ -247,7 +243,7 @@ class ImageWMS extends ImageSource {
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetLegendGraphic',
|
||||
'FORMAT': 'image/png',
|
||||
};
|
||||
@@ -337,7 +333,7 @@ class ImageWMS extends ImageSource {
|
||||
|
||||
const params = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetMap',
|
||||
'FORMAT': 'image/png',
|
||||
'TRANSPARENT': true,
|
||||
@@ -409,7 +405,7 @@ class ImageWMS extends ImageSource {
|
||||
|
||||
if (pixelRatio != 1) {
|
||||
switch (this.serverType_) {
|
||||
case WMSServerType.GEOSERVER:
|
||||
case 'geoserver':
|
||||
const dpi = (90 * pixelRatio + 0.5) | 0;
|
||||
if ('FORMAT_OPTIONS' in params) {
|
||||
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
||||
@@ -417,11 +413,11 @@ class ImageWMS extends ImageSource {
|
||||
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
||||
}
|
||||
break;
|
||||
case WMSServerType.MAPSERVER:
|
||||
case 'mapserver':
|
||||
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
||||
break;
|
||||
case WMSServerType.CARMENTA_SERVER:
|
||||
case WMSServerType.QGIS:
|
||||
case 'carmentaserver':
|
||||
case 'qgis':
|
||||
params['DPI'] = 90 * pixelRatio;
|
||||
break;
|
||||
default: // Unknown `serverType` configured
|
||||
@@ -494,7 +490,7 @@ class ImageWMS extends ImageSource {
|
||||
* @private
|
||||
*/
|
||||
updateV13_() {
|
||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
||||
const version = this.params_['VERSION'] || DEFAULT_VERSION;
|
||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
* @module ol/source/TileWMS
|
||||
*/
|
||||
|
||||
import {DEFAULT_WMS_VERSION} from './common.js';
|
||||
|
||||
import TileImage from './TileImage.js';
|
||||
import WMSServerType from './WMSServerType.js';
|
||||
import {DEFAULT_VERSION} from './wms.js';
|
||||
import {appendParams} from '../uri.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {assign} from '../obj.js';
|
||||
@@ -52,10 +50,10 @@ import {hash as tileCoordHash} from '../tilecoord.js';
|
||||
* tilesize and extent supported by the server.
|
||||
* 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 with origin at 0,0 will be used..
|
||||
* @property {import("./WMSServerType.js").default|string} [serverType]
|
||||
* The type of the remote WMS server. Currently only used when `hidpi` is
|
||||
* `true`.
|
||||
* extent with origin at 0,0 will be used.
|
||||
* @property {import("./wms.js").ServerType} [serverType] The type of
|
||||
* the remote WMS server: `mapserver`, `geoserver`, `carmentaserver`, or `qgis`.
|
||||
* Only needed if `hidpi` is `true`.
|
||||
* @property {import("../Tile.js").LoadFunction} [tileLoadFunction] Optional function to load a tile given a URL. The default is
|
||||
* ```js
|
||||
* function(imageTile, src) {
|
||||
@@ -137,12 +135,9 @@ class TileWMS extends TileImage {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./WMSServerType.js").default|undefined}
|
||||
* @type {import("./wms.js").ServerType}
|
||||
*/
|
||||
this.serverType_ =
|
||||
/** @type {import("./WMSServerType.js").default|undefined} */ (
|
||||
options.serverType
|
||||
);
|
||||
this.serverType_ = options.serverType;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -217,7 +212,7 @@ class TileWMS extends TileImage {
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetFeatureInfo',
|
||||
'FORMAT': 'image/png',
|
||||
'TRANSPARENT': true,
|
||||
@@ -262,7 +257,7 @@ class TileWMS extends TileImage {
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetLegendGraphic',
|
||||
'FORMAT': 'image/png',
|
||||
};
|
||||
@@ -340,7 +335,7 @@ class TileWMS extends TileImage {
|
||||
|
||||
if (pixelRatio != 1) {
|
||||
switch (this.serverType_) {
|
||||
case WMSServerType.GEOSERVER:
|
||||
case 'geoserver':
|
||||
const dpi = (90 * pixelRatio + 0.5) | 0;
|
||||
if ('FORMAT_OPTIONS' in params) {
|
||||
params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
|
||||
@@ -348,11 +343,11 @@ class TileWMS extends TileImage {
|
||||
params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
|
||||
}
|
||||
break;
|
||||
case WMSServerType.MAPSERVER:
|
||||
case 'mapserver':
|
||||
params['MAP_RESOLUTION'] = 90 * pixelRatio;
|
||||
break;
|
||||
case WMSServerType.CARMENTA_SERVER:
|
||||
case WMSServerType.QGIS:
|
||||
case 'carmentaserver':
|
||||
case 'qgis':
|
||||
params['DPI'] = 90 * pixelRatio;
|
||||
break;
|
||||
default: // Unknown `serverType` configured
|
||||
@@ -421,7 +416,7 @@ class TileWMS extends TileImage {
|
||||
* @private
|
||||
*/
|
||||
updateV13_() {
|
||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
||||
const version = this.params_['VERSION'] || DEFAULT_VERSION;
|
||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||
}
|
||||
|
||||
@@ -462,7 +457,7 @@ class TileWMS extends TileImage {
|
||||
|
||||
const baseParams = {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': DEFAULT_WMS_VERSION,
|
||||
'VERSION': DEFAULT_VERSION,
|
||||
'REQUEST': 'GetMap',
|
||||
'FORMAT': 'image/png',
|
||||
'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',
|
||||
};
|
||||
19
src/ol/source/wms.js
Normal file
19
src/ol/source/wms.js
Normal file
@@ -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