@loaders.gl/wms 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csw-capabilities-loader.d.ts +1 -1
- package/dist/csw-capabilities-loader.d.ts.map +1 -1
- package/dist/csw-capabilities-loader.js +23 -15
- package/dist/csw-domain-loader.d.ts +1 -1
- package/dist/csw-domain-loader.d.ts.map +1 -1
- package/dist/csw-domain-loader.js +23 -15
- package/dist/csw-records-loader.d.ts +1 -1
- package/dist/csw-records-loader.d.ts.map +1 -1
- package/dist/csw-records-loader.js +23 -15
- package/dist/gml-loader.d.ts +1 -1
- package/dist/gml-loader.d.ts.map +1 -1
- package/dist/gml-loader.js +23 -15
- package/dist/index.cjs +49 -58
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +30 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/lib/parsers/csw/parse-csw-capabilities.js +18 -13
- package/dist/lib/parsers/csw/parse-csw-domain.js +26 -18
- package/dist/lib/parsers/csw/parse-csw-records.js +47 -36
- package/dist/lib/parsers/csw/parse-exception-report.js +26 -8
- package/dist/lib/parsers/gml/deep-strict-equal.js +107 -39
- package/dist/lib/parsers/gml/parse-gml.js +299 -280
- package/dist/lib/parsers/wms/parse-wms-capabilities.js +207 -187
- package/dist/lib/parsers/wms/parse-wms-error.js +17 -6
- package/dist/lib/parsers/wms/parse-wms-features.js +20 -19
- package/dist/lib/parsers/wms/parse-wms-layer-description.js +10 -4
- package/dist/lib/parsers/xml/parse-xml-helpers.js +54 -45
- package/dist/lib/services/create-image-service.d.ts +1 -1
- package/dist/lib/services/create-image-service.d.ts.map +1 -1
- package/dist/lib/services/create-image-service.js +31 -19
- package/dist/lib/services/image-service.js +39 -32
- package/dist/services/arcgis/arcgis-image-service.d.ts +2 -2
- package/dist/services/arcgis/arcgis-image-service.d.ts.map +1 -1
- package/dist/services/arcgis/arcgis-image-service.js +91 -55
- package/dist/services/arcgis/arcgis-server.js +35 -28
- package/dist/services/create-image-source.d.ts +3 -3
- package/dist/services/create-image-source.d.ts.map +1 -1
- package/dist/services/create-image-source.js +11 -2
- package/dist/services/ogc/csw-service.d.ts +3 -3
- package/dist/services/ogc/csw-service.d.ts.map +1 -1
- package/dist/services/ogc/csw-service.js +156 -142
- package/dist/services/ogc/wms-service.d.ts +4 -4
- package/dist/services/ogc/wms-service.d.ts.map +1 -1
- package/dist/services/ogc/wms-service.js +295 -242
- package/dist/wip/data-source.js +58 -1
- package/dist/wip/lib/wcs/parse-wcs-capabilities.js +8 -11
- package/dist/wip/lib/wfs/parse-wfs-capabilities.js +12 -12
- package/dist/wip/lib/wfs/parse-wfs.js +20 -20
- package/dist/wip/lib/wmts/parse-wmts-capabilities.js +70 -12
- package/dist/wip/lib/wmts/parse-wmts.js +23 -20
- package/dist/wip/services/arcgis-feature-service.js +22 -22
- package/dist/wip/wcs-capabilities-loader.d.ts +1 -1
- package/dist/wip/wcs-capabilities-loader.d.ts.map +1 -1
- package/dist/wip/wcs-capabilities-loader.js +21 -15
- package/dist/wip/wfs-capabilities-loader.d.ts +1 -1
- package/dist/wip/wfs-capabilities-loader.d.ts.map +1 -1
- package/dist/wip/wfs-capabilities-loader.js +21 -15
- package/dist/wip/wms-feature-info-loader.d.ts +1 -1
- package/dist/wip/wms-feature-info-loader.d.ts.map +1 -1
- package/dist/wip/wms-feature-info-loader.js +10 -6
- package/dist/wip/wms-layer-description-loader.d.ts +1 -1
- package/dist/wip/wms-layer-description-loader.d.ts.map +1 -1
- package/dist/wip/wms-layer-description-loader.js +9 -6
- package/dist/wip/wmts-capabilities-loader.js +22 -15
- package/dist/wms-capabilities-loader.d.ts +2 -2
- package/dist/wms-capabilities-loader.d.ts.map +1 -1
- package/dist/wms-capabilities-loader.js +27 -15
- package/dist/wms-error-loader.js +33 -28
- package/package.json +10 -8
- package/dist/csw-capabilities-loader.js.map +0 -1
- package/dist/csw-domain-loader.js.map +0 -1
- package/dist/csw-records-loader.js.map +0 -1
- package/dist/gml-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-capabilities.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-domain.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-records.js.map +0 -1
- package/dist/lib/parsers/csw/parse-exception-report.js.map +0 -1
- package/dist/lib/parsers/gml/deep-strict-equal.js.map +0 -1
- package/dist/lib/parsers/gml/parse-gml.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-capabilities.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-error.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-features.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-layer-description.js.map +0 -1
- package/dist/lib/parsers/xml/parse-xml-helpers.js.map +0 -1
- package/dist/lib/services/create-image-service.js.map +0 -1
- package/dist/lib/services/image-service.js.map +0 -1
- package/dist/services/arcgis/arcgis-image-service.js.map +0 -1
- package/dist/services/arcgis/arcgis-server.js.map +0 -1
- package/dist/services/create-image-source.js.map +0 -1
- package/dist/services/ogc/csw-service.js.map +0 -1
- package/dist/services/ogc/wms-service.js.map +0 -1
- package/dist/wip/data-source.js.map +0 -1
- package/dist/wip/lib/wcs/parse-wcs-capabilities.js.map +0 -1
- package/dist/wip/lib/wfs/parse-wfs-capabilities.js.map +0 -1
- package/dist/wip/lib/wfs/parse-wfs.js.map +0 -1
- package/dist/wip/lib/wmts/parse-wmts-capabilities.js.map +0 -1
- package/dist/wip/lib/wmts/parse-wmts.js.map +0 -1
- package/dist/wip/services/arcgis-feature-service.js.map +0 -1
- package/dist/wip/services/wmts-service.ts.disabled +0 -348
- package/dist/wip/wcs-capabilities-loader.js.map +0 -1
- package/dist/wip/wfs-capabilities-loader.js.map +0 -1
- package/dist/wip/wms-feature-info-loader.js.map +0 -1
- package/dist/wip/wms-layer-description-loader.js.map +0 -1
- package/dist/wip/wms-layer-description-loader.md.disabled.md +0 -47
- package/dist/wip/wmts-capabilities-loader.js.map +0 -1
- package/dist/wms-capabilities-loader.js.map +0 -1
- package/dist/wms-error-loader.js.map +0 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { ImageLoader } from '@loaders.gl/images';
|
|
2
5
|
import { mergeLoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
6
|
import { ImageSource } from '@loaders.gl/loader-utils';
|
|
@@ -6,260 +9,310 @@ import { WMSFeatureInfoLoader } from "../../wip/wms-feature-info-loader.js";
|
|
|
6
9
|
import { WMSLayerDescriptionLoader } from "../../wip/wms-layer-description-loader.js";
|
|
7
10
|
import { WMSErrorLoader } from "../../wms-error-loader.js";
|
|
8
11
|
export const WMSService = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
type: 'wms',
|
|
13
|
+
testURL: (url) => url.toLowerCase().includes('wms'),
|
|
14
|
+
create: (props) => new WMSSource(props)
|
|
12
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The WMSSource class provides
|
|
18
|
+
* - provides type safe methods to form URLs to a WMS service
|
|
19
|
+
* - provides type safe methods to query and parse results (and errors) from a WMS service
|
|
20
|
+
* - implements the ImageService interface
|
|
21
|
+
* @note Only the URL parameter conversion is supported. XML posts are not supported.
|
|
22
|
+
*/
|
|
13
23
|
export class WMSSource extends ImageSource {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...props.wmsParameters
|
|
40
|
-
};
|
|
41
|
-
this.vendorParameters = props.vendorParameters || {};
|
|
42
|
-
}
|
|
43
|
-
async getMetadata() {
|
|
44
|
-
const capabilities = await this.getCapabilities();
|
|
45
|
-
return this.normalizeMetadata(capabilities);
|
|
46
|
-
}
|
|
47
|
-
async getImage(parameters) {
|
|
48
|
-
const {
|
|
49
|
-
boundingBox,
|
|
50
|
-
bbox,
|
|
51
|
-
...rest
|
|
52
|
-
} = parameters;
|
|
53
|
-
const wmsParameters = {
|
|
54
|
-
bbox: boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox,
|
|
55
|
-
...rest
|
|
56
|
-
};
|
|
57
|
-
return await this.getMap(wmsParameters);
|
|
58
|
-
}
|
|
59
|
-
normalizeMetadata(capabilities) {
|
|
60
|
-
return capabilities;
|
|
61
|
-
}
|
|
62
|
-
async getCapabilities(wmsParameters, vendorParameters) {
|
|
63
|
-
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
|
|
64
|
-
const response = await this.fetch(url);
|
|
65
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
66
|
-
this._checkResponse(response, arrayBuffer);
|
|
67
|
-
const capabilities = await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
|
|
68
|
-
this.capabilities = capabilities;
|
|
69
|
-
return capabilities;
|
|
70
|
-
}
|
|
71
|
-
async getMap(wmsParameters, vendorParameters) {
|
|
72
|
-
const url = this.getMapURL(wmsParameters, vendorParameters);
|
|
73
|
-
const response = await this.fetch(url);
|
|
74
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
75
|
-
this._checkResponse(response, arrayBuffer);
|
|
76
|
-
try {
|
|
77
|
-
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
78
|
-
} catch {
|
|
79
|
-
throw this._parseError(arrayBuffer);
|
|
24
|
+
/** Create a WMSSource */
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
this.capabilities = null;
|
|
28
|
+
// TODO - defaults such as version, layers etc could be extracted from a base URL with parameters
|
|
29
|
+
// This would make pasting in any WMS URL more likely to make this class just work.
|
|
30
|
+
// const {baseUrl, parameters} = this._parseWMSUrl(props.url);
|
|
31
|
+
this.url = props.url;
|
|
32
|
+
this.data = props.url;
|
|
33
|
+
this.substituteCRS84 = props.substituteCRS84 ?? false;
|
|
34
|
+
this.flipCRS = ['EPSG:4326'];
|
|
35
|
+
this.wmsParameters = {
|
|
36
|
+
layers: undefined,
|
|
37
|
+
query_layers: undefined,
|
|
38
|
+
styles: undefined,
|
|
39
|
+
version: '1.3.0',
|
|
40
|
+
crs: 'EPSG:4326',
|
|
41
|
+
format: 'image/png',
|
|
42
|
+
info_format: 'text/plain',
|
|
43
|
+
transparent: undefined,
|
|
44
|
+
time: undefined,
|
|
45
|
+
elevation: undefined,
|
|
46
|
+
...props.wmsParameters
|
|
47
|
+
};
|
|
48
|
+
this.vendorParameters = props.vendorParameters || {};
|
|
80
49
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
86
|
-
this._checkResponse(response, arrayBuffer);
|
|
87
|
-
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
|
|
88
|
-
}
|
|
89
|
-
async getFeatureInfoText(wmsParameters, vendorParameters) {
|
|
90
|
-
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
91
|
-
const response = await this.fetch(url);
|
|
92
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
93
|
-
this._checkResponse(response, arrayBuffer);
|
|
94
|
-
return new TextDecoder().decode(arrayBuffer);
|
|
95
|
-
}
|
|
96
|
-
async describeLayer(wmsParameters, vendorParameters) {
|
|
97
|
-
const url = this.describeLayerURL(wmsParameters, vendorParameters);
|
|
98
|
-
const response = await this.fetch(url);
|
|
99
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
100
|
-
this._checkResponse(response, arrayBuffer);
|
|
101
|
-
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
|
|
102
|
-
}
|
|
103
|
-
async getLegendGraphic(wmsParameters, vendorParameters) {
|
|
104
|
-
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters);
|
|
105
|
-
const response = await this.fetch(url);
|
|
106
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
107
|
-
this._checkResponse(response, arrayBuffer);
|
|
108
|
-
try {
|
|
109
|
-
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
110
|
-
} catch {
|
|
111
|
-
throw this._parseError(arrayBuffer);
|
|
50
|
+
// ImageService implementation
|
|
51
|
+
async getMetadata() {
|
|
52
|
+
const capabilities = await this.getCapabilities();
|
|
53
|
+
return this.normalizeMetadata(capabilities);
|
|
112
54
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
getMapURL(wmsParameters, vendorParameters) {
|
|
122
|
-
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
123
|
-
const options = {
|
|
124
|
-
version: this.wmsParameters.version,
|
|
125
|
-
format: this.wmsParameters.format,
|
|
126
|
-
transparent: this.wmsParameters.transparent,
|
|
127
|
-
time: this.wmsParameters.time,
|
|
128
|
-
elevation: this.wmsParameters.elevation,
|
|
129
|
-
layers: this.wmsParameters.layers,
|
|
130
|
-
styles: this.wmsParameters.styles,
|
|
131
|
-
crs: this.wmsParameters.crs,
|
|
132
|
-
...wmsParameters
|
|
133
|
-
};
|
|
134
|
-
return this._getWMSUrl('GetMap', options, vendorParameters);
|
|
135
|
-
}
|
|
136
|
-
getFeatureInfoURL(wmsParameters, vendorParameters) {
|
|
137
|
-
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
138
|
-
const options = {
|
|
139
|
-
version: this.wmsParameters.version,
|
|
140
|
-
info_format: this.wmsParameters.info_format,
|
|
141
|
-
layers: this.wmsParameters.layers,
|
|
142
|
-
query_layers: this.wmsParameters.query_layers,
|
|
143
|
-
styles: this.wmsParameters.styles,
|
|
144
|
-
crs: this.wmsParameters.crs,
|
|
145
|
-
...wmsParameters
|
|
146
|
-
};
|
|
147
|
-
return this._getWMSUrl('GetFeatureInfo', options, vendorParameters);
|
|
148
|
-
}
|
|
149
|
-
describeLayerURL(wmsParameters, vendorParameters) {
|
|
150
|
-
const options = {
|
|
151
|
-
version: this.wmsParameters.version,
|
|
152
|
-
...wmsParameters
|
|
153
|
-
};
|
|
154
|
-
return this._getWMSUrl('DescribeLayer', options, vendorParameters);
|
|
155
|
-
}
|
|
156
|
-
getLegendGraphicURL(wmsParameters, vendorParameters) {
|
|
157
|
-
const options = {
|
|
158
|
-
version: this.wmsParameters.version,
|
|
159
|
-
...wmsParameters
|
|
160
|
-
};
|
|
161
|
-
return this._getWMSUrl('GetLegendGraphic', options, vendorParameters);
|
|
162
|
-
}
|
|
163
|
-
_parseWMSUrl(url) {
|
|
164
|
-
const [baseUrl, search] = url.split('?');
|
|
165
|
-
const searchParams = search.split('&');
|
|
166
|
-
const parameters = {};
|
|
167
|
-
for (const parameter of searchParams) {
|
|
168
|
-
const [key, value] = parameter.split('=');
|
|
169
|
-
parameters[key] = value;
|
|
55
|
+
async getImage(parameters) {
|
|
56
|
+
// Replace the GetImage `boundingBox` parameter with the WMS flat `bbox` parameter.
|
|
57
|
+
const { boundingBox, bbox, ...rest } = parameters;
|
|
58
|
+
const wmsParameters = {
|
|
59
|
+
bbox: boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox,
|
|
60
|
+
...rest
|
|
61
|
+
};
|
|
62
|
+
return await this.getMap(wmsParameters);
|
|
170
63
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
parameters
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
_getWMSUrl(request, wmsParameters, vendorParameters) {
|
|
177
|
-
let url = this.url;
|
|
178
|
-
let first = true;
|
|
179
|
-
const allParameters = {
|
|
180
|
-
service: 'WMS',
|
|
181
|
-
version: wmsParameters.version,
|
|
182
|
-
request,
|
|
183
|
-
...wmsParameters,
|
|
184
|
-
...this.vendorParameters,
|
|
185
|
-
...vendorParameters
|
|
186
|
-
};
|
|
187
|
-
const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation'];
|
|
188
|
-
for (const [key, value] of Object.entries(allParameters)) {
|
|
189
|
-
if (!IGNORE_EMPTY_KEYS.includes(key) || value) {
|
|
190
|
-
url += first ? '?' : '&';
|
|
191
|
-
first = false;
|
|
192
|
-
url += this._getURLParameter(key, value, wmsParameters);
|
|
193
|
-
}
|
|
64
|
+
normalizeMetadata(capabilities) {
|
|
65
|
+
return capabilities;
|
|
194
66
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
67
|
+
// WMS Service API Stubs
|
|
68
|
+
/** Get Capabilities */
|
|
69
|
+
async getCapabilities(wmsParameters, vendorParameters) {
|
|
70
|
+
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
|
|
71
|
+
const response = await this.fetch(url);
|
|
72
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
73
|
+
this._checkResponse(response, arrayBuffer);
|
|
74
|
+
const capabilities = await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
|
|
75
|
+
this.capabilities = capabilities;
|
|
76
|
+
return capabilities;
|
|
204
77
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
value = 'CRS:84';
|
|
78
|
+
/** Get a map image */
|
|
79
|
+
async getMap(wmsParameters, vendorParameters) {
|
|
80
|
+
const url = this.getMapURL(wmsParameters, vendorParameters);
|
|
81
|
+
const response = await this.fetch(url);
|
|
82
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
83
|
+
this._checkResponse(response, arrayBuffer);
|
|
84
|
+
try {
|
|
85
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
214
86
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (wmsParameters.version === '1.3.0') {
|
|
218
|
-
key = 'crs';
|
|
87
|
+
catch {
|
|
88
|
+
throw this._parseError(arrayBuffer);
|
|
219
89
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
90
|
+
}
|
|
91
|
+
/** Get Feature Info for a coordinate */
|
|
92
|
+
async getFeatureInfo(wmsParameters, vendorParameters) {
|
|
93
|
+
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
94
|
+
const response = await this.fetch(url);
|
|
95
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
96
|
+
this._checkResponse(response, arrayBuffer);
|
|
97
|
+
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
|
|
98
|
+
}
|
|
99
|
+
/** Get Feature Info for a coordinate */
|
|
100
|
+
async getFeatureInfoText(wmsParameters, vendorParameters) {
|
|
101
|
+
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
102
|
+
const response = await this.fetch(url);
|
|
103
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
104
|
+
this._checkResponse(response, arrayBuffer);
|
|
105
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
106
|
+
}
|
|
107
|
+
/** Get more information about a layer */
|
|
108
|
+
async describeLayer(wmsParameters, vendorParameters) {
|
|
109
|
+
const url = this.describeLayerURL(wmsParameters, vendorParameters);
|
|
110
|
+
const response = await this.fetch(url);
|
|
111
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
112
|
+
this._checkResponse(response, arrayBuffer);
|
|
113
|
+
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
|
|
114
|
+
}
|
|
115
|
+
/** Get an image with a semantic legend */
|
|
116
|
+
async getLegendGraphic(wmsParameters, vendorParameters) {
|
|
117
|
+
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters);
|
|
118
|
+
const response = await this.fetch(url);
|
|
119
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
120
|
+
this._checkResponse(response, arrayBuffer);
|
|
121
|
+
try {
|
|
122
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
throw this._parseError(arrayBuffer);
|
|
225
126
|
}
|
|
226
|
-
break;
|
|
227
|
-
default:
|
|
228
127
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
128
|
+
// Typed URL creators
|
|
129
|
+
// For applications that want full control of fetching and parsing
|
|
130
|
+
/** Generate a URL for the GetCapabilities request */
|
|
131
|
+
getCapabilitiesURL(wmsParameters, vendorParameters) {
|
|
132
|
+
const options = {
|
|
133
|
+
version: this.wmsParameters.version,
|
|
134
|
+
...wmsParameters
|
|
135
|
+
};
|
|
136
|
+
return this._getWMSUrl('GetCapabilities', options, vendorParameters);
|
|
137
|
+
}
|
|
138
|
+
/** Generate a URL for the GetMap request */
|
|
139
|
+
getMapURL(wmsParameters, vendorParameters) {
|
|
140
|
+
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
141
|
+
const options = {
|
|
142
|
+
version: this.wmsParameters.version,
|
|
143
|
+
format: this.wmsParameters.format,
|
|
144
|
+
transparent: this.wmsParameters.transparent,
|
|
145
|
+
time: this.wmsParameters.time,
|
|
146
|
+
elevation: this.wmsParameters.elevation,
|
|
147
|
+
layers: this.wmsParameters.layers,
|
|
148
|
+
styles: this.wmsParameters.styles,
|
|
149
|
+
crs: this.wmsParameters.crs,
|
|
150
|
+
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
|
|
151
|
+
// width: 1200,
|
|
152
|
+
// height: 900,
|
|
153
|
+
...wmsParameters
|
|
154
|
+
};
|
|
155
|
+
return this._getWMSUrl('GetMap', options, vendorParameters);
|
|
156
|
+
}
|
|
157
|
+
/** Generate a URL for the GetFeatureInfo request */
|
|
158
|
+
getFeatureInfoURL(wmsParameters, vendorParameters) {
|
|
159
|
+
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
160
|
+
const options = {
|
|
161
|
+
version: this.wmsParameters.version,
|
|
162
|
+
// query_layers: [],
|
|
163
|
+
// format: this.wmsParameters.format,
|
|
164
|
+
info_format: this.wmsParameters.info_format,
|
|
165
|
+
layers: this.wmsParameters.layers,
|
|
166
|
+
query_layers: this.wmsParameters.query_layers,
|
|
167
|
+
styles: this.wmsParameters.styles,
|
|
168
|
+
crs: this.wmsParameters.crs,
|
|
169
|
+
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
|
|
170
|
+
// width: 1200,
|
|
171
|
+
// height: 900,
|
|
172
|
+
// x: undefined!,
|
|
173
|
+
// y: undefined!,
|
|
174
|
+
...wmsParameters
|
|
175
|
+
};
|
|
176
|
+
return this._getWMSUrl('GetFeatureInfo', options, vendorParameters);
|
|
177
|
+
}
|
|
178
|
+
/** Generate a URL for the GetFeatureInfo request */
|
|
179
|
+
describeLayerURL(wmsParameters, vendorParameters) {
|
|
180
|
+
const options = {
|
|
181
|
+
version: this.wmsParameters.version,
|
|
182
|
+
...wmsParameters
|
|
183
|
+
};
|
|
184
|
+
return this._getWMSUrl('DescribeLayer', options, vendorParameters);
|
|
185
|
+
}
|
|
186
|
+
getLegendGraphicURL(wmsParameters, vendorParameters) {
|
|
187
|
+
const options = {
|
|
188
|
+
version: this.wmsParameters.version,
|
|
189
|
+
// format?
|
|
190
|
+
...wmsParameters
|
|
191
|
+
};
|
|
192
|
+
return this._getWMSUrl('GetLegendGraphic', options, vendorParameters);
|
|
193
|
+
}
|
|
194
|
+
// INTERNAL METHODS
|
|
195
|
+
_parseWMSUrl(url) {
|
|
196
|
+
const [baseUrl, search] = url.split('?');
|
|
197
|
+
const searchParams = search.split('&');
|
|
198
|
+
const parameters = {};
|
|
199
|
+
for (const parameter of searchParams) {
|
|
200
|
+
const [key, value] = parameter.split('=');
|
|
201
|
+
parameters[key] = value;
|
|
202
|
+
}
|
|
203
|
+
return { url: baseUrl, parameters };
|
|
235
204
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Generate a URL with parameters
|
|
207
|
+
* @note case _getWMSUrl may need to be overridden to handle certain backends?
|
|
208
|
+
* @note at the moment, only URLs with parameters are supported (no XML payloads)
|
|
209
|
+
* */
|
|
210
|
+
_getWMSUrl(request, wmsParameters, vendorParameters) {
|
|
211
|
+
let url = this.url;
|
|
212
|
+
let first = true;
|
|
213
|
+
// Add any vendor searchParams
|
|
214
|
+
const allParameters = {
|
|
215
|
+
service: 'WMS',
|
|
216
|
+
version: wmsParameters.version,
|
|
217
|
+
request,
|
|
218
|
+
...wmsParameters,
|
|
219
|
+
...this.vendorParameters,
|
|
220
|
+
...vendorParameters
|
|
221
|
+
};
|
|
222
|
+
// Encode the keys
|
|
223
|
+
const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation'];
|
|
224
|
+
for (const [key, value] of Object.entries(allParameters)) {
|
|
225
|
+
// hack to preserve test cases. Not super clear if keys should be included when values are undefined
|
|
226
|
+
if (!IGNORE_EMPTY_KEYS.includes(key) || value) {
|
|
227
|
+
url += first ? '?' : '&';
|
|
228
|
+
first = false;
|
|
229
|
+
url += this._getURLParameter(key, value, wmsParameters);
|
|
230
|
+
}
|
|
253
231
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
232
|
+
return encodeURI(url);
|
|
233
|
+
}
|
|
234
|
+
_getWMS130Parameters(wmsParameters) {
|
|
235
|
+
const newParameters = { ...wmsParameters };
|
|
236
|
+
if (newParameters.srs) {
|
|
237
|
+
newParameters.crs = newParameters.crs || newParameters.srs;
|
|
238
|
+
delete newParameters.srs;
|
|
239
|
+
}
|
|
240
|
+
return newParameters;
|
|
241
|
+
}
|
|
242
|
+
// eslint-disable-next-line complexity
|
|
243
|
+
_getURLParameter(key, value, wmsParameters) {
|
|
244
|
+
// Substitute by key
|
|
245
|
+
switch (key) {
|
|
246
|
+
case 'crs':
|
|
247
|
+
// CRS was called SRS before WMS 1.3.0
|
|
248
|
+
if (wmsParameters.version !== '1.3.0') {
|
|
249
|
+
key = 'srs';
|
|
250
|
+
}
|
|
251
|
+
else if (this.substituteCRS84 && value === 'EPSG:4326') {
|
|
252
|
+
/** In 1.3.0, replaces references to 'EPSG:4326' with the new backwards compatible CRS:84 */
|
|
253
|
+
// Substitute by value
|
|
254
|
+
value = 'CRS:84';
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
case 'srs':
|
|
258
|
+
// CRS was called SRS before WMS 1.3.0
|
|
259
|
+
if (wmsParameters.version === '1.3.0') {
|
|
260
|
+
key = 'crs';
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
case 'bbox':
|
|
264
|
+
// Coordinate order is flipped for certain CRS in WMS 1.3.0
|
|
265
|
+
const bbox = this._flipBoundingBox(value, wmsParameters);
|
|
266
|
+
if (bbox) {
|
|
267
|
+
value = bbox;
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
default:
|
|
271
|
+
// do nothing
|
|
272
|
+
}
|
|
273
|
+
key = key.toUpperCase();
|
|
274
|
+
return Array.isArray(value)
|
|
275
|
+
? `${key}=${value.join(',')}`
|
|
276
|
+
: `${key}=${value ? String(value) : ''}`;
|
|
277
|
+
}
|
|
278
|
+
/** Coordinate order is flipped for certain CRS in WMS 1.3.0 */
|
|
279
|
+
_flipBoundingBox(bboxValue, wmsParameters) {
|
|
280
|
+
// Sanity checks
|
|
281
|
+
if (!Array.isArray(bboxValue) || bboxValue.length !== 4) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const flipCoordinates =
|
|
285
|
+
// Only affects WMS 1.3.0
|
|
286
|
+
wmsParameters.version === '1.3.0' &&
|
|
287
|
+
// Flip if we are dealing with a CRS that was flipped in 1.3.0
|
|
288
|
+
this.flipCRS.includes(wmsParameters.crs || '') &&
|
|
289
|
+
// Don't flip if we are subsituting EPSG:4326 with CRS:84
|
|
290
|
+
!(this.substituteCRS84 && wmsParameters.crs === 'EPSG:4326');
|
|
291
|
+
const bbox = bboxValue;
|
|
292
|
+
return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox;
|
|
293
|
+
}
|
|
294
|
+
/** Fetches an array buffer and checks the response (boilerplate reduction) */
|
|
295
|
+
async _fetchArrayBuffer(url) {
|
|
296
|
+
const response = await this.fetch(url);
|
|
297
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
298
|
+
this._checkResponse(response, arrayBuffer);
|
|
299
|
+
return arrayBuffer;
|
|
300
|
+
}
|
|
301
|
+
/** Checks for and parses a WMS XML formatted ServiceError and throws an exception */
|
|
302
|
+
_checkResponse(response, arrayBuffer) {
|
|
303
|
+
const contentType = response.headers['content-type'];
|
|
304
|
+
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) {
|
|
305
|
+
// We want error responses to throw exceptions, the WMSErrorLoader can do this
|
|
306
|
+
const loadOptions = mergeLoaderOptions(this.loadOptions, {
|
|
307
|
+
wms: { throwOnError: true }
|
|
308
|
+
});
|
|
309
|
+
const error = WMSErrorLoader.parseSync?.(arrayBuffer, loadOptions);
|
|
310
|
+
throw new Error(error);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Error situation detected */
|
|
314
|
+
_parseError(arrayBuffer) {
|
|
315
|
+
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.loadOptions);
|
|
316
|
+
return new Error(error);
|
|
257
317
|
}
|
|
258
|
-
}
|
|
259
|
-
_parseError(arrayBuffer) {
|
|
260
|
-
var _WMSErrorLoader$parse2;
|
|
261
|
-
const error = (_WMSErrorLoader$parse2 = WMSErrorLoader.parseSync) === null || _WMSErrorLoader$parse2 === void 0 ? void 0 : _WMSErrorLoader$parse2.call(WMSErrorLoader, arrayBuffer, this.loadOptions);
|
|
262
|
-
return new Error(error);
|
|
263
|
-
}
|
|
264
318
|
}
|
|
265
|
-
//# sourceMappingURL=wms-service.js.map
|
package/dist/wip/data-source.js
CHANGED
|
@@ -1,2 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
/** General data source class */
|
|
4
|
+
// export abstract class DataSource {};
|
|
5
|
+
// export type DataSourceMetadata = {};
|
|
6
|
+
// ImageSource
|
|
7
|
+
// Tile Source
|
|
8
|
+
/** Data source that serves data by tile index *
|
|
9
|
+
export abstract class TileDataSource extends DataSource {};
|
|
1
10
|
|
|
2
|
-
|
|
11
|
+
// Image Tile Data Source
|
|
12
|
+
|
|
13
|
+
export type ImageTileDataSourceCapabilities = {
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ImageTile = Record<string, any>;
|
|
17
|
+
|
|
18
|
+
export type FeatureInfo = {};
|
|
19
|
+
|
|
20
|
+
export abstract class ImageTileDataSource extends TileDataSource {
|
|
21
|
+
source: ImageDataSource;
|
|
22
|
+
|
|
23
|
+
constructor(source: ImageDataSource) {
|
|
24
|
+
super();
|
|
25
|
+
this.source = source;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getCapabilities(): Promise<ImageTileDataSourceCapabilities> {
|
|
29
|
+
return this.source.getCapabilities();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getTile({x, y, z, width, height, layers, parameters}): Promise<ImageType> {
|
|
33
|
+
const boundingBox = this.getBoundingBoxFromTileIndex(x, y, z);
|
|
34
|
+
return this.source.getImage({boundingBox, width, height, layers, parameters});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getFeatureInfo(): FeatureInfo | null {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getBoundingBoxFromTileIndex(x: number, y: number, z: number): [number, number, number, number] {
|
|
42
|
+
return [0, 0, 1, 1];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Vector Tile Source
|
|
47
|
+
|
|
48
|
+
export type VectorTileDataSourceCapabilities = {
|
|
49
|
+
// check tile.json
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type VectorTile = Record<string, any>;
|
|
53
|
+
|
|
54
|
+
export abstract class VectorTileDataSource extends TileDataSource {
|
|
55
|
+
abstract getCapabilities(): Promise<VectorTileDataSourceCapabilities>;
|
|
56
|
+
abstract getTile({x, y, z, width, height, layers, parameters}): Promise<VectorTile>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
*/
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import { XMLLoader } from '@loaders.gl/xml';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a typed data structure from raw XML for `GetCapabilities` response
|
|
5
|
+
* @note Error handlings is fairly weak
|
|
6
|
+
*/
|
|
2
7
|
export function parseWCSCapabilities(text, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
xml: {
|
|
7
|
-
...(options === null || options === void 0 ? void 0 : options.xml),
|
|
8
|
-
removeNSPrefix: true
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
12
|
-
return xmlCapabilities;
|
|
8
|
+
const parsedXML = XMLLoader.parseTextSync?.(text, { ...options, xml: { ...options?.xml, removeNSPrefix: true } });
|
|
9
|
+
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
10
|
+
return xmlCapabilities;
|
|
13
11
|
}
|
|
14
|
-
//# sourceMappingURL=parse-wcs-capabilities.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import { XMLLoader } from '@loaders.gl/xml';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a typed data structure from raw XML for `GetCapabilities` response
|
|
5
|
+
* @note Error handlings is fairly weak
|
|
6
|
+
*/
|
|
2
7
|
export function parseWFSCapabilities(text, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
13
|
-
return xmlCapabilities;
|
|
8
|
+
const parsedXML = XMLLoader.parseTextSync?.(text, { ...options, xml: {
|
|
9
|
+
...options?.xml,
|
|
10
|
+
removeNSPrefix: true,
|
|
11
|
+
uncapitalizeKeys: true
|
|
12
|
+
} });
|
|
13
|
+
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
14
|
+
return xmlCapabilities;
|
|
14
15
|
}
|
|
15
|
-
//# sourceMappingURL=parse-wfs-capabilities.js.map
|