@loaders.gl/wms 4.3.0-alpha.1 → 4.3.0-alpha.3
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.js +1 -1
- package/dist/csw-domain-loader.js +1 -1
- package/dist/csw-records-loader.js +1 -1
- package/dist/gml-loader.js +1 -1
- package/dist/index.cjs +125 -300
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -10
- package/dist/lib/deprecated/create-image-source.d.ts +21 -0
- package/dist/lib/deprecated/create-image-source.d.ts.map +1 -0
- package/dist/lib/deprecated/create-image-source.js +44 -0
- package/dist/lib/parsers/wfs/parse-wfs-capabilities.d.ts.map +1 -0
- package/dist/{wip/lib → lib/parsers}/wfs/parse-wfs-capabilities.js +5 -2
- package/dist/lib/parsers/wfs/parse-wfs.d.ts.map +1 -0
- package/dist/services/arcgis/arcgis-feature-server.d.ts +67 -0
- package/dist/services/arcgis/arcgis-feature-server.d.ts.map +1 -0
- package/dist/services/arcgis/arcgis-feature-server.js +446 -0
- package/dist/services/arcgis/{arcgis-image-service.d.ts → arcgis-image-server.d.ts} +25 -10
- package/dist/services/arcgis/arcgis-image-server.d.ts.map +1 -0
- package/dist/services/arcgis/{arcgis-image-service.js → arcgis-image-server.js} +28 -11
- package/dist/services/ogc/csw-service.d.ts +13 -13
- package/dist/services/ogc/csw-service.d.ts.map +1 -1
- package/dist/services/ogc/wfs-service.d.ts +279 -0
- package/dist/services/ogc/wfs-service.d.ts.map +1 -0
- package/dist/services/ogc/wfs-service.js +388 -0
- package/dist/services/ogc/wms-service.d.ts +42 -21
- package/dist/services/ogc/wms-service.d.ts.map +1 -1
- package/dist/services/ogc/wms-service.js +29 -14
- package/dist/{wip/wfs-capabilities-loader.d.ts → wfs-capabilities-loader.d.ts} +2 -1
- package/dist/wfs-capabilities-loader.d.ts.map +1 -0
- package/dist/{wip/wfs-capabilities-loader.js → wfs-capabilities-loader.js} +3 -2
- package/dist/wip/wcs-capabilities-loader.js +1 -1
- package/dist/wip/wmts-capabilities-loader.js +1 -1
- package/dist/wms-capabilities-loader.js +1 -1
- package/dist/wms-error-loader.js +1 -1
- package/package.json +6 -6
- package/src/index.ts +12 -24
- package/src/lib/{services/create-image-service.ts → deprecated/create-image-service.ts.disabled} +4 -4
- package/src/lib/deprecated/create-image-source.ts +70 -0
- package/src/{wip/lib → lib/parsers}/wfs/parse-wfs-capabilities.ts +8 -5
- package/src/services/arcgis/arcgis-feature-server.ts +506 -0
- package/src/services/arcgis/{arcgis-image-service.ts → arcgis-image-server.ts} +41 -18
- package/src/services/ogc/csw-service.ts +17 -15
- package/src/services/ogc/wfs-service.ts +624 -0
- package/src/services/ogc/wms-service.ts +54 -30
- package/src/{wip/wfs-capabilities-loader.ts → wfs-capabilities-loader.ts} +3 -2
- package/dist/lib/services/create-image-service.d.ts +0 -14
- package/dist/lib/services/create-image-service.d.ts.map +0 -1
- package/dist/lib/services/create-image-service.js +0 -39
- package/dist/lib/services/image-service.d.ts +0 -28
- package/dist/lib/services/image-service.d.ts.map +0 -1
- package/dist/lib/services/image-service.js +0 -45
- package/dist/services/arcgis/arcgis-image-service.d.ts.map +0 -1
- package/dist/services/create-image-source.d.ts +0 -18
- package/dist/services/create-image-source.d.ts.map +0 -1
- package/dist/services/create-image-source.js +0 -17
- package/dist/wip/lib/wfs/parse-wfs-capabilities.d.ts.map +0 -1
- package/dist/wip/lib/wfs/parse-wfs.d.ts.map +0 -1
- package/dist/wip/services/arcgis-feature-service.d.ts +0 -56
- package/dist/wip/services/arcgis-feature-service.d.ts.map +0 -1
- package/dist/wip/services/arcgis-feature-service.js +0 -27
- package/dist/wip/wfs-capabilities-loader.d.ts.map +0 -1
- package/src/services/create-image-source.ts +0 -33
- package/src/wip/services/arcgis-feature-service.ts +0 -89
- /package/dist/{wip/lib → lib/parsers}/wfs/parse-wfs-capabilities.d.ts +0 -0
- /package/dist/{wip/lib → lib/parsers}/wfs/parse-wfs.d.ts +0 -0
- /package/dist/{wip/lib → lib/parsers}/wfs/parse-wfs.js +0 -0
- /package/src/lib/{services/image-service.ts → deprecated/template-image-service.ts.disabled} +0 -0
- /package/src/{wip/lib → lib/parsers}/wfs/parse-wfs.ts +0 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Schema, GeoJSONTable} from '@loaders.gl/schema';
|
|
6
|
+
import type {VectorSourceProps, VectorSourceMetadata} from '@loaders.gl/loader-utils';
|
|
7
|
+
import type {LoaderWithParser, GetFeaturesParameters} from '@loaders.gl/loader-utils';
|
|
8
|
+
import {Source, VectorSource, mergeLoaderOptions} from '@loaders.gl/loader-utils';
|
|
9
|
+
|
|
10
|
+
import type {WFSCapabilities} from '../../wfs-capabilities-loader';
|
|
11
|
+
import {WFSCapabilitiesLoader} from '../../wfs-capabilities-loader';
|
|
12
|
+
|
|
13
|
+
import type {WMSLoaderOptions} from '../../wms-error-loader';
|
|
14
|
+
import {WMSErrorLoader} from '../../wms-error-loader';
|
|
15
|
+
|
|
16
|
+
/* eslint-disable camelcase */ // WFS XML parameters use snake_case
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @ndeprecated This is a WIP, not fully implemented
|
|
20
|
+
* @see https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm
|
|
21
|
+
*/
|
|
22
|
+
export const WFSSource = {
|
|
23
|
+
name: 'WFS',
|
|
24
|
+
id: 'wfs',
|
|
25
|
+
module: 'wms',
|
|
26
|
+
version: '0.0.0',
|
|
27
|
+
extensions: [],
|
|
28
|
+
mimeTypes: [],
|
|
29
|
+
options: {
|
|
30
|
+
url: undefined!,
|
|
31
|
+
wfs: {
|
|
32
|
+
/** Tabular loaders, normally the GeoJSONLoader */
|
|
33
|
+
loaders: []
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
type: 'wfs',
|
|
38
|
+
fromUrl: true,
|
|
39
|
+
fromBlob: false,
|
|
40
|
+
|
|
41
|
+
testURL: (url: string): boolean => url.toLowerCase().includes('wfs'),
|
|
42
|
+
createDataSource: (url, props: WFSVectorSourceProps): WFSVectorSource =>
|
|
43
|
+
new WFSVectorSource(props)
|
|
44
|
+
} as const satisfies Source<WFSVectorSource, WFSVectorSourceProps>;
|
|
45
|
+
|
|
46
|
+
/** Properties for creating a enw WFS service */
|
|
47
|
+
export type WFSVectorSourceProps = VectorSourceProps & {
|
|
48
|
+
url: string;
|
|
49
|
+
wfs?: {
|
|
50
|
+
loaders: LoaderWithParser[];
|
|
51
|
+
/** In 1.3.0, replaces references to EPSG:4326 with CRS:84 */
|
|
52
|
+
substituteCRS84?: boolean;
|
|
53
|
+
/** Default WFS parameters. If not provided here, must be provided in the various request */
|
|
54
|
+
wmsParameters?: WFSParameters;
|
|
55
|
+
/** Any additional service specific parameters */
|
|
56
|
+
vendorParameters?: Record<string, unknown>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// PARAMETER TYPES FOR WFS SOURCE
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* "Static" WFS parameters (not viewport or selected pixel dependent)
|
|
64
|
+
* These can be provided as defaults in the WFSVectorSource constructor
|
|
65
|
+
*/
|
|
66
|
+
export type WFSParameters = {
|
|
67
|
+
/** WFS version (all requests) */
|
|
68
|
+
version?: '1.3.0' | '1.1.1';
|
|
69
|
+
/** Layers to render (GetMap, GetFeatureInfo) */
|
|
70
|
+
layers?: string[];
|
|
71
|
+
/** list of layers to query.. (GetFeatureInfo) */
|
|
72
|
+
query_layers?: string[];
|
|
73
|
+
|
|
74
|
+
/** Coordinate Reference System (CRS) for the image (not the bounding box) */
|
|
75
|
+
crs?: string;
|
|
76
|
+
/** Requested format for the return image (GetMap, GetLegendGraphic) */
|
|
77
|
+
format?: 'image/png';
|
|
78
|
+
/** Requested MIME type of returned feature info (GetFeatureInfo) */
|
|
79
|
+
info_format?: 'text/plain' | 'application/geojson' | 'application/vnd.ogc.gml';
|
|
80
|
+
/** Styling - Not yet supported */
|
|
81
|
+
styles?: unknown;
|
|
82
|
+
/** Any additional parameters specific to this WFSVectorSource (GetMap) */
|
|
83
|
+
transparent?: boolean;
|
|
84
|
+
/** If layer supports time dimension */
|
|
85
|
+
time?: string;
|
|
86
|
+
/** If layer supports elevation dimension */
|
|
87
|
+
elevation?: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Parameters for GetCapabilities */
|
|
91
|
+
export type WFSGetCapabilitiesParameters = {
|
|
92
|
+
/** In case the endpoint supports multiple WFS versions */
|
|
93
|
+
version?: '1.3.0' | '1.1.1';
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Parameters for GetMap */
|
|
97
|
+
export type WFSGetMapParameters = {
|
|
98
|
+
/** In case the endpoint supports multiple WFS versions */
|
|
99
|
+
version?: '1.3.0' | '1.1.1';
|
|
100
|
+
/** bounding box of the requested map image `[[w, s], [e, n]]` */
|
|
101
|
+
// boundingBox: [min: [x: number, y: number], max: [x: number, y: number]];
|
|
102
|
+
/** bounding box of the requested map image @deprecated Use .boundingBox */
|
|
103
|
+
bbox: [number, number, number, number];
|
|
104
|
+
/** pixel width of returned image */
|
|
105
|
+
width: number;
|
|
106
|
+
/** pixels */
|
|
107
|
+
height: number;
|
|
108
|
+
/** requested format for the return image. can be provided in service constructor */
|
|
109
|
+
format?: 'image/png';
|
|
110
|
+
/** Layers to render - can be provided in service constructor */
|
|
111
|
+
layers?: string | string[];
|
|
112
|
+
/** Coordinate Reference System for the image (not bounding box). can be provided in service constructor. */
|
|
113
|
+
crs?: string;
|
|
114
|
+
/** Styling. can be provided in service constructor */
|
|
115
|
+
styles?: unknown;
|
|
116
|
+
/** Don't render background when no data. can be provided in service constructor */
|
|
117
|
+
transparent?: boolean;
|
|
118
|
+
/** If layer supports time dimension */
|
|
119
|
+
time?: string;
|
|
120
|
+
/** If layer supports elevation dimension */
|
|
121
|
+
elevation?: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// /** GetMap parameters that are specific to the current view */
|
|
125
|
+
// export type WFSGetMapViewParameters = {
|
|
126
|
+
// /** pixel width of returned image */
|
|
127
|
+
// width: number;
|
|
128
|
+
// /** pixels */
|
|
129
|
+
// height: number;
|
|
130
|
+
// /** bounding box of the requested map image */
|
|
131
|
+
// bbox: [number, number, number, number];
|
|
132
|
+
// /** Coordinate Reference System for the image (not bounding box). can be provided in service constructor. */
|
|
133
|
+
// crs?: string;
|
|
134
|
+
// };
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Parameters for GetFeatureInfo
|
|
138
|
+
* @see https://imagery.pasda.psu.edu/arcgis/services/pasda/UrbanTreeCanopy_Landcover/MapServer/WmsServer?SERVICE=WFS&
|
|
139
|
+
*/
|
|
140
|
+
export type WFSGetFeatureInfoParameters = {
|
|
141
|
+
/** In case the endpoint supports multiple WFS versions */
|
|
142
|
+
version?: '1.3.0' | '1.1.1';
|
|
143
|
+
/** x coordinate for the feature info request */
|
|
144
|
+
x: number;
|
|
145
|
+
/** y coordinate for the feature info request */
|
|
146
|
+
y: number;
|
|
147
|
+
/** MIME type of returned feature info. Can be specified in service constructor */
|
|
148
|
+
info_format?: 'text/plain' | 'application/geojson' | 'application/vnd.ogc.gml';
|
|
149
|
+
/** list of layers to query. Required but can be specified in service constructor. */
|
|
150
|
+
query_layers?: string[];
|
|
151
|
+
/** Layers to render. Required, but can be specified in service constructor */
|
|
152
|
+
layers?: string[];
|
|
153
|
+
/** Styling */
|
|
154
|
+
styles?: unknown;
|
|
155
|
+
/** bounding box of the requested map image */
|
|
156
|
+
bbox: [number, number, number, number];
|
|
157
|
+
/** pixel width of returned image */
|
|
158
|
+
width: number;
|
|
159
|
+
/** pixels */
|
|
160
|
+
height: number;
|
|
161
|
+
/** srs for the image (not the bounding box) */
|
|
162
|
+
crs?: string;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/** GetMap parameters that are specific to the current view */
|
|
166
|
+
export type WFSGetFeatureInfoViewParameters = {
|
|
167
|
+
/** x coordinate for the feature info request */
|
|
168
|
+
x: number;
|
|
169
|
+
/** y coordinate for the feature info request */
|
|
170
|
+
y: number;
|
|
171
|
+
/** pixel width of returned image */
|
|
172
|
+
width: number;
|
|
173
|
+
/** pixels */
|
|
174
|
+
height: number;
|
|
175
|
+
/** bounding box of the requested map image */
|
|
176
|
+
bbox: [number, number, number, number];
|
|
177
|
+
/** srs for the image (not the bounding box) */
|
|
178
|
+
crs?: string;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/** Parameters for DescribeLayer */
|
|
182
|
+
export type WFSDescribeLayerParameters = {
|
|
183
|
+
/** In case the endpoint supports multiple WFS versions */
|
|
184
|
+
version?: '1.3.0' | '1.1.1';
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/** Parameters for GetLegendGraphic */
|
|
188
|
+
export type WFSGetLegendGraphicParameters = {
|
|
189
|
+
/** In case the endpoint supports multiple WFS versions */
|
|
190
|
+
version?: '1.3.0' | '1.1.1';
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The WFSVectorSource class provides
|
|
197
|
+
* - provides type safe methods to form URLs to a WFS service
|
|
198
|
+
* - provides type safe methods to query and parse results (and errors) from a WFS service
|
|
199
|
+
* - implements the VectorSource interface
|
|
200
|
+
* @note Only the URL parameter conversion is supported. XML posts are not supported.
|
|
201
|
+
*/
|
|
202
|
+
export class WFSVectorSource extends VectorSource<WFSVectorSourceProps> {
|
|
203
|
+
/** Base URL to the service */
|
|
204
|
+
readonly url: string;
|
|
205
|
+
readonly data: string;
|
|
206
|
+
|
|
207
|
+
// /** In WFS 1.3.0, replaces references to EPSG:4326 with CRS:84. But not always supported. Default: false */
|
|
208
|
+
// substituteCRS84: boolean;
|
|
209
|
+
// /** In WFS 1.3.0, flips x,y (lng, lat) coordinates for the supplied coordinate systems. Default: ['ESPG:4326'] */
|
|
210
|
+
// flipCRS: string[];
|
|
211
|
+
|
|
212
|
+
// /** Default static WFS parameters */
|
|
213
|
+
// wmsParameters: Required<WFSParameters>;
|
|
214
|
+
/** Default static vendor parameters */
|
|
215
|
+
vendorParameters?: Record<string, unknown>;
|
|
216
|
+
|
|
217
|
+
capabilities: WFSCapabilities | null = null;
|
|
218
|
+
|
|
219
|
+
/** Create a WFSVectorSource */
|
|
220
|
+
constructor(props: WFSVectorSourceProps) {
|
|
221
|
+
super(props);
|
|
222
|
+
|
|
223
|
+
// TODO - defaults such as version, layers etc could be extracted from a base URL with parameters
|
|
224
|
+
// This would make pasting in any WFS URL more likely to make this class just work.
|
|
225
|
+
// const {baseUrl, parameters} = this._parseWFSUrl(props.url);
|
|
226
|
+
|
|
227
|
+
this.url = props.url;
|
|
228
|
+
this.data = props.url;
|
|
229
|
+
|
|
230
|
+
// this.substituteCRS84 = props.substituteCRS84 ?? false;
|
|
231
|
+
// this.flipCRS = ['EPSG:4326'];
|
|
232
|
+
|
|
233
|
+
// this.wmsParameters = {
|
|
234
|
+
// layers: undefined!,
|
|
235
|
+
// query_layers: undefined!,
|
|
236
|
+
// styles: undefined,
|
|
237
|
+
// version: '1.3.0',
|
|
238
|
+
// crs: 'EPSG:4326',
|
|
239
|
+
// format: 'image/png',
|
|
240
|
+
// info_format: 'text/plain',
|
|
241
|
+
// transparent: undefined!,
|
|
242
|
+
// time: undefined!,
|
|
243
|
+
// elevation: undefined!,
|
|
244
|
+
// ...props.wmsParameters
|
|
245
|
+
// };
|
|
246
|
+
|
|
247
|
+
// this.vendorParameters = props.vendorParameters || {};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async getSchema(): Promise<Schema> {
|
|
251
|
+
return {metadata: {}, fields: []};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// VectorSource implementation
|
|
255
|
+
async getMetadata(): Promise<VectorSourceMetadata> {
|
|
256
|
+
const capabilities = await this.getCapabilities();
|
|
257
|
+
return this.normalizeMetadata(capabilities);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async getFeatures(parameters: GetFeaturesParameters): Promise<GeoJSONTable> {
|
|
261
|
+
// Replace the GetImage `boundingBox` parameter with the WFS flat `bbox` parameter.
|
|
262
|
+
// const {boundingBox, bbox, ...rest} = parameters;
|
|
263
|
+
// const wmsParameters: WFSGetMapParameters = {
|
|
264
|
+
// bbox: boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox!,
|
|
265
|
+
// ...rest
|
|
266
|
+
// };
|
|
267
|
+
return {shape: 'geojson-table', type: 'FeatureCollection', features: []};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
normalizeMetadata(capabilities: WFSCapabilities): VectorSourceMetadata {
|
|
271
|
+
return capabilities as any;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// WFS Service API Stubs
|
|
275
|
+
|
|
276
|
+
/** Get Capabilities */
|
|
277
|
+
async getCapabilities(
|
|
278
|
+
wmsParameters?: WFSGetCapabilitiesParameters,
|
|
279
|
+
vendorParameters?: Record<string, unknown>
|
|
280
|
+
): Promise<WFSCapabilities> {
|
|
281
|
+
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
|
|
282
|
+
const response = await this.fetch(url);
|
|
283
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
284
|
+
this._checkResponse(response, arrayBuffer);
|
|
285
|
+
const capabilities = await WFSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
|
|
286
|
+
this.capabilities = capabilities;
|
|
287
|
+
return capabilities;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Get a map image *
|
|
291
|
+
async getMap(
|
|
292
|
+
wmsParameters: WFSGetMapParameters,
|
|
293
|
+
vendorParameters?: Record<string, unknown>
|
|
294
|
+
): Promise<ImageType> {
|
|
295
|
+
const url = this.getMapURL(wmsParameters, vendorParameters);
|
|
296
|
+
const response = await this.fetch(url);
|
|
297
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
298
|
+
this._checkResponse(response, arrayBuffer);
|
|
299
|
+
try {
|
|
300
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
301
|
+
} catch {
|
|
302
|
+
throw this._parseError(arrayBuffer);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Get Feature Info for a coordinate *
|
|
307
|
+
async getFeatureInfo(
|
|
308
|
+
wmsParameters: WFSGetFeatureInfoParameters,
|
|
309
|
+
vendorParameters?: Record<string, unknown>
|
|
310
|
+
): Promise<WFSFeatureInfo> {
|
|
311
|
+
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
312
|
+
const response = await this.fetch(url);
|
|
313
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
314
|
+
this._checkResponse(response, arrayBuffer);
|
|
315
|
+
return await WFSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Get Feature Info for a coordinate *
|
|
319
|
+
async getFeatureInfoText(
|
|
320
|
+
wmsParameters: WFSGetFeatureInfoParameters,
|
|
321
|
+
vendorParameters?: Record<string, unknown>
|
|
322
|
+
): Promise<string> {
|
|
323
|
+
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
324
|
+
const response = await this.fetch(url);
|
|
325
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
326
|
+
this._checkResponse(response, arrayBuffer);
|
|
327
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Get more information about a layer *
|
|
331
|
+
async describeLayer(
|
|
332
|
+
wmsParameters: WFSDescribeLayerParameters,
|
|
333
|
+
vendorParameters?: Record<string, unknown>
|
|
334
|
+
): Promise<WFSLayerDescription> {
|
|
335
|
+
const url = this.describeLayerURL(wmsParameters, vendorParameters);
|
|
336
|
+
const response = await this.fetch(url);
|
|
337
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
338
|
+
this._checkResponse(response, arrayBuffer);
|
|
339
|
+
return await WFSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Get an image with a semantic legend *
|
|
343
|
+
async getLegendGraphic(
|
|
344
|
+
wmsParameters: WFSGetLegendGraphicParameters,
|
|
345
|
+
vendorParameters?: Record<string, unknown>
|
|
346
|
+
): Promise<ImageType> {
|
|
347
|
+
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters);
|
|
348
|
+
const response = await this.fetch(url);
|
|
349
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
350
|
+
this._checkResponse(response, arrayBuffer);
|
|
351
|
+
try {
|
|
352
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
353
|
+
} catch {
|
|
354
|
+
throw this._parseError(arrayBuffer);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
// Typed URL creators
|
|
360
|
+
// For applications that want full control of fetching and parsing
|
|
361
|
+
|
|
362
|
+
/** Generate a URL for the GetCapabilities request */
|
|
363
|
+
getCapabilitiesURL(
|
|
364
|
+
wmsParameters?: WFSGetCapabilitiesParameters,
|
|
365
|
+
vendorParameters?: Record<string, unknown>
|
|
366
|
+
): string {
|
|
367
|
+
// @ts-expect-error
|
|
368
|
+
const options: Required<WFSGetCapabilitiesParameters> = {
|
|
369
|
+
// version: this.wmsParameters.version,
|
|
370
|
+
...wmsParameters
|
|
371
|
+
};
|
|
372
|
+
return this._getWFSUrl('GetCapabilities', options, vendorParameters);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Generate a URL for the GetMap request */
|
|
376
|
+
getMapURL(
|
|
377
|
+
wmsParameters: WFSGetMapParameters,
|
|
378
|
+
vendorParameters?: Record<string, unknown>
|
|
379
|
+
): string {
|
|
380
|
+
wmsParameters = this._getWFS130Parameters(wmsParameters);
|
|
381
|
+
// @ts-expect-error
|
|
382
|
+
const options: Required<WFSGetMapParameters> = {
|
|
383
|
+
// version: this.wmsParameters.version,
|
|
384
|
+
// format: this.wmsParameters.format,
|
|
385
|
+
// transparent: this.wmsParameters.transparent,
|
|
386
|
+
// time: this.wmsParameters.time,
|
|
387
|
+
// elevation: this.wmsParameters.elevation,
|
|
388
|
+
// layers: this.wmsParameters.layers,
|
|
389
|
+
// styles: this.wmsParameters.styles,
|
|
390
|
+
// crs: this.wmsParameters.crs,
|
|
391
|
+
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
|
|
392
|
+
// width: 1200,
|
|
393
|
+
// height: 900,
|
|
394
|
+
...wmsParameters
|
|
395
|
+
};
|
|
396
|
+
return this._getWFSUrl('GetMap', options, vendorParameters);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Generate a URL for the GetFeatureInfo request */
|
|
400
|
+
getFeatureInfoURL(
|
|
401
|
+
wmsParameters: WFSGetFeatureInfoParameters,
|
|
402
|
+
vendorParameters?: Record<string, unknown>
|
|
403
|
+
): string {
|
|
404
|
+
wmsParameters = this._getWFS130Parameters(wmsParameters);
|
|
405
|
+
|
|
406
|
+
// Replace the GetImage `boundingBox` parameter with the WFS flat `bbox` parameter.
|
|
407
|
+
const {boundingBox, bbox} = wmsParameters as any;
|
|
408
|
+
wmsParameters.bbox = boundingBox ? [...boundingBox[0], ...boundingBox[1]] : bbox!;
|
|
409
|
+
|
|
410
|
+
// @ts-expect-error
|
|
411
|
+
const options: Required<WFSGetFeatureInfoParameters> = {
|
|
412
|
+
// version: this.wmsParameters.version,
|
|
413
|
+
// // query_layers: [],
|
|
414
|
+
// // format: this.wmsParameters.format,
|
|
415
|
+
// info_format: this.wmsParameters.info_format,
|
|
416
|
+
// layers: this.wmsParameters.layers,
|
|
417
|
+
// query_layers: this.wmsParameters.query_layers,
|
|
418
|
+
// styles: this.wmsParameters.styles,
|
|
419
|
+
// crs: this.wmsParameters.crs,
|
|
420
|
+
// bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
|
|
421
|
+
// width: 1200,
|
|
422
|
+
// height: 900,
|
|
423
|
+
// x: undefined!,
|
|
424
|
+
// y: undefined!,
|
|
425
|
+
...wmsParameters
|
|
426
|
+
};
|
|
427
|
+
return this._getWFSUrl('GetFeatureInfo', options, vendorParameters);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Generate a URL for the GetFeatureInfo request */
|
|
431
|
+
describeLayerURL(
|
|
432
|
+
wmsParameters: WFSDescribeLayerParameters,
|
|
433
|
+
vendorParameters?: Record<string, unknown>
|
|
434
|
+
): string {
|
|
435
|
+
// @ts-expect-error
|
|
436
|
+
const options: Required<WFSDescribeLayerParameters> = {
|
|
437
|
+
// version: this.wmsParameters.version,
|
|
438
|
+
...wmsParameters
|
|
439
|
+
};
|
|
440
|
+
return this._getWFSUrl('DescribeLayer', options, vendorParameters);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
getLegendGraphicURL(
|
|
444
|
+
wmsParameters: WFSGetLegendGraphicParameters,
|
|
445
|
+
vendorParameters?: Record<string, unknown>
|
|
446
|
+
): string {
|
|
447
|
+
// @ts-expect-error
|
|
448
|
+
const options: Required<WFSGetLegendGraphicParameters> = {
|
|
449
|
+
// version: this.wmsParameters.version,
|
|
450
|
+
// format?
|
|
451
|
+
...wmsParameters
|
|
452
|
+
};
|
|
453
|
+
return this._getWFSUrl('GetLegendGraphic', options, vendorParameters);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// INTERNAL METHODS
|
|
457
|
+
|
|
458
|
+
_parseWFSUrl(url: string): {url: string; parameters: Record<string, unknown>} {
|
|
459
|
+
const [baseUrl, search] = url.split('?');
|
|
460
|
+
const searchParams = search.split('&');
|
|
461
|
+
|
|
462
|
+
const parameters: Record<string, unknown> = {};
|
|
463
|
+
for (const parameter of searchParams) {
|
|
464
|
+
const [key, value] = parameter.split('=');
|
|
465
|
+
parameters[key] = value;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return {url: baseUrl, parameters};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Generate a URL with parameters
|
|
473
|
+
* @note case _getWFSUrl may need to be overridden to handle certain backends?
|
|
474
|
+
* @note at the moment, only URLs with parameters are supported (no XML payloads)
|
|
475
|
+
* */
|
|
476
|
+
protected _getWFSUrl(
|
|
477
|
+
request: string,
|
|
478
|
+
wmsParameters: {version?: '1.3.0' | '1.1.1'; [key: string]: unknown},
|
|
479
|
+
vendorParameters?: Record<string, unknown>
|
|
480
|
+
): string {
|
|
481
|
+
let url = this.url;
|
|
482
|
+
let first = true;
|
|
483
|
+
|
|
484
|
+
// Add any vendor searchParams
|
|
485
|
+
const allParameters = {
|
|
486
|
+
service: 'WFS',
|
|
487
|
+
version: wmsParameters.version,
|
|
488
|
+
request,
|
|
489
|
+
...wmsParameters,
|
|
490
|
+
...this.vendorParameters,
|
|
491
|
+
...vendorParameters
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// Encode the keys
|
|
495
|
+
const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation'];
|
|
496
|
+
for (const [key, value] of Object.entries(allParameters)) {
|
|
497
|
+
// hack to preserve test cases. Not super clear if keys should be included when values are undefined
|
|
498
|
+
if (!IGNORE_EMPTY_KEYS.includes(key) || value) {
|
|
499
|
+
url += first ? '?' : '&';
|
|
500
|
+
first = false;
|
|
501
|
+
url += this._getURLParameter(key, value, wmsParameters);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return encodeURI(url);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
_getWFS130Parameters<ParametersT extends {crs?: string; srs?: string}>(
|
|
509
|
+
wmsParameters: ParametersT
|
|
510
|
+
): ParametersT {
|
|
511
|
+
const newParameters = {...wmsParameters};
|
|
512
|
+
if (newParameters.srs) {
|
|
513
|
+
newParameters.crs = newParameters.crs || newParameters.srs;
|
|
514
|
+
delete newParameters.srs;
|
|
515
|
+
}
|
|
516
|
+
return newParameters;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// eslint-disable-next-line complexity
|
|
520
|
+
_getURLParameter(key: string, value: unknown, wmsParameters: WFSParameters): string {
|
|
521
|
+
// Substitute by key
|
|
522
|
+
switch (key) {
|
|
523
|
+
case 'crs':
|
|
524
|
+
// CRS was called SRS before WFS 1.3.0
|
|
525
|
+
if (wmsParameters.version !== '1.3.0') {
|
|
526
|
+
key = 'srs';
|
|
527
|
+
// } else if (this.substituteCRS84 && value === 'EPSG:4326') {
|
|
528
|
+
// /** In 1.3.0, replaces references to 'EPSG:4326' with the new backwards compatible CRS:84 */
|
|
529
|
+
// // Substitute by value
|
|
530
|
+
// value = 'CRS:84';
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
|
|
534
|
+
case 'srs':
|
|
535
|
+
// CRS was called SRS before WFS 1.3.0
|
|
536
|
+
if (wmsParameters.version === '1.3.0') {
|
|
537
|
+
key = 'crs';
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
|
|
541
|
+
case 'bbox':
|
|
542
|
+
// Coordinate order is flipped for certain CRS in WFS 1.3.0
|
|
543
|
+
const bbox = this._flipBoundingBox(value, wmsParameters);
|
|
544
|
+
if (bbox) {
|
|
545
|
+
value = bbox;
|
|
546
|
+
}
|
|
547
|
+
break;
|
|
548
|
+
|
|
549
|
+
case 'x':
|
|
550
|
+
// i is the parameter used in WFS 1.3
|
|
551
|
+
// TODO - change parameter to `i` and convert to `x` if not 1.3
|
|
552
|
+
if (wmsParameters.version === '1.3.0') {
|
|
553
|
+
key = 'i';
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
|
|
557
|
+
case 'y':
|
|
558
|
+
// j is the parameter used in WFS 1.3
|
|
559
|
+
// TODO - change parameter to `j` and convert to `y` if not 1.3
|
|
560
|
+
if (wmsParameters.version === '1.3.0') {
|
|
561
|
+
key = 'j';
|
|
562
|
+
}
|
|
563
|
+
break;
|
|
564
|
+
|
|
565
|
+
default:
|
|
566
|
+
// do nothing
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
key = key.toUpperCase();
|
|
570
|
+
|
|
571
|
+
return Array.isArray(value)
|
|
572
|
+
? `${key}=${value.join(',')}`
|
|
573
|
+
: `${key}=${value ? String(value) : ''}`;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Coordinate order is flipped for certain CRS in WFS 1.3.0 */
|
|
577
|
+
_flipBoundingBox(
|
|
578
|
+
bboxValue: unknown,
|
|
579
|
+
wmsParameters: WFSParameters
|
|
580
|
+
): [number, number, number, number] | null {
|
|
581
|
+
// Sanity checks
|
|
582
|
+
if (!Array.isArray(bboxValue) || bboxValue.length !== 4) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const flipCoordinates = false;
|
|
587
|
+
// // Only affects WFS 1.3.0
|
|
588
|
+
// wmsParameters.version === '1.3.0' &&
|
|
589
|
+
// // Flip if we are dealing with a CRS that was flipped in 1.3.0
|
|
590
|
+
// this.flipCRS.includes(wmsParameters.crs || '') &&
|
|
591
|
+
// // Don't flip if we are substituting EPSG:4326 with CRS:84
|
|
592
|
+
// !(this.substituteCRS84 && wmsParameters.crs === 'EPSG:4326');
|
|
593
|
+
|
|
594
|
+
const bbox = bboxValue as [number, number, number, number];
|
|
595
|
+
return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** Fetches an array buffer and checks the response (boilerplate reduction) */
|
|
599
|
+
protected async _fetchArrayBuffer(url: string): Promise<ArrayBuffer> {
|
|
600
|
+
const response = await this.fetch(url);
|
|
601
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
602
|
+
this._checkResponse(response, arrayBuffer);
|
|
603
|
+
return arrayBuffer;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/** Checks for and parses a WFS XML formatted ServiceError and throws an exception */
|
|
607
|
+
protected _checkResponse(response: Response, arrayBuffer: ArrayBuffer): void {
|
|
608
|
+
const contentType = response.headers['content-type'];
|
|
609
|
+
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) {
|
|
610
|
+
// We want error responses to throw exceptions, the WMSErrorLoader can do this
|
|
611
|
+
const loadOptions = mergeLoaderOptions<WMSLoaderOptions>(this.loadOptions, {
|
|
612
|
+
wms: {throwOnError: true}
|
|
613
|
+
});
|
|
614
|
+
const error = WMSErrorLoader.parseSync?.(arrayBuffer, loadOptions);
|
|
615
|
+
throw new Error(error);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/** Error situation detected */
|
|
620
|
+
protected _parseError(arrayBuffer: ArrayBuffer): Error {
|
|
621
|
+
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.loadOptions);
|
|
622
|
+
return new Error(error);
|
|
623
|
+
}
|
|
624
|
+
}
|