@loaders.gl/wms 3.3.0-alpha.10 → 3.3.0-alpha.11
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,348 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { XMLLoader } from '@loaders.gl/xml';
|
|
4
|
+
import deepStrictEqual from 'deep-strict-equal';
|
|
5
|
+
import rewind from '@turf/rewind';
|
|
6
|
+
function noTransform() {
|
|
7
|
+
for (var _len = arguments.length, coords = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
|
+
coords[_key] = arguments[_key];
|
|
9
|
+
}
|
|
10
|
+
return coords;
|
|
11
|
+
}
|
|
12
|
+
export function parseGML(text, options) {
|
|
13
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
14
|
+
options = {
|
|
15
|
+
transformCoords: noTransform,
|
|
16
|
+
stride: 2,
|
|
17
|
+
...options
|
|
18
|
+
};
|
|
19
|
+
const context = createChildContext(parsedXML, options, {});
|
|
20
|
+
return parseGMLToGeometry(parsedXML, options, context);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function parseGMLToGeometry(inputXML, options, context) {
|
|
24
|
+
const childContext = createChildContext(inputXML, options, context);
|
|
25
|
+
let geometry = null;
|
|
26
|
+
const [name, xml] = getFirstKeyValue(inputXML);
|
|
27
|
+
switch (name) {
|
|
28
|
+
|
|
29
|
+
case 'gml:LineString':
|
|
30
|
+
geometry = {
|
|
31
|
+
type: 'LineString',
|
|
32
|
+
coordinates: parseLinearRingOrLineString(xml, options, childContext)
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
case 'gml:Polygon':
|
|
37
|
+
case 'gml:Rectangle':
|
|
38
|
+
geometry = {
|
|
39
|
+
type: 'Polygon',
|
|
40
|
+
coordinates: parsePolygonOrRectangle(xml, options, childContext)
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
43
|
+
case 'gml:Surface':
|
|
44
|
+
geometry = {
|
|
45
|
+
type: 'MultiPolygon',
|
|
46
|
+
coordinates: parseSurface(xml, options, childContext)
|
|
47
|
+
};
|
|
48
|
+
break;
|
|
49
|
+
case 'gml:MultiSurface':
|
|
50
|
+
geometry = {
|
|
51
|
+
type: 'MultiPolygon',
|
|
52
|
+
coordinates: parseMultiSurface(xml, options, childContext)
|
|
53
|
+
};
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return rewind(geometry, {
|
|
60
|
+
mutate: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseCoords(s, options, context) {
|
|
65
|
+
const stride = context.srsDimension || options.stride || 2;
|
|
66
|
+
|
|
67
|
+
const coords = s.replace(/\s+/g, ' ').trim().split(' ');
|
|
68
|
+
if (coords.length === 0 || coords.length % stride !== 0) {
|
|
69
|
+
throw new Error("invalid coordinates list (stride ".concat(stride, ")"));
|
|
70
|
+
}
|
|
71
|
+
const points = [];
|
|
72
|
+
for (let i = 0; i < coords.length - 1; i += stride) {
|
|
73
|
+
var _options$transformCoo;
|
|
74
|
+
const point = coords.slice(i, i + stride).map(parseFloat);
|
|
75
|
+
points.push(((_options$transformCoo = options.transformCoords) === null || _options$transformCoo === void 0 ? void 0 : _options$transformCoo.call(options, ...point)) || point);
|
|
76
|
+
}
|
|
77
|
+
return points;
|
|
78
|
+
}
|
|
79
|
+
export function parsePosList(xml, options, context) {
|
|
80
|
+
const childContext = createChildContext(xml, options, context);
|
|
81
|
+
const coords = textOf(xml);
|
|
82
|
+
if (!coords) {
|
|
83
|
+
throw new Error('invalid gml:posList element');
|
|
84
|
+
}
|
|
85
|
+
return parseCoords(coords, options, childContext);
|
|
86
|
+
}
|
|
87
|
+
export function parsePos(xml, options, context) {
|
|
88
|
+
const childContext = createChildContext(xml, options, context);
|
|
89
|
+
const coords = textOf(xml);
|
|
90
|
+
if (!coords) {
|
|
91
|
+
throw new Error('invalid gml:pos element');
|
|
92
|
+
}
|
|
93
|
+
const points = parseCoords(coords, options, childContext);
|
|
94
|
+
if (points.length !== 1) {
|
|
95
|
+
throw new Error('gml:pos must have 1 point');
|
|
96
|
+
}
|
|
97
|
+
return points[0];
|
|
98
|
+
}
|
|
99
|
+
export function parsePoint(xml, options, context) {
|
|
100
|
+
const childContext = createChildContext(xml, options, context);
|
|
101
|
+
|
|
102
|
+
const pos = findIn(xml, 'gml:pos');
|
|
103
|
+
if (!pos) {
|
|
104
|
+
throw new Error('invalid gml:Point element, expected a gml:pos subelement');
|
|
105
|
+
}
|
|
106
|
+
return parsePos(pos, options, childContext);
|
|
107
|
+
}
|
|
108
|
+
export function parseLinearRingOrLineString(xml, options, context) {
|
|
109
|
+
const childContext = createChildContext(xml, options, context);
|
|
110
|
+
let points = [];
|
|
111
|
+
const posList = findIn(xml, 'gml:posList');
|
|
112
|
+
if (posList) {
|
|
113
|
+
points = parsePosList(posList, options, childContext);
|
|
114
|
+
} else {
|
|
115
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
116
|
+
switch (childName) {
|
|
117
|
+
case 'gml:Point':
|
|
118
|
+
points.push(parsePoint(childXML, options, childContext));
|
|
119
|
+
break;
|
|
120
|
+
case 'gml:pos':
|
|
121
|
+
points.push(parsePos(childXML, options, childContext));
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (points.length === 0) {
|
|
129
|
+
throw new Error("".concat(xml.name, " must have > 0 points"));
|
|
130
|
+
}
|
|
131
|
+
return points;
|
|
132
|
+
}
|
|
133
|
+
export function parseCurveSegments(xml, options, context) {
|
|
134
|
+
const points = [];
|
|
135
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
136
|
+
switch (childName) {
|
|
137
|
+
case 'gml:LineStringSegment':
|
|
138
|
+
const points2 = parseLinearRingOrLineString(childXML, options, context);
|
|
139
|
+
|
|
140
|
+
const end = points[points.length - 1];
|
|
141
|
+
const start = points2[0];
|
|
142
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
143
|
+
points2.shift();
|
|
144
|
+
}
|
|
145
|
+
points.push(...points2);
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (points.length === 0) {
|
|
152
|
+
throw new Error('gml:Curve > gml:segments must have > 0 points');
|
|
153
|
+
}
|
|
154
|
+
return points;
|
|
155
|
+
}
|
|
156
|
+
export function parseRing(xml, options, context) {
|
|
157
|
+
const childContext = createChildContext(xml, options, context);
|
|
158
|
+
const points = [];
|
|
159
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
160
|
+
switch (childName) {
|
|
161
|
+
case 'gml:curveMember':
|
|
162
|
+
let points2;
|
|
163
|
+
const lineString = findIn(childXML, 'gml:LineString');
|
|
164
|
+
if (lineString) {
|
|
165
|
+
points2 = parseLinearRingOrLineString(lineString, options, childContext);
|
|
166
|
+
} else {
|
|
167
|
+
const segments = findIn(childXML, 'gml:Curve', 'gml:segments');
|
|
168
|
+
if (!segments) {
|
|
169
|
+
throw new Error("invalid ".concat(childName, " element"));
|
|
170
|
+
}
|
|
171
|
+
points2 = parseCurveSegments(segments, options, childContext);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const end = points[points.length - 1];
|
|
175
|
+
const start = points2[0];
|
|
176
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
177
|
+
points2.shift();
|
|
178
|
+
}
|
|
179
|
+
points.push(...points2);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (points.length < 4) {
|
|
184
|
+
throw new Error("".concat(xml.name, " must have >= 4 points"));
|
|
185
|
+
}
|
|
186
|
+
return points;
|
|
187
|
+
}
|
|
188
|
+
export function parseExteriorOrInterior(xml, options, context) {
|
|
189
|
+
const linearRing = findIn(xml, 'gml:LinearRing');
|
|
190
|
+
if (linearRing) {
|
|
191
|
+
return parseLinearRingOrLineString(linearRing, options, context);
|
|
192
|
+
}
|
|
193
|
+
const ring = findIn(xml, 'gml:Ring');
|
|
194
|
+
if (!ring) {
|
|
195
|
+
throw new Error("invalid ".concat(xml.name, " element"));
|
|
196
|
+
}
|
|
197
|
+
return parseRing(ring, options, context);
|
|
198
|
+
}
|
|
199
|
+
export function parsePolygonOrRectangle(xml, options, context) {
|
|
200
|
+
const childContext = createChildContext(xml, options, context);
|
|
201
|
+
const exterior = findIn(xml, 'gml:exterior');
|
|
202
|
+
if (!exterior) {
|
|
203
|
+
throw new Error("invalid ".concat(xml.name, " element"));
|
|
204
|
+
}
|
|
205
|
+
const pointLists = [parseExteriorOrInterior(exterior, options, childContext)];
|
|
206
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
207
|
+
switch (childName) {
|
|
208
|
+
case 'gml:interior':
|
|
209
|
+
pointLists.push(parseExteriorOrInterior(childXML, options, childContext));
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return pointLists;
|
|
214
|
+
}
|
|
215
|
+
export function parseSurface(xml, options, context) {
|
|
216
|
+
const childContext = createChildContext(xml, options, context);
|
|
217
|
+
const patches = findIn(xml, 'gml:patches');
|
|
218
|
+
if (!patches) {
|
|
219
|
+
throw new Error("invalid ".concat(xml.name, " element"));
|
|
220
|
+
}
|
|
221
|
+
const polygons = [];
|
|
222
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
223
|
+
switch (childName) {
|
|
224
|
+
case 'gml:PolygonPatch':
|
|
225
|
+
case 'gml:Rectangle':
|
|
226
|
+
polygons.push(parsePolygonOrRectangle(childXML, options, childContext));
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (polygons.length === 0) {
|
|
233
|
+
throw new Error("".concat(xml.name, " must have > 0 polygons"));
|
|
234
|
+
}
|
|
235
|
+
return polygons;
|
|
236
|
+
}
|
|
237
|
+
export function parseCompositeSurface(xml, options, context) {
|
|
238
|
+
const childContext = createChildContext(xml, options, context);
|
|
239
|
+
const polygons = [];
|
|
240
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
241
|
+
switch (childName) {
|
|
242
|
+
case 'gml:surfaceMember':
|
|
243
|
+
case 'gml:surfaceMembers':
|
|
244
|
+
const [c2Name, c2Xml] = getFirstKeyValue(childXML);
|
|
245
|
+
switch (c2Name) {
|
|
246
|
+
case 'gml:Surface':
|
|
247
|
+
polygons.push(...parseSurface(c2Xml, options, childContext));
|
|
248
|
+
break;
|
|
249
|
+
case 'gml:Polygon':
|
|
250
|
+
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (polygons.length === 0) {
|
|
257
|
+
throw new Error("".concat(xml.name, " must have > 0 polygons"));
|
|
258
|
+
}
|
|
259
|
+
return polygons;
|
|
260
|
+
}
|
|
261
|
+
export function parseMultiSurface(xml, options, context) {
|
|
262
|
+
let el = xml;
|
|
263
|
+
const surfaceMembers = findIn(xml, 'gml:LinearRing');
|
|
264
|
+
if (surfaceMembers) {
|
|
265
|
+
el = surfaceMembers;
|
|
266
|
+
}
|
|
267
|
+
const polygons = [];
|
|
268
|
+
for (const [childName, childXML] of Object.entries(el)) {
|
|
269
|
+
switch (childName) {
|
|
270
|
+
case 'gml:Surface':
|
|
271
|
+
const polygons2 = parseSurface(childXML, options, context);
|
|
272
|
+
polygons.push(...polygons2);
|
|
273
|
+
break;
|
|
274
|
+
case 'gml:surfaceMember':
|
|
275
|
+
const polygons3 = parseSurfaceMember(childXML, options, context);
|
|
276
|
+
polygons.push(...polygons3);
|
|
277
|
+
break;
|
|
278
|
+
case 'gml:surfaceMembers':
|
|
279
|
+
const polygonXML = findIn(childXML, 'gml:Polygon');
|
|
280
|
+
for (const surfaceMemberXML of polygonXML) {
|
|
281
|
+
const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context);
|
|
282
|
+
polygons.push(...polygons3);
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (polygons.length === 0) {
|
|
288
|
+
throw new Error("".concat(xml.name, " must have > 0 polygons"));
|
|
289
|
+
}
|
|
290
|
+
return polygons;
|
|
291
|
+
}
|
|
292
|
+
function parseSurfaceMember(xml, options, context) {
|
|
293
|
+
const [childName, childXml] = getFirstKeyValue(xml);
|
|
294
|
+
switch (childName) {
|
|
295
|
+
case 'gml:CompositeSurface':
|
|
296
|
+
return parseCompositeSurface(childXml, options, context);
|
|
297
|
+
case 'gml:Surface':
|
|
298
|
+
return parseSurface(childXml, options, context);
|
|
299
|
+
case 'gml:Polygon':
|
|
300
|
+
return [parsePolygonOrRectangle(childXml, options, context)];
|
|
301
|
+
}
|
|
302
|
+
throw new Error("".concat(childName, " must have polygons"));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function textOf(el) {
|
|
306
|
+
if (typeof el !== 'string') {
|
|
307
|
+
throw new Error('expected string');
|
|
308
|
+
}
|
|
309
|
+
return el;
|
|
310
|
+
}
|
|
311
|
+
function findIn(root) {
|
|
312
|
+
let el = root;
|
|
313
|
+
for (var _len2 = arguments.length, tags = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
314
|
+
tags[_key2 - 1] = arguments[_key2];
|
|
315
|
+
}
|
|
316
|
+
for (const tag of tags) {
|
|
317
|
+
const child = el[tag];
|
|
318
|
+
if (!child) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
el = child;
|
|
322
|
+
}
|
|
323
|
+
return el;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function getFirstKeyValue(object) {
|
|
327
|
+
if (object && typeof object === 'object') {
|
|
328
|
+
for (const [key, value] of Object.entries(object)) {
|
|
329
|
+
return [key, value];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return ['', null];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function createChildContext(xml, options, context) {
|
|
336
|
+
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;
|
|
337
|
+
if (srsDimensionAttribute) {
|
|
338
|
+
const srsDimension = parseInt(srsDimensionAttribute);
|
|
339
|
+
if (Number.isNaN(srsDimension) || srsDimension <= 0) {
|
|
340
|
+
throw new Error("invalid srsDimension attribute value \"".concat(srsDimensionAttribute, "\", expected a positive integer"));
|
|
341
|
+
}
|
|
342
|
+
const childContext = Object.create(context);
|
|
343
|
+
childContext.srsDimension = srsDimension;
|
|
344
|
+
return childContext;
|
|
345
|
+
}
|
|
346
|
+
return context;
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=parse-gml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-gml.js","names":["XMLLoader","deepStrictEqual","rewind","noTransform","coords","parseGML","text","options","parsedXML","parseTextSync","transformCoords","stride","context","createChildContext","parseGMLToGeometry","inputXML","childContext","geometry","name","xml","getFirstKeyValue","type","coordinates","parseLinearRingOrLineString","parsePolygonOrRectangle","parseSurface","parseMultiSurface","mutate","parseCoords","s","srsDimension","replace","trim","split","length","Error","points","i","point","slice","map","parseFloat","push","parsePosList","textOf","parsePos","parsePoint","pos","findIn","posList","childName","childXML","Object","entries","parseCurveSegments","points2","end","start","shift","parseRing","lineString","segments","parseExteriorOrInterior","linearRing","ring","exterior","pointLists","patches","polygons","parseCompositeSurface","c2Name","c2Xml","el","surfaceMembers","polygons2","polygons3","parseSurfaceMember","polygonXML","surfaceMemberXML","childXml","root","tags","tag","child","object","key","value","srsDimensionAttribute","attributes","parseInt","Number","isNaN","create"],"sources":["../../../../src/lib/gml/parse-gml.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// Forked from https://github.com/derhuerst/parse-gml-polygon/blob/master/index.js\n// under ISC license\n\n/* eslint-disable no-continue, default-case */\n\nimport type {\n // GeoJSON,\n // Feature,\n // FeatureCollection,\n Geometry,\n Position\n // GeoJsonProperties,\n // Point,\n // MultiPoint,\n // LineString,\n // MultiLineString,\n // Polygon,\n // MultiPolygon,\n // GeometryCollection\n} from '@loaders.gl/schema';\n\nimport {XMLLoader} from '@loaders.gl/xml';\nimport deepStrictEqual from 'deep-strict-equal';\nimport rewind from '@turf/rewind';\n\nfunction noTransform(...coords) {\n return coords;\n}\n\nexport type ParseGMLOptions = {\n transformCoords?: Function;\n stride?: 2 | 3 | 4;\n};\n\nexport type ParseGMLContext = {\n srsDimension?: number;\n [key: string]: any;\n};\n\n/**\n * Parses a typed data structure from raw XML for GML features\n * @note Error handlings is fairly weak\n */\nexport function parseGML(text: string, options) {\n // GeoJSON | null {\n const parsedXML = XMLLoader.parseTextSync(text, options);\n\n options = {transformCoords: noTransform, stride: 2, ...options};\n const context = createChildContext(parsedXML, options, {});\n\n return parseGMLToGeometry(parsedXML, options, context);\n}\n\n/** Parse a GeoJSON geometry from GML XML */\nexport function parseGMLToGeometry(\n inputXML: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Geometry | null {\n const childContext = createChildContext(inputXML, options, context);\n\n let geometry: Geometry | null = null;\n\n const [name, xml] = getFirstKeyValue(inputXML);\n\n switch (name) {\n // case 'gml:MultiPoint':\n // geometry = {\n // type: 'MultiPoint',\n // coordinates: parseMultiPoint(xml, options, childContext)\n // };\n // break;\n\n case 'gml:LineString':\n geometry = {\n type: 'LineString',\n coordinates: parseLinearRingOrLineString(xml, options, childContext)\n };\n break;\n\n // case 'gml:MultiLineString':\n // geometry = {\n // type: 'MultiLineString',\n // coordinates: parseMultiLineString(xml, options, childContext)\n // };\n // break;\n\n case 'gml:Polygon':\n case 'gml:Rectangle':\n geometry = {\n type: 'Polygon',\n coordinates: parsePolygonOrRectangle(xml, options, childContext)\n };\n break;\n case 'gml:Surface':\n geometry = {\n type: 'MultiPolygon',\n coordinates: parseSurface(xml, options, childContext)\n };\n break;\n case 'gml:MultiSurface':\n geometry = {\n type: 'MultiPolygon',\n coordinates: parseMultiSurface(xml, options, childContext)\n };\n break;\n\n default:\n return null;\n }\n\n // todo\n return rewind(geometry, {mutate: true});\n}\n\n/** Parse a list of coordinates from a string */\nfunction parseCoords(s: string, options: ParseGMLOptions, context: ParseGMLContext): Position[] {\n const stride = context.srsDimension || options.stride || 2;\n\n // Handle white space\n const coords = s.replace(/\\s+/g, ' ').trim().split(' ');\n\n if (coords.length === 0 || coords.length % stride !== 0) {\n throw new Error(`invalid coordinates list (stride ${stride})`);\n }\n\n const points: Position[] = [];\n for (let i = 0; i < coords.length - 1; i += stride) {\n const point = coords.slice(i, i + stride).map(parseFloat);\n points.push(options.transformCoords?.(...point) || point);\n }\n\n return points;\n}\n\nexport function parsePosList(xml: any, options: ParseGMLOptions, context: ParseGMLContext) {\n const childContext = createChildContext(xml, options, context);\n\n const coords = textOf(xml);\n if (!coords) {\n throw new Error('invalid gml:posList element');\n }\n\n return parseCoords(coords, options, childContext);\n}\n\nexport function parsePos(xml: any, options: ParseGMLOptions, context: ParseGMLContext): Position {\n const childContext = createChildContext(xml, options, context);\n\n const coords = textOf(xml);\n if (!coords) {\n throw new Error('invalid gml:pos element');\n }\n\n const points = parseCoords(coords, options, childContext);\n if (points.length !== 1) {\n throw new Error('gml:pos must have 1 point');\n }\n return points[0];\n}\n\nexport function parsePoint(xml: any, options: ParseGMLOptions, context: ParseGMLContext): number[] {\n const childContext = createChildContext(xml, options, context);\n\n // TODO AV: Parse other gml:Point options\n const pos = findIn(xml, 'gml:pos');\n if (!pos) {\n throw new Error('invalid gml:Point element, expected a gml:pos subelement');\n }\n return parsePos(pos, options, childContext);\n}\n\nexport function parseLinearRingOrLineString(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[] {\n // or a LineStringSegment\n const childContext = createChildContext(xml, options, context);\n\n let points: Position[] = [];\n\n const posList = findIn(xml, 'gml:posList');\n if (posList) {\n points = parsePosList(posList, options, childContext);\n } else {\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:Point':\n points.push(parsePoint(childXML, options, childContext));\n break;\n case 'gml:pos':\n points.push(parsePos(childXML, options, childContext));\n break;\n default:\n continue;\n }\n }\n }\n\n if (points.length === 0) {\n throw new Error(`${xml.name} must have > 0 points`);\n }\n return points;\n}\n\nexport function parseCurveSegments(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[] {\n const points: Position[] = [];\n\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:LineStringSegment':\n const points2 = parseLinearRingOrLineString(childXML, options, context);\n\n // remove overlapping\n const end = points[points.length - 1];\n const start = points2[0];\n if (end && start && deepStrictEqual(end, start)) {\n points2.shift();\n }\n\n points.push(...points2);\n break;\n default:\n continue;\n }\n }\n\n if (points.length === 0) {\n throw new Error('gml:Curve > gml:segments must have > 0 points');\n }\n return points;\n}\n\nexport function parseRing(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[] {\n const childContext = createChildContext(xml, options, context);\n\n const points: Position[] = [];\n\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:curveMember':\n let points2;\n\n const lineString = findIn(childXML, 'gml:LineString');\n if (lineString) {\n points2 = parseLinearRingOrLineString(lineString, options, childContext);\n } else {\n const segments = findIn(childXML, 'gml:Curve', 'gml:segments');\n if (!segments) {\n throw new Error(`invalid ${childName} element`);\n }\n\n points2 = parseCurveSegments(segments, options, childContext);\n }\n\n // remove overlapping\n const end = points[points.length - 1];\n const start = points2[0];\n if (end && start && deepStrictEqual(end, start)) {\n points2.shift();\n }\n\n points.push(...points2);\n\n break;\n }\n }\n\n if (points.length < 4) {\n throw new Error(`${xml.name} must have >= 4 points`);\n }\n return points;\n}\n\nexport function parseExteriorOrInterior(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[] {\n const linearRing = findIn(xml, 'gml:LinearRing');\n if (linearRing) {\n return parseLinearRingOrLineString(linearRing, options, context);\n }\n\n const ring = findIn(xml, 'gml:Ring');\n if (!ring) {\n throw new Error(`invalid ${xml.name} element`);\n }\n\n return parseRing(ring, options, context);\n}\n\nexport function parsePolygonOrRectangle(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[][] {\n // or PolygonPatch\n const childContext = createChildContext(xml, options, context);\n\n const exterior = findIn(xml, 'gml:exterior');\n if (!exterior) {\n throw new Error(`invalid ${xml.name} element`);\n }\n\n const pointLists: Position[][] = [parseExteriorOrInterior(exterior, options, childContext)];\n\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:interior':\n pointLists.push(parseExteriorOrInterior(childXML, options, childContext));\n break;\n }\n }\n\n return pointLists;\n}\n\nexport function parseSurface(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[][][] {\n const childContext = createChildContext(xml, options, context);\n\n const patches = findIn(xml, 'gml:patches');\n if (!patches) {\n throw new Error(`invalid ${xml.name} element`);\n }\n\n const polygons: Position[][][] = [];\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:PolygonPatch':\n case 'gml:Rectangle':\n polygons.push(parsePolygonOrRectangle(childXML, options, childContext));\n break;\n\n default:\n continue;\n }\n }\n\n if (polygons.length === 0) {\n throw new Error(`${xml.name} must have > 0 polygons`);\n }\n\n return polygons;\n}\n\nexport function parseCompositeSurface(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[][][] {\n const childContext = createChildContext(xml, options, context);\n\n const polygons: Position[][][] = [];\n for (const [childName, childXML] of Object.entries(xml)) {\n switch (childName) {\n case 'gml:surfaceMember':\n case 'gml:surfaceMembers':\n const [c2Name, c2Xml] = getFirstKeyValue(childXML);\n switch (c2Name) {\n case 'gml:Surface':\n polygons.push(...parseSurface(c2Xml, options, childContext));\n break;\n case 'gml:Polygon':\n polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));\n break;\n }\n break;\n }\n }\n\n if (polygons.length === 0) {\n throw new Error(`${xml.name} must have > 0 polygons`);\n }\n return polygons;\n}\n\nexport function parseMultiSurface(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[][][] {\n let el = xml;\n\n const surfaceMembers = findIn(xml, 'gml:LinearRing');\n if (surfaceMembers) {\n el = surfaceMembers;\n }\n\n const polygons: Position[][][] = [];\n for (const [childName, childXML] of Object.entries(el)) {\n switch (childName) {\n case 'gml:Surface':\n const polygons2 = parseSurface(childXML, options, context);\n polygons.push(...polygons2);\n break;\n case 'gml:surfaceMember':\n const polygons3 = parseSurfaceMember(childXML, options, context);\n polygons.push(...polygons3);\n break;\n\n case 'gml:surfaceMembers':\n const polygonXML = findIn(childXML, 'gml:Polygon');\n for (const surfaceMemberXML of polygonXML as []) {\n const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context);\n polygons.push(...polygons3);\n }\n break;\n }\n }\n\n if (polygons.length === 0) {\n throw new Error(`${xml.name} must have > 0 polygons`);\n }\n\n return polygons;\n}\n\nfunction parseSurfaceMember(\n xml: any,\n options: ParseGMLOptions,\n context: ParseGMLContext\n): Position[][][] {\n const [childName, childXml] = getFirstKeyValue(xml);\n switch (childName) {\n case 'gml:CompositeSurface':\n return parseCompositeSurface(childXml, options, context);\n case 'gml:Surface':\n return parseSurface(childXml, options, context);\n case 'gml:Polygon':\n return [parsePolygonOrRectangle(childXml, options, context)];\n }\n throw new Error(`${childName} must have polygons`);\n}\n\n// Helpers\n\nfunction textOf(el: any): string {\n if (typeof el !== 'string') {\n throw new Error('expected string');\n }\n return el;\n}\n\nfunction findIn(root: any, ...tags: string[]): any {\n let el = root;\n for (const tag of tags) {\n const child = el[tag];\n if (!child) {\n return null;\n }\n el = child;\n }\n return el;\n}\n\n/** @returns the first [key, value] pair in an object, or ['', null] if empty object */\nfunction getFirstKeyValue(object: any): [string, any] {\n if (object && typeof object === 'object') {\n for (const [key, value] of Object.entries(object)) {\n return [key, value];\n }\n }\n return ['', null];\n}\n\n/** A bit heavyweight for just tracking dimension? */\nfunction createChildContext(xml, options, context): ParseGMLContext {\n const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;\n\n if (srsDimensionAttribute) {\n const srsDimension = parseInt(srsDimensionAttribute);\n if (Number.isNaN(srsDimension) || srsDimension <= 0) {\n throw new Error(\n `invalid srsDimension attribute value \"${srsDimensionAttribute}\", expected a positive integer`\n );\n }\n\n const childContext = Object.create(context);\n childContext.srsDimension = srsDimension;\n return childContext;\n }\n\n return context;\n}\n"],"mappings":";;AAuBA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AAE;MACnD,MAAM,IAAIK,KAAK,kDAC4BoD,qBAAqB,qCAC/D;IACH;IAEA,MAAMvE,YAAY,GAAGoC,MAAM,CAACwC,MAAM,CAAChF,OAAO,CAAC;IAC3CI,YAAY,CAACc,YAAY,GAAGA,YAAY;IACxC,OAAOd,YAAY;EACrB;EAEA,OAAOJ,OAAO;AAChB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { XMLLoader } from '@loaders.gl/xml';
|
|
4
|
+
|
|
5
|
+
export function parseWFSCapabilities(text, options) {
|
|
6
|
+
var _options;
|
|
7
|
+
options = {
|
|
8
|
+
...options,
|
|
9
|
+
xml: {
|
|
10
|
+
...((_options = options) === null || _options === void 0 ? void 0 : _options.xml),
|
|
11
|
+
removeNSPrefix: true
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
15
|
+
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
16
|
+
return uncapitalizeKeys(xmlCapabilities);
|
|
17
|
+
}
|
|
18
|
+
function uncapitalizeKeys(object) {
|
|
19
|
+
if (object && typeof object === 'object') {
|
|
20
|
+
const newObject = {};
|
|
21
|
+
for (const [key, value] of Object.entries(object)) {
|
|
22
|
+
newObject[uncapitalize(key)] = uncapitalizeKeys(value);
|
|
23
|
+
}
|
|
24
|
+
return newObject;
|
|
25
|
+
}
|
|
26
|
+
return object;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function uncapitalize(str) {
|
|
30
|
+
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=parse-wfs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-wfs.js","names":["XMLLoader","parseWFSCapabilities","text","options","xml","removeNSPrefix","parsedXML","parseTextSync","xmlCapabilities","Capabilities","uncapitalizeKeys","object","newObject","key","value","Object","entries","uncapitalize","str","charAt","toLowerCase","slice"],"sources":["../../../../src/lib/wfs/parse-wfs.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {WFSCapabilities} from './wfs-types';\n\nimport {XMLLoader} from '@loaders.gl/xml';\n\n// GetCapabilities\n\n/**\n * Parses a typed data structure from raw XML for `GetCapabilities` response\n * @note Error handlings is fairly weak\n */\nexport function parseWFSCapabilities(text: string, options): WFSCapabilities {\n // Remove namespaces in XML\n options = {...options, xml: {...options?.xml, removeNSPrefix: true}};\n const parsedXML = XMLLoader.parseTextSync(text, options);\n const xmlCapabilities: any = parsedXML.Capabilities || parsedXML;\n return uncapitalizeKeys(xmlCapabilities);\n}\n\nfunction uncapitalizeKeys(object: any): any {\n if (object && typeof object === 'object') {\n const newObject = {};\n for (const [key, value] of Object.entries(object)) {\n newObject[uncapitalize(key)] = uncapitalizeKeys(value);\n }\n return newObject;\n }\n return object;\n}\n\n/**\n * Uncapitalize first letter of a string\n * @param {string} str\n * @returns {string}\n */\nfunction uncapitalize(str: string): string {\n return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;\n}\n"],"mappings":";;AAIA,SAAQA,SAAS,QAAO,iBAAiB;;AAQzC,OAAO,SAASC,oBAAoB,CAACC,IAAY,EAAEC,OAAO,EAAmB;EAAA;EAE3EA,OAAO,GAAG;IAAC,GAAGA,OAAO;IAAEC,GAAG,EAAE;MAAC,gBAAGD,OAAO,6CAAP,SAASC,GAAG;MAAEC,cAAc,EAAE;IAAI;EAAC,CAAC;EACpE,MAAMC,SAAS,GAAGN,SAAS,CAACO,aAAa,CAACL,IAAI,EAAEC,OAAO,CAAC;EACxD,MAAMK,eAAoB,GAAGF,SAAS,CAACG,YAAY,IAAIH,SAAS;EAChE,OAAOI,gBAAgB,CAACF,eAAe,CAAC;AAC1C;AAEA,SAASE,gBAAgB,CAACC,MAAW,EAAO;EAC1C,IAAIA,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IACxC,MAAMC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;MACjDC,SAAS,CAACK,YAAY,CAACJ,GAAG,CAAC,CAAC,GAAGH,gBAAgB,CAACI,KAAK,CAAC;IACxD;IACA,OAAOF,SAAS;EAClB;EACA,OAAOD,MAAM;AACf;;AAOA,SAASM,YAAY,CAACC,GAAW,EAAU;EACzC,OAAO,OAAOA,GAAG,KAAK,QAAQ,GAAGA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC,GAAGH,GAAG;AACnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wfs-types.js","names":[],"sources":["../../../../src/lib/wfs/wfs-types.ts"],"sourcesContent":["// loaders.gl, MIT licenses\n\n/** All capabilities of a WFS service - response to a WFS `GetCapabilities` data structure extracted from XML */\nexport type WFSCapabilities = {\n serviceIdentification: {\n title: string;\n serviceTypeVersion: string;\n serviceType: string;\n };\n \n serviceProvider: {\n providerName: string;\n providerSite: string;\n serviceContact: {\n individualName: string;\n positionName: string;\n contactInfo: {\n address: {\n administrativeArea: string;\n city: string;\n country: string;\n deliveryPoint: string;\n electronicMailAddress: string;\n postalCode: string;\n };\n phone: {\n voice: string;\n };\n };\n };\n };\n \n operationsMetadata: {\n GetCapabilities: any;\n GetFeatureInfo: any;\n GetTile: any;\n };\n \n contents: {\n layers: {\n abstract: string;\n identifier: string;\n title: string;\n formats: string[];\n styles: {\n identifier: string;\n isDefault: string;\n title: string;\n abstract?: string;\n }[];\n bounds: {\n left: number;\n right: number;\n bottom: number;\n top: number;\n };\n tileMatrixSetLinks: {\n tileMatrixSet: string;\n }[];\n tileMatrixSets: {\n identifier: string;\n matrixIds: {\n identifier: string;\n matrixHeight: number;\n matrixWidth: number;\n scaleDenominator: number;\n tileWidth: number;\n tileHeight: number;\n topLeftCorner: {\n lon: number;\n lat: number;\n };\n }[];\n };\n }[];\n };\n };\n "],"mappings":""}
|
|
@@ -45,12 +45,23 @@ function extractLayer(xmlLayer) {
|
|
|
45
45
|
srs: (xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.SRS) || [],
|
|
46
46
|
layers: []
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
const xmlLayers = getXMLArray(xmlLayer === null || xmlLayer === void 0 ? void 0 : xmlLayer.Layer);
|
|
50
|
+
for (const xmlSubLayer of xmlLayers) {
|
|
49
51
|
var _layer$layers;
|
|
50
52
|
(_layer$layers = layer.layers) === null || _layer$layers === void 0 ? void 0 : _layer$layers.push(extractLayer(xmlSubLayer));
|
|
51
53
|
}
|
|
52
54
|
return layer;
|
|
53
55
|
}
|
|
56
|
+
function getXMLArray(xmlValue) {
|
|
57
|
+
if (Array.isArray(xmlValue)) {
|
|
58
|
+
return xmlValue;
|
|
59
|
+
}
|
|
60
|
+
if (xmlValue) {
|
|
61
|
+
return [xmlValue];
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
54
65
|
|
|
55
66
|
export function parseWMSFeatureInfo(text, options) {
|
|
56
67
|
var _parsedXML$FeatureInf;
|
|
@@ -64,7 +75,25 @@ export function parseWMSFeatureInfo(text, options) {
|
|
|
64
75
|
function extractFeature(xmlFeature) {
|
|
65
76
|
const xmlFields = xmlFeature || {};
|
|
66
77
|
return {
|
|
67
|
-
attributes: xmlFields
|
|
78
|
+
attributes: xmlFields,
|
|
79
|
+
type: '',
|
|
80
|
+
bounds: {
|
|
81
|
+
bottom: 0,
|
|
82
|
+
top: 0,
|
|
83
|
+
left: 0,
|
|
84
|
+
right: 0
|
|
85
|
+
}
|
|
68
86
|
};
|
|
69
87
|
}
|
|
88
|
+
|
|
89
|
+
export function parseWMSLayerDescription(text, options) {
|
|
90
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
91
|
+
return parsedXML;
|
|
92
|
+
}
|
|
93
|
+
export function parseWMSError(text, options) {
|
|
94
|
+
var _parsedXML$ServiceExc;
|
|
95
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
96
|
+
const error = (parsedXML === null || parsedXML === void 0 ? void 0 : (_parsedXML$ServiceExc = parsedXML.ServiceExceptionReport) === null || _parsedXML$ServiceExc === void 0 ? void 0 : _parsedXML$ServiceExc.ServiceException) || 'Unknown error';
|
|
97
|
+
return String(error);
|
|
98
|
+
}
|
|
70
99
|
//# sourceMappingURL=parse-wms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-wms.js","names":["XMLLoader","parseWMSCapabilities","text","options","parsedXML","parseTextSync","xmlCapabilities","WMT_MS_Capabilities","WMS_Capabilities","extractCapabilities","xml","capabilities","name","Service","Name","title","Title","keywords","requests","layer","extractLayer","Capability","Layer","raw","keyword","KeywordList","Keyword","push","xmlRequest","Object","entries","Request","extractRequest","format","Format","mimeTypes","Array","isArray","xmlLayer","srs","SRS","layers","xmlLayers","getXMLArray","xmlSubLayer","xmlValue","parseWMSFeatureInfo","xmlFeatureInfo","FeatureInfoResponse","FIELDS","xmlFeatures","features","map","xmlFeature","extractFeature","xmlFields","attributes","type","bounds","bottom","top","left","right","parseWMSLayerDescription","parseWMSError","error","ServiceExceptionReport","ServiceException","String"],"sources":["../../../../src/lib/wms/parse-wms.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {\n WMSCapabilities,\n WMSLayer,\n WMSRequest,\n WMSFeatureInfo,\n WMSLayerDescription\n // WMSFeature,\n // WMSLayerDescription\n} from './wms-types';\n\nimport {XMLLoader} from '@loaders.gl/xml';\n\n// GetCapabilities\n\n/**\n * Parses a typed data structure from raw XML for `GetCapabilities` response\n * @note Error handlings is fairly weak\n */\nexport function parseWMSCapabilities(text: string, options): WMSCapabilities {\n const parsedXML = XMLLoader.parseTextSync(text, options);\n const xmlCapabilities: any =\n parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML;\n return extractCapabilities(xmlCapabilities);\n}\n\n/** Extract typed capability data from XML */\nfunction extractCapabilities(xml: any): WMSCapabilities {\n const capabilities: WMSCapabilities = {\n name: xml.Service?.Name || 'unnamed',\n title: xml.Service?.Title,\n keywords: [],\n requests: {},\n layer: extractLayer(xml.Capability?.Layer),\n raw: xml\n };\n\n for (const keyword of xml.Service?.KeywordList?.Keyword || []) {\n capabilities.keywords.push(keyword);\n }\n\n for (const [name, xmlRequest] of Object.entries(xml.Capability?.Request || {})) {\n capabilities.requests[name] = extractRequest(name, xmlRequest);\n }\n\n return capabilities;\n}\n\n/** Extract typed request data from XML */\nfunction extractRequest(name: string, xmlRequest: any): WMSRequest {\n const format: string | string[] = xmlRequest?.Format;\n const mimeTypes: string[] = Array.isArray(format) ? format : [format];\n return {name, mimeTypes};\n}\n\n/** Extract request data */\nfunction extractLayer(xmlLayer: any): WMSLayer {\n const layer: WMSLayer = {\n name: xmlLayer?.Name,\n title: xmlLayer?.Title,\n srs: xmlLayer?.SRS || [],\n layers: []\n };\n\n // Single layer is not represented as array in XML\n const xmlLayers = getXMLArray(xmlLayer?.Layer);\n\n for (const xmlSubLayer of xmlLayers) {\n layer.layers?.push(extractLayer(xmlSubLayer));\n }\n\n return layer;\n}\n\nfunction getXMLArray(xmlValue: any) {\n if (Array.isArray(xmlValue)) {\n return xmlValue;\n }\n if (xmlValue) {\n return [xmlValue];\n }\n return [];\n}\n\n// GetFeatureInfo\n\n/**\n * Parses a typed data structure from raw XML for `GetFeatureInfo` response\n * @note Error handlings is fairly weak\n */\nexport function parseWMSFeatureInfo(text: string, options): WMSFeatureInfo {\n const parsedXML = XMLLoader.parseTextSync(text, options);\n const xmlFeatureInfo: any = parsedXML.FeatureInfoResponse?.FIELDS || [];\n\n const xmlFeatures = Array.isArray(xmlFeatureInfo) ? xmlFeatureInfo : [xmlFeatureInfo];\n\n return {\n features: xmlFeatures.map((xmlFeature) => extractFeature(xmlFeature))\n };\n}\n\nfunction extractFeature(xmlFeature: any) {\n const xmlFields = xmlFeature || {};\n // TODO - not correct\n return {\n attributes: xmlFields,\n type: '',\n bounds: {bottom: 0, top: 0, left: 0, right: 0}\n };\n}\n\n// GetFeatureInfo\n\n/**\n * Parses a typed data structure from raw XML for `GetFeatureInfo` response\n * @note Error handlings is fairly weak\n */\nexport function parseWMSLayerDescription(text: string, options): WMSLayerDescription {\n const parsedXML = XMLLoader.parseTextSync(text, options);\n // TODO - implement parser\n return parsedXML as unknown as WMSLayerDescription;\n}\n\nexport function parseWMSError(text: string, options): string {\n const parsedXML = XMLLoader.parseTextSync(text, options);\n const error = parsedXML?.ServiceExceptionReport?.ServiceException || 'Unknown error';\n return String(error);\n}\n"],"mappings":";;AAYA,SAAQA,SAAS,QAAO,iBAAiB;;AAQzC,OAAO,SAASC,oBAAoB,CAACC,IAAY,EAAEC,OAAO,EAAmB;EAC3E,MAAMC,SAAS,GAAGJ,SAAS,CAACK,aAAa,CAACH,IAAI,EAAEC,OAAO,CAAC;EACxD,MAAMG,eAAoB,GACxBF,SAAS,CAACG,mBAAmB,IAAIH,SAAS,CAACI,gBAAgB,IAAIJ,SAAS;EAC1E,OAAOK,mBAAmB,CAACH,eAAe,CAAC;AAC7C;;AAGA,SAASG,mBAAmB,CAACC,GAAQ,EAAmB;EAAA;EACtD,MAAMC,YAA6B,GAAG;IACpCC,IAAI,EAAE,iBAAAF,GAAG,CAACG,OAAO,iDAAX,aAAaC,IAAI,KAAI,SAAS;IACpCC,KAAK,mBAAEL,GAAG,CAACG,OAAO,kDAAX,cAAaG,KAAK;IACzBC,QAAQ,EAAE,EAAE;IACZC,QAAQ,EAAE,CAAC,CAAC;IACZC,KAAK,EAAEC,YAAY,oBAACV,GAAG,CAACW,UAAU,oDAAd,gBAAgBC,KAAK,CAAC;IAC1CC,GAAG,EAAEb;EACP,CAAC;EAED,KAAK,MAAMc,OAAO,IAAI,kBAAAd,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