@loaders.gl/wms 4.2.0-alpha.3 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csw-capabilities-loader.d.ts +1 -1
- package/dist/csw-capabilities-loader.d.ts.map +1 -1
- package/dist/csw-capabilities-loader.js +24 -16
- package/dist/csw-domain-loader.d.ts +1 -1
- package/dist/csw-domain-loader.d.ts.map +1 -1
- package/dist/csw-domain-loader.js +24 -16
- package/dist/csw-records-loader.d.ts +1 -1
- package/dist/csw-records-loader.d.ts.map +1 -1
- package/dist/csw-records-loader.js +24 -16
- package/dist/gml-loader.d.ts +1 -1
- package/dist/gml-loader.d.ts.map +1 -1
- package/dist/gml-loader.js +24 -16
- package/dist/index.cjs +49 -58
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +30 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/lib/parsers/csw/parse-csw-capabilities.js +18 -13
- package/dist/lib/parsers/csw/parse-csw-domain.js +26 -18
- package/dist/lib/parsers/csw/parse-csw-records.js +47 -36
- package/dist/lib/parsers/csw/parse-exception-report.js +26 -8
- package/dist/lib/parsers/gml/deep-strict-equal.js +107 -39
- package/dist/lib/parsers/gml/parse-gml.js +299 -280
- package/dist/lib/parsers/wms/parse-wms-capabilities.js +207 -187
- package/dist/lib/parsers/wms/parse-wms-error.js +17 -6
- package/dist/lib/parsers/wms/parse-wms-features.js +20 -19
- package/dist/lib/parsers/wms/parse-wms-layer-description.js +10 -4
- package/dist/lib/parsers/xml/parse-xml-helpers.js +54 -45
- package/dist/lib/services/create-image-service.d.ts +1 -1
- package/dist/lib/services/create-image-service.d.ts.map +1 -1
- package/dist/lib/services/create-image-service.js +31 -19
- package/dist/lib/services/image-service.js +39 -32
- package/dist/services/arcgis/arcgis-image-service.d.ts +2 -2
- package/dist/services/arcgis/arcgis-image-service.d.ts.map +1 -1
- package/dist/services/arcgis/arcgis-image-service.js +91 -55
- package/dist/services/arcgis/arcgis-server.js +35 -28
- package/dist/services/create-image-source.d.ts +3 -3
- package/dist/services/create-image-source.d.ts.map +1 -1
- package/dist/services/create-image-source.js +11 -2
- package/dist/services/ogc/csw-service.d.ts +3 -3
- package/dist/services/ogc/csw-service.d.ts.map +1 -1
- package/dist/services/ogc/csw-service.js +156 -142
- package/dist/services/ogc/wms-service.d.ts +4 -4
- package/dist/services/ogc/wms-service.d.ts.map +1 -1
- package/dist/services/ogc/wms-service.js +295 -242
- package/dist/wip/data-source.js +58 -1
- package/dist/wip/lib/wcs/parse-wcs-capabilities.js +8 -11
- package/dist/wip/lib/wfs/parse-wfs-capabilities.js +12 -12
- package/dist/wip/lib/wfs/parse-wfs.js +20 -20
- package/dist/wip/lib/wmts/parse-wmts-capabilities.js +70 -12
- package/dist/wip/lib/wmts/parse-wmts.js +23 -20
- package/dist/wip/services/arcgis-feature-service.js +22 -22
- package/dist/wip/wcs-capabilities-loader.d.ts +1 -1
- package/dist/wip/wcs-capabilities-loader.d.ts.map +1 -1
- package/dist/wip/wcs-capabilities-loader.js +22 -16
- package/dist/wip/wfs-capabilities-loader.d.ts +1 -1
- package/dist/wip/wfs-capabilities-loader.d.ts.map +1 -1
- package/dist/wip/wfs-capabilities-loader.js +22 -16
- package/dist/wip/wms-feature-info-loader.d.ts +1 -1
- package/dist/wip/wms-feature-info-loader.d.ts.map +1 -1
- package/dist/wip/wms-feature-info-loader.js +10 -6
- package/dist/wip/wms-layer-description-loader.d.ts +1 -1
- package/dist/wip/wms-layer-description-loader.d.ts.map +1 -1
- package/dist/wip/wms-layer-description-loader.js +9 -6
- package/dist/wip/wmts-capabilities-loader.js +23 -16
- package/dist/wms-capabilities-loader.d.ts +2 -2
- package/dist/wms-capabilities-loader.d.ts.map +1 -1
- package/dist/wms-capabilities-loader.js +28 -16
- package/dist/wms-error-loader.js +34 -29
- package/package.json +10 -8
- package/dist/csw-capabilities-loader.js.map +0 -1
- package/dist/csw-domain-loader.js.map +0 -1
- package/dist/csw-records-loader.js.map +0 -1
- package/dist/gml-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-capabilities.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-domain.js.map +0 -1
- package/dist/lib/parsers/csw/parse-csw-records.js.map +0 -1
- package/dist/lib/parsers/csw/parse-exception-report.js.map +0 -1
- package/dist/lib/parsers/gml/deep-strict-equal.js.map +0 -1
- package/dist/lib/parsers/gml/parse-gml.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-capabilities.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-error.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-features.js.map +0 -1
- package/dist/lib/parsers/wms/parse-wms-layer-description.js.map +0 -1
- package/dist/lib/parsers/xml/parse-xml-helpers.js.map +0 -1
- package/dist/lib/services/create-image-service.js.map +0 -1
- package/dist/lib/services/image-service.js.map +0 -1
- package/dist/services/arcgis/arcgis-image-service.js.map +0 -1
- package/dist/services/arcgis/arcgis-server.js.map +0 -1
- package/dist/services/create-image-source.js.map +0 -1
- package/dist/services/ogc/csw-service.js.map +0 -1
- package/dist/services/ogc/wms-service.js.map +0 -1
- package/dist/wip/data-source.js.map +0 -1
- package/dist/wip/lib/wcs/parse-wcs-capabilities.js.map +0 -1
- package/dist/wip/lib/wfs/parse-wfs-capabilities.js.map +0 -1
- package/dist/wip/lib/wfs/parse-wfs.js.map +0 -1
- package/dist/wip/lib/wmts/parse-wmts-capabilities.js.map +0 -1
- package/dist/wip/lib/wmts/parse-wmts.js.map +0 -1
- package/dist/wip/services/arcgis-feature-service.js.map +0 -1
- package/dist/wip/services/wmts-service.ts.disabled +0 -348
- package/dist/wip/wcs-capabilities-loader.js.map +0 -1
- package/dist/wip/wfs-capabilities-loader.js.map +0 -1
- package/dist/wip/wms-feature-info-loader.js.map +0 -1
- package/dist/wip/wms-layer-description-loader.js.map +0 -1
- package/dist/wip/wms-layer-description-loader.md.disabled.md +0 -47
- package/dist/wip/wmts-capabilities-loader.js.map +0 -1
- package/dist/wms-capabilities-loader.js.map +0 -1
- package/dist/wms-error-loader.js.map +0 -1
|
@@ -1,335 +1,354 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { XMLLoader } from '@loaders.gl/xml';
|
|
2
5
|
import { deepStrictEqual } from "./deep-strict-equal.js";
|
|
3
6
|
import rewind from '@turf/rewind';
|
|
4
|
-
function noTransform() {
|
|
5
|
-
|
|
6
|
-
coords[_key] = arguments[_key];
|
|
7
|
-
}
|
|
8
|
-
return coords;
|
|
7
|
+
function noTransform(...coords) {
|
|
8
|
+
return coords;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Parses a typed data structure from raw XML for GML features
|
|
12
|
+
* @note Error handlings is fairly weak
|
|
13
|
+
*/
|
|
10
14
|
export function parseGML(text, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...options
|
|
17
|
-
};
|
|
18
|
-
const context = createChildContext(parsedXML, options, {});
|
|
19
|
-
return parseGMLToGeometry(parsedXML, options, context);
|
|
15
|
+
// GeoJSON | null {
|
|
16
|
+
const parsedXML = XMLLoader.parseTextSync?.(text, options);
|
|
17
|
+
options = { transformCoords: noTransform, stride: 2, ...options };
|
|
18
|
+
const context = createChildContext(parsedXML, options, {});
|
|
19
|
+
return parseGMLToGeometry(parsedXML, options, context);
|
|
20
20
|
}
|
|
21
|
+
/** Parse a GeoJSON geometry from GML XML */
|
|
21
22
|
export function parseGMLToGeometry(inputXML, options, context) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
type: '
|
|
29
|
-
coordinates:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
23
|
+
const childContext = createChildContext(inputXML, options, context);
|
|
24
|
+
let geometry = null;
|
|
25
|
+
const [name, xml] = getFirstKeyValue(inputXML);
|
|
26
|
+
switch (name) {
|
|
27
|
+
// case 'gml:MultiPoint':
|
|
28
|
+
// geometry = {
|
|
29
|
+
// type: 'MultiPoint',
|
|
30
|
+
// coordinates: parseMultiPoint(xml, options, childContext)
|
|
31
|
+
// };
|
|
32
|
+
// break;
|
|
33
|
+
case 'gml:LineString':
|
|
34
|
+
geometry = {
|
|
35
|
+
type: 'LineString',
|
|
36
|
+
coordinates: parseLinearRingOrLineString(xml, options, childContext)
|
|
37
|
+
};
|
|
38
|
+
break;
|
|
39
|
+
// case 'gml:MultiLineString':
|
|
40
|
+
// geometry = {
|
|
41
|
+
// type: 'MultiLineString',
|
|
42
|
+
// coordinates: parseMultiLineString(xml, options, childContext)
|
|
43
|
+
// };
|
|
44
|
+
// break;
|
|
45
|
+
case 'gml:Polygon':
|
|
46
|
+
case 'gml:Rectangle':
|
|
47
|
+
geometry = {
|
|
48
|
+
type: 'Polygon',
|
|
49
|
+
coordinates: parsePolygonOrRectangle(xml, options, childContext)
|
|
50
|
+
};
|
|
51
|
+
break;
|
|
52
|
+
case 'gml:Surface':
|
|
53
|
+
geometry = {
|
|
54
|
+
type: 'MultiPolygon',
|
|
55
|
+
coordinates: parseSurface(xml, options, childContext)
|
|
56
|
+
};
|
|
57
|
+
break;
|
|
58
|
+
case 'gml:MultiSurface':
|
|
59
|
+
geometry = {
|
|
60
|
+
type: 'MultiPolygon',
|
|
61
|
+
coordinates: parseMultiSurface(xml, options, childContext)
|
|
62
|
+
};
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
// todo
|
|
68
|
+
return rewind(geometry, { mutate: true });
|
|
57
69
|
}
|
|
70
|
+
/** Parse a list of coordinates from a string */
|
|
58
71
|
function parseCoords(s, options, context) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
const stride = context.srsDimension || options.stride || 2;
|
|
73
|
+
// Handle white space
|
|
74
|
+
const coords = s.replace(/\s+/g, ' ').trim().split(' ');
|
|
75
|
+
if (coords.length === 0 || coords.length % stride !== 0) {
|
|
76
|
+
throw new Error(`invalid coordinates list (stride ${stride})`);
|
|
77
|
+
}
|
|
78
|
+
const points = [];
|
|
79
|
+
for (let i = 0; i < coords.length - 1; i += stride) {
|
|
80
|
+
const point = coords.slice(i, i + stride).map(parseFloat);
|
|
81
|
+
points.push(options.transformCoords?.(...point) || point);
|
|
82
|
+
}
|
|
83
|
+
return points;
|
|
71
84
|
}
|
|
72
85
|
export function parsePosList(xml, options, context) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
const childContext = createChildContext(xml, options, context);
|
|
87
|
+
const coords = textOf(xml);
|
|
88
|
+
if (!coords) {
|
|
89
|
+
throw new Error('invalid gml:posList element');
|
|
90
|
+
}
|
|
91
|
+
return parseCoords(coords, options, childContext);
|
|
79
92
|
}
|
|
80
93
|
export function parsePos(xml, options, context) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
const childContext = createChildContext(xml, options, context);
|
|
95
|
+
const coords = textOf(xml);
|
|
96
|
+
if (!coords) {
|
|
97
|
+
throw new Error('invalid gml:pos element');
|
|
98
|
+
}
|
|
99
|
+
const points = parseCoords(coords, options, childContext);
|
|
100
|
+
if (points.length !== 1) {
|
|
101
|
+
throw new Error('gml:pos must have 1 point');
|
|
102
|
+
}
|
|
103
|
+
return points[0];
|
|
91
104
|
}
|
|
92
105
|
export function parsePoint(xml, options, context) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
const childContext = createChildContext(xml, options, context);
|
|
107
|
+
// TODO AV: Parse other gml:Point options
|
|
108
|
+
const pos = findIn(xml, 'gml:pos');
|
|
109
|
+
if (!pos) {
|
|
110
|
+
throw new Error('invalid gml:Point element, expected a gml:pos subelement');
|
|
111
|
+
}
|
|
112
|
+
return parsePos(pos, options, childContext);
|
|
99
113
|
}
|
|
100
114
|
export function parseLinearRingOrLineString(xml, options, context) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
// or a LineStringSegment
|
|
116
|
+
const childContext = createChildContext(xml, options, context);
|
|
117
|
+
let points = [];
|
|
118
|
+
const posList = findIn(xml, 'gml:posList');
|
|
119
|
+
if (posList) {
|
|
120
|
+
points = parsePosList(posList, options, childContext);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
124
|
+
switch (childName) {
|
|
125
|
+
case 'gml:Point':
|
|
126
|
+
points.push(parsePoint(childXML, options, childContext));
|
|
127
|
+
break;
|
|
128
|
+
case 'gml:pos':
|
|
129
|
+
points.push(parsePos(childXML, options, childContext));
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
118
135
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return points;
|
|
136
|
+
if (points.length === 0) {
|
|
137
|
+
throw new Error(`${xml.name} must have > 0 points`);
|
|
138
|
+
}
|
|
139
|
+
return points;
|
|
124
140
|
}
|
|
125
141
|
export function parseCurveSegments(xml, options, context) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
const points = [];
|
|
143
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
144
|
+
switch (childName) {
|
|
145
|
+
case 'gml:LineStringSegment':
|
|
146
|
+
const points2 = parseLinearRingOrLineString(childXML, options, context);
|
|
147
|
+
// remove overlapping
|
|
148
|
+
const end = points[points.length - 1];
|
|
149
|
+
const start = points2[0];
|
|
150
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
151
|
+
points2.shift();
|
|
152
|
+
}
|
|
153
|
+
points.push(...points2);
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
continue;
|
|
135
157
|
}
|
|
136
|
-
points.push(...points2);
|
|
137
|
-
break;
|
|
138
|
-
default:
|
|
139
|
-
continue;
|
|
140
158
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return points;
|
|
159
|
+
if (points.length === 0) {
|
|
160
|
+
throw new Error('gml:Curve > gml:segments must have > 0 points');
|
|
161
|
+
}
|
|
162
|
+
return points;
|
|
146
163
|
}
|
|
147
164
|
export function parseRing(xml, options, context) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
const childContext = createChildContext(xml, options, context);
|
|
166
|
+
const points = [];
|
|
167
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
168
|
+
switch (childName) {
|
|
169
|
+
case 'gml:curveMember':
|
|
170
|
+
let points2;
|
|
171
|
+
const lineString = findIn(childXML, 'gml:LineString');
|
|
172
|
+
if (lineString) {
|
|
173
|
+
points2 = parseLinearRingOrLineString(lineString, options, childContext);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const segments = findIn(childXML, 'gml:Curve', 'gml:segments');
|
|
177
|
+
if (!segments) {
|
|
178
|
+
throw new Error(`invalid ${childName} element`);
|
|
179
|
+
}
|
|
180
|
+
points2 = parseCurveSegments(segments, options, childContext);
|
|
181
|
+
}
|
|
182
|
+
// remove overlapping
|
|
183
|
+
const end = points[points.length - 1];
|
|
184
|
+
const start = points2[0];
|
|
185
|
+
if (end && start && deepStrictEqual(end, start)) {
|
|
186
|
+
points2.shift();
|
|
187
|
+
}
|
|
188
|
+
points.push(...points2);
|
|
189
|
+
break;
|
|
168
190
|
}
|
|
169
|
-
points.push(...points2);
|
|
170
|
-
break;
|
|
171
191
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return points;
|
|
192
|
+
if (points.length < 4) {
|
|
193
|
+
throw new Error(`${xml.name} must have >= 4 points`);
|
|
194
|
+
}
|
|
195
|
+
return points;
|
|
177
196
|
}
|
|
178
197
|
export function parseExteriorOrInterior(xml, options, context) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
const linearRing = findIn(xml, 'gml:LinearRing');
|
|
199
|
+
if (linearRing) {
|
|
200
|
+
return parseLinearRingOrLineString(linearRing, options, context);
|
|
201
|
+
}
|
|
202
|
+
const ring = findIn(xml, 'gml:Ring');
|
|
203
|
+
if (!ring) {
|
|
204
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
205
|
+
}
|
|
206
|
+
return parseRing(ring, options, context);
|
|
188
207
|
}
|
|
189
208
|
export function parsePolygonOrRectangle(xml, options, context) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
// or PolygonPatch
|
|
210
|
+
const childContext = createChildContext(xml, options, context);
|
|
211
|
+
const exterior = findIn(xml, 'gml:exterior');
|
|
212
|
+
if (!exterior) {
|
|
213
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
214
|
+
}
|
|
215
|
+
const pointLists = [parseExteriorOrInterior(exterior, options, childContext)];
|
|
216
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
217
|
+
switch (childName) {
|
|
218
|
+
case 'gml:interior':
|
|
219
|
+
pointLists.push(parseExteriorOrInterior(childXML, options, childContext));
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
201
222
|
}
|
|
202
|
-
|
|
203
|
-
return pointLists;
|
|
223
|
+
return pointLists;
|
|
204
224
|
}
|
|
205
225
|
export function parseSurface(xml, options, context) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
const polygons = [];
|
|
212
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
213
|
-
switch (childName) {
|
|
214
|
-
case 'gml:PolygonPatch':
|
|
215
|
-
case 'gml:Rectangle':
|
|
216
|
-
polygons.push(parsePolygonOrRectangle(childXML, options, childContext));
|
|
217
|
-
break;
|
|
218
|
-
default:
|
|
219
|
-
continue;
|
|
226
|
+
const childContext = createChildContext(xml, options, context);
|
|
227
|
+
const patches = findIn(xml, 'gml:patches');
|
|
228
|
+
if (!patches) {
|
|
229
|
+
throw new Error(`invalid ${xml.name} element`);
|
|
220
230
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
const polygons = [];
|
|
232
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
233
|
+
switch (childName) {
|
|
234
|
+
case 'gml:PolygonPatch':
|
|
235
|
+
case 'gml:Rectangle':
|
|
236
|
+
polygons.push(parsePolygonOrRectangle(childXML, options, childContext));
|
|
237
|
+
break;
|
|
238
|
+
default:
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (polygons.length === 0) {
|
|
243
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
244
|
+
}
|
|
245
|
+
return polygons;
|
|
226
246
|
}
|
|
227
247
|
export function parseCompositeSurface(xml, options, context) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
248
|
+
const childContext = createChildContext(xml, options, context);
|
|
249
|
+
const polygons = [];
|
|
250
|
+
for (const [childName, childXML] of Object.entries(xml)) {
|
|
251
|
+
switch (childName) {
|
|
252
|
+
case 'gml:surfaceMember':
|
|
253
|
+
case 'gml:surfaceMembers':
|
|
254
|
+
const [c2Name, c2Xml] = getFirstKeyValue(childXML);
|
|
255
|
+
switch (c2Name) {
|
|
256
|
+
case 'gml:Surface':
|
|
257
|
+
polygons.push(...parseSurface(c2Xml, options, childContext));
|
|
258
|
+
break;
|
|
259
|
+
case 'gml:Polygon':
|
|
260
|
+
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
242
264
|
}
|
|
243
|
-
break;
|
|
244
265
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return polygons;
|
|
266
|
+
if (polygons.length === 0) {
|
|
267
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
268
|
+
}
|
|
269
|
+
return polygons;
|
|
250
270
|
}
|
|
251
271
|
export function parseMultiSurface(xml, options, context) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
let el = xml;
|
|
273
|
+
const surfaceMembers = findIn(xml, 'gml:LinearRing');
|
|
274
|
+
if (surfaceMembers) {
|
|
275
|
+
el = surfaceMembers;
|
|
276
|
+
}
|
|
277
|
+
const polygons = [];
|
|
278
|
+
for (const [childName, childXML] of Object.entries(el)) {
|
|
279
|
+
switch (childName) {
|
|
280
|
+
case 'gml:Surface':
|
|
281
|
+
const polygons2 = parseSurface(childXML, options, context);
|
|
282
|
+
polygons.push(...polygons2);
|
|
283
|
+
break;
|
|
284
|
+
case 'gml:surfaceMember':
|
|
285
|
+
const polygons3 = parseSurfaceMember(childXML, options, context);
|
|
286
|
+
polygons.push(...polygons3);
|
|
287
|
+
break;
|
|
288
|
+
case 'gml:surfaceMembers':
|
|
289
|
+
const polygonXML = findIn(childXML, 'gml:Polygon');
|
|
290
|
+
for (const surfaceMemberXML of polygonXML) {
|
|
291
|
+
const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context);
|
|
292
|
+
polygons.push(...polygons3);
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
273
295
|
}
|
|
274
|
-
break;
|
|
275
296
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return polygons;
|
|
297
|
+
if (polygons.length === 0) {
|
|
298
|
+
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
299
|
+
}
|
|
300
|
+
return polygons;
|
|
281
301
|
}
|
|
282
302
|
function parseSurfaceMember(xml, options, context) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
303
|
+
const [childName, childXml] = getFirstKeyValue(xml);
|
|
304
|
+
switch (childName) {
|
|
305
|
+
case 'gml:CompositeSurface':
|
|
306
|
+
return parseCompositeSurface(childXml, options, context);
|
|
307
|
+
case 'gml:Surface':
|
|
308
|
+
return parseSurface(childXml, options, context);
|
|
309
|
+
case 'gml:Polygon':
|
|
310
|
+
return [parsePolygonOrRectangle(childXml, options, context)];
|
|
311
|
+
}
|
|
312
|
+
throw new Error(`${childName} must have polygons`);
|
|
293
313
|
}
|
|
314
|
+
// Helpers
|
|
294
315
|
function textOf(el) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
316
|
+
if (typeof el !== 'string') {
|
|
317
|
+
throw new Error('expected string');
|
|
318
|
+
}
|
|
319
|
+
return el;
|
|
299
320
|
}
|
|
300
|
-
function findIn(root) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return null;
|
|
321
|
+
function findIn(root, ...tags) {
|
|
322
|
+
let el = root;
|
|
323
|
+
for (const tag of tags) {
|
|
324
|
+
const child = el[tag];
|
|
325
|
+
if (!child) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
el = child;
|
|
309
329
|
}
|
|
310
|
-
el
|
|
311
|
-
}
|
|
312
|
-
return el;
|
|
330
|
+
return el;
|
|
313
331
|
}
|
|
332
|
+
/** @returns the first [key, value] pair in an object, or ['', null] if empty object */
|
|
314
333
|
function getFirstKeyValue(object) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
334
|
+
if (object && typeof object === 'object') {
|
|
335
|
+
for (const [key, value] of Object.entries(object)) {
|
|
336
|
+
return [key, value];
|
|
337
|
+
}
|
|
318
338
|
}
|
|
319
|
-
|
|
320
|
-
return ['', null];
|
|
339
|
+
return ['', null];
|
|
321
340
|
}
|
|
341
|
+
/** A bit heavyweight for just tracking dimension? */
|
|
322
342
|
function createChildContext(xml, options, context) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
343
|
+
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;
|
|
344
|
+
if (srsDimensionAttribute) {
|
|
345
|
+
const srsDimension = parseInt(srsDimensionAttribute);
|
|
346
|
+
if (Number.isNaN(srsDimension) || srsDimension <= 0) {
|
|
347
|
+
throw new Error(`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`);
|
|
348
|
+
}
|
|
349
|
+
const childContext = Object.create(context);
|
|
350
|
+
childContext.srsDimension = srsDimension;
|
|
351
|
+
return childContext;
|
|
328
352
|
}
|
|
329
|
-
|
|
330
|
-
childContext.srsDimension = srsDimension;
|
|
331
|
-
return childContext;
|
|
332
|
-
}
|
|
333
|
-
return context;
|
|
353
|
+
return context;
|
|
334
354
|
}
|
|
335
|
-
//# sourceMappingURL=parse-gml.js.map
|