@loaders.gl/wms 3.3.0-alpha.10 → 3.3.0-alpha.12
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/dist.min.js +3487 -33
- package/dist/es5/gml-loader.js +54 -0
- package/dist/es5/gml-loader.js.map +1 -0
- package/dist/es5/index.js +31 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/data-sources/image-data-source.js.map +1 -1
- package/dist/es5/lib/data-sources/{wms-data-source.js → wms-service.js} +182 -65
- package/dist/es5/lib/data-sources/wms-service.js.map +1 -0
- package/dist/es5/lib/gml/parse-gml.js +416 -0
- package/dist/es5/lib/gml/parse-gml.js.map +1 -0
- package/dist/es5/lib/wfs/parse-wfs.js +43 -0
- package/dist/es5/lib/wfs/parse-wfs.js.map +1 -0
- package/dist/es5/lib/wfs/wfs-types.js +2 -0
- package/dist/es5/lib/wfs/wfs-types.js.map +1 -0
- package/dist/es5/lib/{parse-wms.js → wms/parse-wms.js} +33 -2
- package/dist/es5/lib/wms/parse-wms.js.map +1 -0
- package/dist/es5/{wms-types.js → lib/wms/wms-types.js} +0 -0
- package/dist/es5/lib/wms/wms-types.js.map +1 -0
- package/dist/es5/lib/wmts/parse-wmts.js +43 -0
- package/dist/es5/lib/wmts/parse-wmts.js.map +1 -0
- package/dist/es5/lib/wmts/wmts-types.js +2 -0
- package/dist/es5/lib/wmts/wmts-types.js.map +1 -0
- package/dist/es5/wcs-capabilities-loader.js +54 -0
- package/dist/es5/wcs-capabilities-loader.js.map +1 -0
- package/dist/es5/wfs-capabilities-loader.js +54 -0
- package/dist/es5/wfs-capabilities-loader.js.map +1 -0
- package/dist/es5/wms-capabilities-loader.js +2 -2
- package/dist/es5/wms-capabilities-loader.js.map +1 -1
- package/dist/es5/wms-error-loader.js +54 -0
- package/dist/es5/wms-error-loader.js.map +1 -0
- package/dist/es5/wms-feature-info-loader.js +1 -1
- package/dist/es5/wms-feature-info-loader.js.map +1 -1
- package/dist/es5/wms-layer-description-loader.js +3 -3
- package/dist/es5/wms-layer-description-loader.js.map +1 -1
- package/dist/es5/wmts-capabilities-loader.js +54 -0
- package/dist/es5/wmts-capabilities-loader.js.map +1 -0
- package/dist/esm/gml-loader.js +25 -0
- package/dist/esm/gml-loader.js.map +1 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/data-sources/image-data-source.js.map +1 -1
- package/dist/esm/lib/data-sources/wms-service.js +156 -0
- package/dist/esm/lib/data-sources/wms-service.js.map +1 -0
- package/dist/esm/lib/gml/parse-gml.js +348 -0
- package/dist/esm/lib/gml/parse-gml.js.map +1 -0
- package/dist/esm/lib/wfs/parse-wfs.js +32 -0
- package/dist/esm/lib/wfs/parse-wfs.js.map +1 -0
- package/dist/esm/lib/wfs/wfs-types.js +2 -0
- package/dist/esm/lib/wfs/wfs-types.js.map +1 -0
- package/dist/esm/lib/{parse-wms.js → wms/parse-wms.js} +31 -2
- package/dist/esm/lib/wms/parse-wms.js.map +1 -0
- package/dist/esm/{wms-types.js → lib/wms/wms-types.js} +0 -0
- package/dist/esm/lib/wms/wms-types.js.map +1 -0
- package/dist/esm/lib/wmts/parse-wmts.js +32 -0
- package/dist/esm/lib/wmts/parse-wmts.js.map +1 -0
- package/dist/esm/lib/wmts/wmts-types.js +2 -0
- package/dist/esm/lib/wmts/wmts-types.js.map +1 -0
- package/dist/esm/wcs-capabilities-loader.js +25 -0
- package/dist/esm/wcs-capabilities-loader.js.map +1 -0
- package/dist/esm/wfs-capabilities-loader.js +25 -0
- package/dist/esm/wfs-capabilities-loader.js.map +1 -0
- package/dist/esm/wms-capabilities-loader.js +2 -2
- package/dist/esm/wms-capabilities-loader.js.map +1 -1
- package/dist/esm/wms-error-loader.js +25 -0
- package/dist/esm/wms-error-loader.js.map +1 -0
- package/dist/esm/wms-feature-info-loader.js +1 -1
- package/dist/esm/wms-feature-info-loader.js.map +1 -1
- package/dist/esm/wms-layer-description-loader.js +3 -3
- package/dist/esm/wms-layer-description-loader.js.map +1 -1
- package/dist/esm/wmts-capabilities-loader.js +25 -0
- package/dist/esm/wmts-capabilities-loader.js.map +1 -0
- package/package.json +15 -5
- package/src/gml-loader.ts +40 -0
- package/src/index.ts +23 -4
- package/src/lib/data-sources/image-data-source.ts +1 -2
- package/src/lib/data-sources/wms-service.ts +313 -0
- package/src/lib/gml/parse-gml.ts +500 -0
- package/src/lib/wfs/parse-wfs.ts +39 -0
- package/src/lib/wfs/wfs-types.ts +78 -0
- package/src/lib/{parse-wms.ts → wms/parse-wms.ts} +41 -4
- package/src/{wms-types.ts → lib/wms/wms-types.ts} +3 -1
- package/src/lib/wmts/parse-wmts.ts +39 -0
- package/src/lib/wmts/wmts-types.ts +77 -0
- package/src/wcs-capabilities-loader.ts +40 -0
- package/src/wfs-capabilities-loader.ts +40 -0
- package/src/wms-capabilities-loader.ts +1 -1
- package/src/wms-error-loader.ts +40 -0
- package/src/wms-feature-info-loader.ts +1 -1
- package/src/wms-layer-description-loader.ts +4 -4
- package/src/wmts-capabilities-loader.ts +40 -0
- package/dist/es5/lib/data-sources/wms-data-source.js.map +0 -1
- package/dist/es5/lib/parse-wms.js.map +0 -1
- package/dist/es5/wms-types.js.map +0 -1
- package/dist/esm/lib/data-sources/wms-data-source.js +0 -70
- package/dist/esm/lib/data-sources/wms-data-source.js.map +0 -1
- package/dist/esm/lib/parse-wms.js.map +0 -1
- package/dist/esm/wms-types.js.map +0 -1
- package/src/lib/data-sources/wms-data-source.ts +0 -99
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
// Forked from https://github.com/derhuerst/parse-gml-polygon/blob/master/index.js
|
|
4
|
+
// under ISC license
|
|
5
|
+
|
|
6
|
+
/* eslint-disable no-continue, default-case */
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
// GeoJSON,
|
|
10
|
+
// Feature,
|
|
11
|
+
// FeatureCollection,
|
|
12
|
+
Geometry,
|
|
13
|
+
Position
|
|
14
|
+
// GeoJsonProperties,
|
|
15
|
+
// Point,
|
|
16
|
+
// MultiPoint,
|
|
17
|
+
// LineString,
|
|
18
|
+
// MultiLineString,
|
|
19
|
+
// Polygon,
|
|
20
|
+
// MultiPolygon,
|
|
21
|
+
// GeometryCollection
|
|
22
|
+
} from '@loaders.gl/schema';
|
|
23
|
+
|
|
24
|
+
import {XMLLoader} from '@loaders.gl/xml';
|
|
25
|
+
import deepStrictEqual from 'deep-strict-equal';
|
|
26
|
+
import rewind from '@turf/rewind';
|
|
27
|
+
|
|
28
|
+
function noTransform(...coords) {
|
|
29
|
+
return coords;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ParseGMLOptions = {
|
|
33
|
+
transformCoords?: Function;
|
|
34
|
+
stride?: 2 | 3 | 4;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ParseGMLContext = {
|
|
38
|
+
srsDimension?: number;
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses a typed data structure from raw XML for GML features
|
|
44
|
+
* @note Error handlings is fairly weak
|
|
45
|
+
*/
|
|
46
|
+
export function parseGML(text: string, options) {
|
|
47
|
+
// GeoJSON | null {
|
|
48
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
49
|
+
|
|
50
|
+
options = {transformCoords: noTransform, stride: 2, ...options};
|
|
51
|
+
const context = createChildContext(parsedXML, options, {});
|
|
52
|
+
|
|
53
|
+
return parseGMLToGeometry(parsedXML, options, context);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parse a GeoJSON geometry from GML XML */
|
|
57
|
+
export function parseGMLToGeometry(
|
|
58
|
+
inputXML: any,
|
|
59
|
+
options: ParseGMLOptions,
|
|
60
|
+
context: ParseGMLContext
|
|
61
|
+
): Geometry | null {
|
|
62
|
+
const childContext = createChildContext(inputXML, options, context);
|
|
63
|
+
|
|
64
|
+
let geometry: Geometry | null = null;
|
|
65
|
+
|
|
66
|
+
const [name, xml] = getFirstKeyValue(inputXML);
|
|
67
|
+
|
|
68
|
+
switch (name) {
|
|
69
|
+
// case 'gml:MultiPoint':
|
|
70
|
+
// geometry = {
|
|
71
|
+
// type: 'MultiPoint',
|
|
72
|
+
// coordinates: parseMultiPoint(xml, options, childContext)
|
|
73
|
+
// };
|
|
74
|
+
// break;
|
|
75
|
+
|
|
76
|
+
case 'gml:LineString':
|
|
77
|
+
geometry = {
|
|
78
|
+
type: 'LineString',
|
|
79
|
+
coordinates: parseLinearRingOrLineString(xml, options, childContext)
|
|
80
|
+
};
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
// case 'gml:MultiLineString':
|
|
84
|
+
// geometry = {
|
|
85
|
+
// type: 'MultiLineString',
|
|
86
|
+
// coordinates: parseMultiLineString(xml, options, childContext)
|
|
87
|
+
// };
|
|
88
|
+
// break;
|
|
89
|
+
|
|
90
|
+
case 'gml:Polygon':
|
|
91
|
+
case 'gml:Rectangle':
|
|
92
|
+
geometry = {
|
|
93
|
+
type: 'Polygon',
|
|
94
|
+
coordinates: parsePolygonOrRectangle(xml, options, childContext)
|
|
95
|
+
};
|
|
96
|
+
break;
|
|
97
|
+
case 'gml:Surface':
|
|
98
|
+
geometry = {
|
|
99
|
+
type: 'MultiPolygon',
|
|
100
|
+
coordinates: parseSurface(xml, options, childContext)
|
|
101
|
+
};
|
|
102
|
+
break;
|
|
103
|
+
case 'gml:MultiSurface':
|
|
104
|
+
geometry = {
|
|
105
|
+
type: 'MultiPolygon',
|
|
106
|
+
coordinates: parseMultiSurface(xml, options, childContext)
|
|
107
|
+
};
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// todo
|
|
115
|
+
return rewind(geometry, {mutate: true});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Parse a list of coordinates from a string */
|
|
119
|
+
function parseCoords(s: string, options: ParseGMLOptions, context: ParseGMLContext): Position[] {
|
|
120
|
+
const stride = context.srsDimension || options.stride || 2;
|
|
121
|
+
|
|
122
|
+
// Handle white space
|
|
123
|
+
const coords = s.replace(/\s+/g, ' ').trim().split(' ');
|
|
124
|
+
|
|
125
|
+
if (coords.length === 0 || coords.length % stride !== 0) {
|
|
126
|
+
throw new Error(`invalid coordinates list (stride ${stride})`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const points: Position[] = [];
|
|
130
|
+
for (let i = 0; i < coords.length - 1; i += stride) {
|
|
131
|
+
const point = coords.slice(i, i + stride).map(parseFloat);
|
|
132
|
+
points.push(options.transformCoords?.(...point) || point);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return points;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function parsePosList(xml: any, options: ParseGMLOptions, context: ParseGMLContext) {
|
|
139
|
+
const childContext = createChildContext(xml, options, context);
|
|
140
|
+
|
|
141
|
+
const coords = textOf(xml);
|
|
142
|
+
if (!coords) {
|
|
143
|
+
throw new Error('invalid gml:posList element');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return parseCoords(coords, options, childContext);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function parsePos(xml: any, options: ParseGMLOptions, context: ParseGMLContext): Position {
|
|
150
|
+
const childContext = createChildContext(xml, options, context);
|
|
151
|
+
|
|
152
|
+
const coords = textOf(xml);
|
|
153
|
+
if (!coords) {
|
|
154
|
+
throw new Error('invalid gml:pos element');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const points = parseCoords(coords, options, childContext);
|
|
158
|
+
if (points.length !== 1) {
|
|
159
|
+
throw new Error('gml:pos must have 1 point');
|
|
160
|
+
}
|
|
161
|
+
return points[0];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function parsePoint(xml: any, options: ParseGMLOptions, context: ParseGMLContext): number[] {
|
|
165
|
+
const childContext = createChildContext(xml, options, context);
|
|
166
|
+
|
|
167
|
+
// TODO AV: Parse other gml:Point options
|
|
168
|
+
const pos = findIn(xml, 'gml:pos');
|
|
169
|
+
if (!pos) {
|
|
170
|
+
throw new Error('invalid gml:Point element, expected a gml:pos subelement');
|
|
171
|
+
}
|
|
172
|
+
return parsePos(pos, options, childContext);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function parseLinearRingOrLineString(
|
|
176
|
+
xml: any,
|
|
177
|
+
options: ParseGMLOptions,
|
|
178
|
+
context: ParseGMLContext
|
|
179
|
+
): Position[] {
|
|
180
|
+
// or a LineStringSegment
|
|
181
|
+
const childContext = createChildContext(xml, options, context);
|
|
182
|
+
|
|
183
|
+
let points: Position[] = [];
|
|
184
|
+
|
|
185
|
+
const posList = findIn(xml, 'gml:posList');
|
|
186
|
+
if (posList) {
|
|
187
|
+
points = parsePosList(posList, options, childContext);
|
|
188
|
+
} else {
|
|
189
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
190
|
+
switch (childName) {
|
|
191
|
+
case 'gml:Point':
|
|
192
|
+
points.push(parsePoint(childXML, options, childContext));
|
|
193
|
+
break;
|
|
194
|
+
case 'gml:pos':
|
|
195
|
+
points.push(parsePos(childXML, options, childContext));
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (points.length === 0) {
|
|
204
|
+
throw new Error(`${xml.name} must have > 0 points`);
|
|
205
|
+
}
|
|
206
|
+
return points;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function parseCurveSegments(
|
|
210
|
+
xml: any,
|
|
211
|
+
options: ParseGMLOptions,
|
|
212
|
+
context: ParseGMLContext
|
|
213
|
+
): Position[] {
|
|
214
|
+
const points: Position[] = [];
|
|
215
|
+
|
|
216
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
217
|
+
switch (childName) {
|
|
218
|
+
case 'gml:LineStringSegment':
|
|
219
|
+
const points2 = parseLinearRingOrLineString(childXML, options, context);
|
|
220
|
+
|
|
221
|
+
// remove overlapping
|
|
222
|
+
const end = points[points.length - 1];
|
|
223
|
+
const start = points2[0];
|
|
224
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
225
|
+
points2.shift();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
points.push(...points2);
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (points.length === 0) {
|
|
236
|
+
throw new Error('gml:Curve > gml:segments must have > 0 points');
|
|
237
|
+
}
|
|
238
|
+
return points;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function parseRing(
|
|
242
|
+
xml: any,
|
|
243
|
+
options: ParseGMLOptions,
|
|
244
|
+
context: ParseGMLContext
|
|
245
|
+
): Position[] {
|
|
246
|
+
const childContext = createChildContext(xml, options, context);
|
|
247
|
+
|
|
248
|
+
const points: Position[] = [];
|
|
249
|
+
|
|
250
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
251
|
+
switch (childName) {
|
|
252
|
+
case 'gml:curveMember':
|
|
253
|
+
let points2;
|
|
254
|
+
|
|
255
|
+
const lineString = findIn(childXML, 'gml:LineString');
|
|
256
|
+
if (lineString) {
|
|
257
|
+
points2 = parseLinearRingOrLineString(lineString, options, childContext);
|
|
258
|
+
} else {
|
|
259
|
+
const segments = findIn(childXML, 'gml:Curve', 'gml:segments');
|
|
260
|
+
if (!segments) {
|
|
261
|
+
throw new Error(`invalid ${childName} element`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
points2 = parseCurveSegments(segments, options, childContext);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// remove overlapping
|
|
268
|
+
const end = points[points.length - 1];
|
|
269
|
+
const start = points2[0];
|
|
270
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
271
|
+
points2.shift();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
points.push(...points2);
|
|
275
|
+
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (points.length < 4) {
|
|
281
|
+
throw new Error(`${xml.name} must have >= 4 points`);
|
|
282
|
+
}
|
|
283
|
+
return points;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function parseExteriorOrInterior(
|
|
287
|
+
xml: any,
|
|
288
|
+
options: ParseGMLOptions,
|
|
289
|
+
context: ParseGMLContext
|
|
290
|
+
): Position[] {
|
|
291
|
+
const linearRing = findIn(xml, 'gml:LinearRing');
|
|
292
|
+
if (linearRing) {
|
|
293
|
+
return parseLinearRingOrLineString(linearRing, options, context);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const ring = findIn(xml, 'gml:Ring');
|
|
297
|
+
if (!ring) {
|
|
298
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return parseRing(ring, options, context);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function parsePolygonOrRectangle(
|
|
305
|
+
xml: any,
|
|
306
|
+
options: ParseGMLOptions,
|
|
307
|
+
context: ParseGMLContext
|
|
308
|
+
): Position[][] {
|
|
309
|
+
// or PolygonPatch
|
|
310
|
+
const childContext = createChildContext(xml, options, context);
|
|
311
|
+
|
|
312
|
+
const exterior = findIn(xml, 'gml:exterior');
|
|
313
|
+
if (!exterior) {
|
|
314
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const pointLists: Position[][] = [parseExteriorOrInterior(exterior, options, childContext)];
|
|
318
|
+
|
|
319
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
320
|
+
switch (childName) {
|
|
321
|
+
case 'gml:interior':
|
|
322
|
+
pointLists.push(parseExteriorOrInterior(childXML, options, childContext));
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return pointLists;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function parseSurface(
|
|
331
|
+
xml: any,
|
|
332
|
+
options: ParseGMLOptions,
|
|
333
|
+
context: ParseGMLContext
|
|
334
|
+
): Position[][][] {
|
|
335
|
+
const childContext = createChildContext(xml, options, context);
|
|
336
|
+
|
|
337
|
+
const patches = findIn(xml, 'gml:patches');
|
|
338
|
+
if (!patches) {
|
|
339
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const polygons: Position[][][] = [];
|
|
343
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
344
|
+
switch (childName) {
|
|
345
|
+
case 'gml:PolygonPatch':
|
|
346
|
+
case 'gml:Rectangle':
|
|
347
|
+
polygons.push(parsePolygonOrRectangle(childXML, options, childContext));
|
|
348
|
+
break;
|
|
349
|
+
|
|
350
|
+
default:
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (polygons.length === 0) {
|
|
356
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return polygons;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function parseCompositeSurface(
|
|
363
|
+
xml: any,
|
|
364
|
+
options: ParseGMLOptions,
|
|
365
|
+
context: ParseGMLContext
|
|
366
|
+
): Position[][][] {
|
|
367
|
+
const childContext = createChildContext(xml, options, context);
|
|
368
|
+
|
|
369
|
+
const polygons: Position[][][] = [];
|
|
370
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
371
|
+
switch (childName) {
|
|
372
|
+
case 'gml:surfaceMember':
|
|
373
|
+
case 'gml:surfaceMembers':
|
|
374
|
+
const [c2Name, c2Xml] = getFirstKeyValue(childXML);
|
|
375
|
+
switch (c2Name) {
|
|
376
|
+
case 'gml:Surface':
|
|
377
|
+
polygons.push(...parseSurface(c2Xml, options, childContext));
|
|
378
|
+
break;
|
|
379
|
+
case 'gml:Polygon':
|
|
380
|
+
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (polygons.length === 0) {
|
|
388
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
389
|
+
}
|
|
390
|
+
return polygons;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export function parseMultiSurface(
|
|
394
|
+
xml: any,
|
|
395
|
+
options: ParseGMLOptions,
|
|
396
|
+
context: ParseGMLContext
|
|
397
|
+
): Position[][][] {
|
|
398
|
+
let el = xml;
|
|
399
|
+
|
|
400
|
+
const surfaceMembers = findIn(xml, 'gml:LinearRing');
|
|
401
|
+
if (surfaceMembers) {
|
|
402
|
+
el = surfaceMembers;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const polygons: Position[][][] = [];
|
|
406
|
+
for (const [childName, childXML] of Object.entries(el)) {
|
|
407
|
+
switch (childName) {
|
|
408
|
+
case 'gml:Surface':
|
|
409
|
+
const polygons2 = parseSurface(childXML, options, context);
|
|
410
|
+
polygons.push(...polygons2);
|
|
411
|
+
break;
|
|
412
|
+
case 'gml:surfaceMember':
|
|
413
|
+
const polygons3 = parseSurfaceMember(childXML, options, context);
|
|
414
|
+
polygons.push(...polygons3);
|
|
415
|
+
break;
|
|
416
|
+
|
|
417
|
+
case 'gml:surfaceMembers':
|
|
418
|
+
const polygonXML = findIn(childXML, 'gml:Polygon');
|
|
419
|
+
for (const surfaceMemberXML of polygonXML as []) {
|
|
420
|
+
const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context);
|
|
421
|
+
polygons.push(...polygons3);
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (polygons.length === 0) {
|
|
428
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return polygons;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function parseSurfaceMember(
|
|
435
|
+
xml: any,
|
|
436
|
+
options: ParseGMLOptions,
|
|
437
|
+
context: ParseGMLContext
|
|
438
|
+
): Position[][][] {
|
|
439
|
+
const [childName, childXml] = getFirstKeyValue(xml);
|
|
440
|
+
switch (childName) {
|
|
441
|
+
case 'gml:CompositeSurface':
|
|
442
|
+
return parseCompositeSurface(childXml, options, context);
|
|
443
|
+
case 'gml:Surface':
|
|
444
|
+
return parseSurface(childXml, options, context);
|
|
445
|
+
case 'gml:Polygon':
|
|
446
|
+
return [parsePolygonOrRectangle(childXml, options, context)];
|
|
447
|
+
}
|
|
448
|
+
throw new Error(`${childName} must have polygons`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Helpers
|
|
452
|
+
|
|
453
|
+
function textOf(el: any): string {
|
|
454
|
+
if (typeof el !== 'string') {
|
|
455
|
+
throw new Error('expected string');
|
|
456
|
+
}
|
|
457
|
+
return el;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function findIn(root: any, ...tags: string[]): any {
|
|
461
|
+
let el = root;
|
|
462
|
+
for (const tag of tags) {
|
|
463
|
+
const child = el[tag];
|
|
464
|
+
if (!child) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
el = child;
|
|
468
|
+
}
|
|
469
|
+
return el;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** @returns the first [key, value] pair in an object, or ['', null] if empty object */
|
|
473
|
+
function getFirstKeyValue(object: any): [string, any] {
|
|
474
|
+
if (object && typeof object === 'object') {
|
|
475
|
+
for (const [key, value] of Object.entries(object)) {
|
|
476
|
+
return [key, value];
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return ['', null];
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** A bit heavyweight for just tracking dimension? */
|
|
483
|
+
function createChildContext(xml, options, context): ParseGMLContext {
|
|
484
|
+
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;
|
|
485
|
+
|
|
486
|
+
if (srsDimensionAttribute) {
|
|
487
|
+
const srsDimension = parseInt(srsDimensionAttribute);
|
|
488
|
+
if (Number.isNaN(srsDimension) || srsDimension <= 0) {
|
|
489
|
+
throw new Error(
|
|
490
|
+
`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const childContext = Object.create(context);
|
|
495
|
+
childContext.srsDimension = srsDimension;
|
|
496
|
+
return childContext;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return context;
|
|
500
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {WFSCapabilities} from './wfs-types';
|
|
4
|
+
|
|
5
|
+
import {XMLLoader} from '@loaders.gl/xml';
|
|
6
|
+
|
|
7
|
+
// GetCapabilities
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parses a typed data structure from raw XML for `GetCapabilities` response
|
|
11
|
+
* @note Error handlings is fairly weak
|
|
12
|
+
*/
|
|
13
|
+
export function parseWFSCapabilities(text: string, options): WFSCapabilities {
|
|
14
|
+
// Remove namespaces in XML
|
|
15
|
+
options = {...options, xml: {...options?.xml, removeNSPrefix: true}};
|
|
16
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
17
|
+
const xmlCapabilities: any = parsedXML.Capabilities || parsedXML;
|
|
18
|
+
return uncapitalizeKeys(xmlCapabilities);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function uncapitalizeKeys(object: any): any {
|
|
22
|
+
if (object && typeof object === 'object') {
|
|
23
|
+
const newObject = {};
|
|
24
|
+
for (const [key, value] of Object.entries(object)) {
|
|
25
|
+
newObject[uncapitalize(key)] = uncapitalizeKeys(value);
|
|
26
|
+
}
|
|
27
|
+
return newObject;
|
|
28
|
+
}
|
|
29
|
+
return object;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Uncapitalize first letter of a string
|
|
34
|
+
* @param {string} str
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function uncapitalize(str: string): string {
|
|
38
|
+
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
|
|
39
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// loaders.gl, MIT licenses
|
|
2
|
+
|
|
3
|
+
/** All capabilities of a WFS service - response to a WFS `GetCapabilities` data structure extracted from XML */
|
|
4
|
+
export type WFSCapabilities = {
|
|
5
|
+
serviceIdentification: {
|
|
6
|
+
title: string;
|
|
7
|
+
serviceTypeVersion: string;
|
|
8
|
+
serviceType: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
serviceProvider: {
|
|
12
|
+
providerName: string;
|
|
13
|
+
providerSite: string;
|
|
14
|
+
serviceContact: {
|
|
15
|
+
individualName: string;
|
|
16
|
+
positionName: string;
|
|
17
|
+
contactInfo: {
|
|
18
|
+
address: {
|
|
19
|
+
administrativeArea: string;
|
|
20
|
+
city: string;
|
|
21
|
+
country: string;
|
|
22
|
+
deliveryPoint: string;
|
|
23
|
+
electronicMailAddress: string;
|
|
24
|
+
postalCode: string;
|
|
25
|
+
};
|
|
26
|
+
phone: {
|
|
27
|
+
voice: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
operationsMetadata: {
|
|
34
|
+
GetCapabilities: any;
|
|
35
|
+
GetFeatureInfo: any;
|
|
36
|
+
GetTile: any;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
contents: {
|
|
40
|
+
layers: {
|
|
41
|
+
abstract: string;
|
|
42
|
+
identifier: string;
|
|
43
|
+
title: string;
|
|
44
|
+
formats: string[];
|
|
45
|
+
styles: {
|
|
46
|
+
identifier: string;
|
|
47
|
+
isDefault: string;
|
|
48
|
+
title: string;
|
|
49
|
+
abstract?: string;
|
|
50
|
+
}[];
|
|
51
|
+
bounds: {
|
|
52
|
+
left: number;
|
|
53
|
+
right: number;
|
|
54
|
+
bottom: number;
|
|
55
|
+
top: number;
|
|
56
|
+
};
|
|
57
|
+
tileMatrixSetLinks: {
|
|
58
|
+
tileMatrixSet: string;
|
|
59
|
+
}[];
|
|
60
|
+
tileMatrixSets: {
|
|
61
|
+
identifier: string;
|
|
62
|
+
matrixIds: {
|
|
63
|
+
identifier: string;
|
|
64
|
+
matrixHeight: number;
|
|
65
|
+
matrixWidth: number;
|
|
66
|
+
scaleDenominator: number;
|
|
67
|
+
tileWidth: number;
|
|
68
|
+
tileHeight: number;
|
|
69
|
+
topLeftCorner: {
|
|
70
|
+
lon: number;
|
|
71
|
+
lat: number;
|
|
72
|
+
};
|
|
73
|
+
}[];
|
|
74
|
+
};
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
@@ -4,10 +4,11 @@ import type {
|
|
|
4
4
|
WMSCapabilities,
|
|
5
5
|
WMSLayer,
|
|
6
6
|
WMSRequest,
|
|
7
|
-
WMSFeatureInfo
|
|
7
|
+
WMSFeatureInfo,
|
|
8
|
+
WMSLayerDescription
|
|
8
9
|
// WMSFeature,
|
|
9
10
|
// WMSLayerDescription
|
|
10
|
-
} from '
|
|
11
|
+
} from './wms-types';
|
|
11
12
|
|
|
12
13
|
import {XMLLoader} from '@loaders.gl/xml';
|
|
13
14
|
|
|
@@ -62,13 +63,26 @@ function extractLayer(xmlLayer: any): WMSLayer {
|
|
|
62
63
|
layers: []
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
// Single layer is not represented as array in XML
|
|
67
|
+
const xmlLayers = getXMLArray(xmlLayer?.Layer);
|
|
68
|
+
|
|
69
|
+
for (const xmlSubLayer of xmlLayers) {
|
|
66
70
|
layer.layers?.push(extractLayer(xmlSubLayer));
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
return layer;
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
function getXMLArray(xmlValue: any) {
|
|
77
|
+
if (Array.isArray(xmlValue)) {
|
|
78
|
+
return xmlValue;
|
|
79
|
+
}
|
|
80
|
+
if (xmlValue) {
|
|
81
|
+
return [xmlValue];
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
72
86
|
// GetFeatureInfo
|
|
73
87
|
|
|
74
88
|
/**
|
|
@@ -88,5 +102,28 @@ export function parseWMSFeatureInfo(text: string, options): WMSFeatureInfo {
|
|
|
88
102
|
|
|
89
103
|
function extractFeature(xmlFeature: any) {
|
|
90
104
|
const xmlFields = xmlFeature || {};
|
|
91
|
-
|
|
105
|
+
// TODO - not correct
|
|
106
|
+
return {
|
|
107
|
+
attributes: xmlFields,
|
|
108
|
+
type: '',
|
|
109
|
+
bounds: {bottom: 0, top: 0, left: 0, right: 0}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// GetFeatureInfo
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parses a typed data structure from raw XML for `GetFeatureInfo` response
|
|
117
|
+
* @note Error handlings is fairly weak
|
|
118
|
+
*/
|
|
119
|
+
export function parseWMSLayerDescription(text: string, options): WMSLayerDescription {
|
|
120
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
121
|
+
// TODO - implement parser
|
|
122
|
+
return parsedXML as unknown as WMSLayerDescription;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function parseWMSError(text: string, options): string {
|
|
126
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
127
|
+
const error = parsedXML?.ServiceExceptionReport?.ServiceException || 'Unknown error';
|
|
128
|
+
return String(error);
|
|
92
129
|
}
|
|
@@ -39,13 +39,15 @@ export type WMSFeatureInfo = {
|
|
|
39
39
|
|
|
40
40
|
export type WMSFeature = {
|
|
41
41
|
attributes: Record<string, number | string>;
|
|
42
|
+
type: string;
|
|
43
|
+
bounds: {top: number; bottom: number; left: number; right: number};
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
// DescribeLayer
|
|
45
47
|
|
|
46
48
|
/** Layer description - response to a WMS `DescribeLayer` request */
|
|
47
49
|
export type WMSLayerDescription = {
|
|
48
|
-
|
|
50
|
+
layers: {}[];
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
// // WIP
|