@loaders.gl/wms 4.2.0-alpha.4 → 4.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/csw-capabilities-loader.d.ts +1 -1
  2. package/dist/csw-capabilities-loader.d.ts.map +1 -1
  3. package/dist/csw-capabilities-loader.js +23 -15
  4. package/dist/csw-domain-loader.d.ts +1 -1
  5. package/dist/csw-domain-loader.d.ts.map +1 -1
  6. package/dist/csw-domain-loader.js +23 -15
  7. package/dist/csw-records-loader.d.ts +1 -1
  8. package/dist/csw-records-loader.d.ts.map +1 -1
  9. package/dist/csw-records-loader.js +23 -15
  10. package/dist/gml-loader.d.ts +1 -1
  11. package/dist/gml-loader.d.ts.map +1 -1
  12. package/dist/gml-loader.js +23 -15
  13. package/dist/index.cjs +49 -58
  14. package/dist/index.cjs.map +7 -0
  15. package/dist/index.d.ts +30 -30
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +8 -1
  18. package/dist/lib/parsers/csw/parse-csw-capabilities.js +18 -13
  19. package/dist/lib/parsers/csw/parse-csw-domain.js +26 -18
  20. package/dist/lib/parsers/csw/parse-csw-records.js +47 -36
  21. package/dist/lib/parsers/csw/parse-exception-report.js +26 -8
  22. package/dist/lib/parsers/gml/deep-strict-equal.js +107 -39
  23. package/dist/lib/parsers/gml/parse-gml.js +299 -280
  24. package/dist/lib/parsers/wms/parse-wms-capabilities.js +207 -187
  25. package/dist/lib/parsers/wms/parse-wms-error.js +17 -6
  26. package/dist/lib/parsers/wms/parse-wms-features.js +20 -19
  27. package/dist/lib/parsers/wms/parse-wms-layer-description.js +10 -4
  28. package/dist/lib/parsers/xml/parse-xml-helpers.js +54 -45
  29. package/dist/lib/services/create-image-service.d.ts +1 -1
  30. package/dist/lib/services/create-image-service.d.ts.map +1 -1
  31. package/dist/lib/services/create-image-service.js +31 -19
  32. package/dist/lib/services/image-service.js +39 -32
  33. package/dist/services/arcgis/arcgis-image-service.d.ts +2 -2
  34. package/dist/services/arcgis/arcgis-image-service.d.ts.map +1 -1
  35. package/dist/services/arcgis/arcgis-image-service.js +91 -55
  36. package/dist/services/arcgis/arcgis-server.js +35 -28
  37. package/dist/services/create-image-source.d.ts +3 -3
  38. package/dist/services/create-image-source.d.ts.map +1 -1
  39. package/dist/services/create-image-source.js +11 -2
  40. package/dist/services/ogc/csw-service.d.ts +3 -3
  41. package/dist/services/ogc/csw-service.d.ts.map +1 -1
  42. package/dist/services/ogc/csw-service.js +156 -142
  43. package/dist/services/ogc/wms-service.d.ts +4 -4
  44. package/dist/services/ogc/wms-service.d.ts.map +1 -1
  45. package/dist/services/ogc/wms-service.js +295 -242
  46. package/dist/wip/data-source.js +58 -1
  47. package/dist/wip/lib/wcs/parse-wcs-capabilities.js +8 -11
  48. package/dist/wip/lib/wfs/parse-wfs-capabilities.js +12 -12
  49. package/dist/wip/lib/wfs/parse-wfs.js +20 -20
  50. package/dist/wip/lib/wmts/parse-wmts-capabilities.js +70 -12
  51. package/dist/wip/lib/wmts/parse-wmts.js +23 -20
  52. package/dist/wip/services/arcgis-feature-service.js +22 -22
  53. package/dist/wip/wcs-capabilities-loader.d.ts +1 -1
  54. package/dist/wip/wcs-capabilities-loader.d.ts.map +1 -1
  55. package/dist/wip/wcs-capabilities-loader.js +21 -15
  56. package/dist/wip/wfs-capabilities-loader.d.ts +1 -1
  57. package/dist/wip/wfs-capabilities-loader.d.ts.map +1 -1
  58. package/dist/wip/wfs-capabilities-loader.js +21 -15
  59. package/dist/wip/wms-feature-info-loader.d.ts +1 -1
  60. package/dist/wip/wms-feature-info-loader.d.ts.map +1 -1
  61. package/dist/wip/wms-feature-info-loader.js +10 -6
  62. package/dist/wip/wms-layer-description-loader.d.ts +1 -1
  63. package/dist/wip/wms-layer-description-loader.d.ts.map +1 -1
  64. package/dist/wip/wms-layer-description-loader.js +9 -6
  65. package/dist/wip/wmts-capabilities-loader.js +22 -15
  66. package/dist/wms-capabilities-loader.d.ts +2 -2
  67. package/dist/wms-capabilities-loader.d.ts.map +1 -1
  68. package/dist/wms-capabilities-loader.js +27 -15
  69. package/dist/wms-error-loader.js +33 -28
  70. package/package.json +10 -8
  71. package/dist/csw-capabilities-loader.js.map +0 -1
  72. package/dist/csw-domain-loader.js.map +0 -1
  73. package/dist/csw-records-loader.js.map +0 -1
  74. package/dist/gml-loader.js.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/lib/parsers/csw/parse-csw-capabilities.js.map +0 -1
  77. package/dist/lib/parsers/csw/parse-csw-domain.js.map +0 -1
  78. package/dist/lib/parsers/csw/parse-csw-records.js.map +0 -1
  79. package/dist/lib/parsers/csw/parse-exception-report.js.map +0 -1
  80. package/dist/lib/parsers/gml/deep-strict-equal.js.map +0 -1
  81. package/dist/lib/parsers/gml/parse-gml.js.map +0 -1
  82. package/dist/lib/parsers/wms/parse-wms-capabilities.js.map +0 -1
  83. package/dist/lib/parsers/wms/parse-wms-error.js.map +0 -1
  84. package/dist/lib/parsers/wms/parse-wms-features.js.map +0 -1
  85. package/dist/lib/parsers/wms/parse-wms-layer-description.js.map +0 -1
  86. package/dist/lib/parsers/xml/parse-xml-helpers.js.map +0 -1
  87. package/dist/lib/services/create-image-service.js.map +0 -1
  88. package/dist/lib/services/image-service.js.map +0 -1
  89. package/dist/services/arcgis/arcgis-image-service.js.map +0 -1
  90. package/dist/services/arcgis/arcgis-server.js.map +0 -1
  91. package/dist/services/create-image-source.js.map +0 -1
  92. package/dist/services/ogc/csw-service.js.map +0 -1
  93. package/dist/services/ogc/wms-service.js.map +0 -1
  94. package/dist/wip/data-source.js.map +0 -1
  95. package/dist/wip/lib/wcs/parse-wcs-capabilities.js.map +0 -1
  96. package/dist/wip/lib/wfs/parse-wfs-capabilities.js.map +0 -1
  97. package/dist/wip/lib/wfs/parse-wfs.js.map +0 -1
  98. package/dist/wip/lib/wmts/parse-wmts-capabilities.js.map +0 -1
  99. package/dist/wip/lib/wmts/parse-wmts.js.map +0 -1
  100. package/dist/wip/services/arcgis-feature-service.js.map +0 -1
  101. package/dist/wip/services/wmts-service.ts.disabled +0 -348
  102. package/dist/wip/wcs-capabilities-loader.js.map +0 -1
  103. package/dist/wip/wfs-capabilities-loader.js.map +0 -1
  104. package/dist/wip/wms-feature-info-loader.js.map +0 -1
  105. package/dist/wip/wms-layer-description-loader.js.map +0 -1
  106. package/dist/wip/wms-layer-description-loader.md.disabled.md +0 -47
  107. package/dist/wip/wmts-capabilities-loader.js.map +0 -1
  108. package/dist/wms-capabilities-loader.js.map +0 -1
  109. 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
- for (var _len = arguments.length, coords = new Array(_len), _key = 0; _key < _len; _key++) {
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
- var _XMLLoader$parseTextS;
12
- const parsedXML = (_XMLLoader$parseTextS = XMLLoader.parseTextSync) === null || _XMLLoader$parseTextS === void 0 ? void 0 : _XMLLoader$parseTextS.call(XMLLoader, text, options);
13
- options = {
14
- transformCoords: noTransform,
15
- stride: 2,
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
- const childContext = createChildContext(inputXML, options, context);
23
- let geometry = null;
24
- const [name, xml] = getFirstKeyValue(inputXML);
25
- switch (name) {
26
- case 'gml:LineString':
27
- geometry = {
28
- type: 'LineString',
29
- coordinates: parseLinearRingOrLineString(xml, options, childContext)
30
- };
31
- break;
32
- case 'gml:Polygon':
33
- case 'gml:Rectangle':
34
- geometry = {
35
- type: 'Polygon',
36
- coordinates: parsePolygonOrRectangle(xml, options, childContext)
37
- };
38
- break;
39
- case 'gml:Surface':
40
- geometry = {
41
- type: 'MultiPolygon',
42
- coordinates: parseSurface(xml, options, childContext)
43
- };
44
- break;
45
- case 'gml:MultiSurface':
46
- geometry = {
47
- type: 'MultiPolygon',
48
- coordinates: parseMultiSurface(xml, options, childContext)
49
- };
50
- break;
51
- default:
52
- return null;
53
- }
54
- return rewind(geometry, {
55
- mutate: true
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
- const stride = context.srsDimension || options.stride || 2;
60
- const coords = s.replace(/\s+/g, ' ').trim().split(' ');
61
- if (coords.length === 0 || coords.length % stride !== 0) {
62
- throw new Error(`invalid coordinates list (stride ${stride})`);
63
- }
64
- const points = [];
65
- for (let i = 0; i < coords.length - 1; i += stride) {
66
- var _options$transformCoo;
67
- const point = coords.slice(i, i + stride).map(parseFloat);
68
- points.push(((_options$transformCoo = options.transformCoords) === null || _options$transformCoo === void 0 ? void 0 : _options$transformCoo.call(options, ...point)) || point);
69
- }
70
- return points;
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
- const childContext = createChildContext(xml, options, context);
74
- const coords = textOf(xml);
75
- if (!coords) {
76
- throw new Error('invalid gml:posList element');
77
- }
78
- return parseCoords(coords, options, childContext);
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
- const childContext = createChildContext(xml, options, context);
82
- const coords = textOf(xml);
83
- if (!coords) {
84
- throw new Error('invalid gml:pos element');
85
- }
86
- const points = parseCoords(coords, options, childContext);
87
- if (points.length !== 1) {
88
- throw new Error('gml:pos must have 1 point');
89
- }
90
- return points[0];
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
- const childContext = createChildContext(xml, options, context);
94
- const pos = findIn(xml, 'gml:pos');
95
- if (!pos) {
96
- throw new Error('invalid gml:Point element, expected a gml:pos subelement');
97
- }
98
- return parsePos(pos, options, childContext);
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
- const childContext = createChildContext(xml, options, context);
102
- let points = [];
103
- const posList = findIn(xml, 'gml:posList');
104
- if (posList) {
105
- points = parsePosList(posList, options, childContext);
106
- } else {
107
- for (const [childName, childXML] of Object.entries(xml)) {
108
- switch (childName) {
109
- case 'gml:Point':
110
- points.push(parsePoint(childXML, options, childContext));
111
- break;
112
- case 'gml:pos':
113
- points.push(parsePos(childXML, options, childContext));
114
- break;
115
- default:
116
- continue;
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
- if (points.length === 0) {
121
- throw new Error(`${xml.name} must have > 0 points`);
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
- const points = [];
127
- for (const [childName, childXML] of Object.entries(xml)) {
128
- switch (childName) {
129
- case 'gml:LineStringSegment':
130
- const points2 = parseLinearRingOrLineString(childXML, options, context);
131
- const end = points[points.length - 1];
132
- const start = points2[0];
133
- if (end && start && deepStrictEqual(end, start)) {
134
- points2.shift();
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
- if (points.length === 0) {
143
- throw new Error('gml:Curve > gml:segments must have > 0 points');
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
- const childContext = createChildContext(xml, options, context);
149
- const points = [];
150
- for (const [childName, childXML] of Object.entries(xml)) {
151
- switch (childName) {
152
- case 'gml:curveMember':
153
- let points2;
154
- const lineString = findIn(childXML, 'gml:LineString');
155
- if (lineString) {
156
- points2 = parseLinearRingOrLineString(lineString, options, childContext);
157
- } else {
158
- const segments = findIn(childXML, 'gml:Curve', 'gml:segments');
159
- if (!segments) {
160
- throw new Error(`invalid ${childName} element`);
161
- }
162
- points2 = parseCurveSegments(segments, options, childContext);
163
- }
164
- const end = points[points.length - 1];
165
- const start = points2[0];
166
- if (end && start && deepStrictEqual(end, start)) {
167
- points2.shift();
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
- if (points.length < 4) {
174
- throw new Error(`${xml.name} must have >= 4 points`);
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
- const linearRing = findIn(xml, 'gml:LinearRing');
180
- if (linearRing) {
181
- return parseLinearRingOrLineString(linearRing, options, context);
182
- }
183
- const ring = findIn(xml, 'gml:Ring');
184
- if (!ring) {
185
- throw new Error(`invalid ${xml.name} element`);
186
- }
187
- return parseRing(ring, options, context);
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
- const childContext = createChildContext(xml, options, context);
191
- const exterior = findIn(xml, 'gml:exterior');
192
- if (!exterior) {
193
- throw new Error(`invalid ${xml.name} element`);
194
- }
195
- const pointLists = [parseExteriorOrInterior(exterior, options, childContext)];
196
- for (const [childName, childXML] of Object.entries(xml)) {
197
- switch (childName) {
198
- case 'gml:interior':
199
- pointLists.push(parseExteriorOrInterior(childXML, options, childContext));
200
- break;
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
- const childContext = createChildContext(xml, options, context);
207
- const patches = findIn(xml, 'gml:patches');
208
- if (!patches) {
209
- throw new Error(`invalid ${xml.name} element`);
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
- if (polygons.length === 0) {
223
- throw new Error(`${xml.name} must have > 0 polygons`);
224
- }
225
- return polygons;
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
- const childContext = createChildContext(xml, options, context);
229
- const polygons = [];
230
- for (const [childName, childXML] of Object.entries(xml)) {
231
- switch (childName) {
232
- case 'gml:surfaceMember':
233
- case 'gml:surfaceMembers':
234
- const [c2Name, c2Xml] = getFirstKeyValue(childXML);
235
- switch (c2Name) {
236
- case 'gml:Surface':
237
- polygons.push(...parseSurface(c2Xml, options, childContext));
238
- break;
239
- case 'gml:Polygon':
240
- polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));
241
- break;
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
- if (polygons.length === 0) {
247
- throw new Error(`${xml.name} must have > 0 polygons`);
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
- let el = xml;
253
- const surfaceMembers = findIn(xml, 'gml:LinearRing');
254
- if (surfaceMembers) {
255
- el = surfaceMembers;
256
- }
257
- const polygons = [];
258
- for (const [childName, childXML] of Object.entries(el)) {
259
- switch (childName) {
260
- case 'gml:Surface':
261
- const polygons2 = parseSurface(childXML, options, context);
262
- polygons.push(...polygons2);
263
- break;
264
- case 'gml:surfaceMember':
265
- const polygons3 = parseSurfaceMember(childXML, options, context);
266
- polygons.push(...polygons3);
267
- break;
268
- case 'gml:surfaceMembers':
269
- const polygonXML = findIn(childXML, 'gml:Polygon');
270
- for (const surfaceMemberXML of polygonXML) {
271
- const polygons3 = parseSurfaceMember(surfaceMemberXML, options, context);
272
- polygons.push(...polygons3);
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
- if (polygons.length === 0) {
278
- throw new Error(`${xml.name} must have > 0 polygons`);
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
- const [childName, childXml] = getFirstKeyValue(xml);
284
- switch (childName) {
285
- case 'gml:CompositeSurface':
286
- return parseCompositeSurface(childXml, options, context);
287
- case 'gml:Surface':
288
- return parseSurface(childXml, options, context);
289
- case 'gml:Polygon':
290
- return [parsePolygonOrRectangle(childXml, options, context)];
291
- }
292
- throw new Error(`${childName} must have polygons`);
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
- if (typeof el !== 'string') {
296
- throw new Error('expected string');
297
- }
298
- return el;
316
+ if (typeof el !== 'string') {
317
+ throw new Error('expected string');
318
+ }
319
+ return el;
299
320
  }
300
- function findIn(root) {
301
- let el = root;
302
- for (var _len2 = arguments.length, tags = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
303
- tags[_key2 - 1] = arguments[_key2];
304
- }
305
- for (const tag of tags) {
306
- const child = el[tag];
307
- if (!child) {
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 = child;
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
- if (object && typeof object === 'object') {
316
- for (const [key, value] of Object.entries(object)) {
317
- return [key, value];
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
- const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;
324
- if (srsDimensionAttribute) {
325
- const srsDimension = parseInt(srsDimensionAttribute);
326
- if (Number.isNaN(srsDimension) || srsDimension <= 0) {
327
- throw new Error(`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`);
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
- const childContext = Object.create(context);
330
- childContext.srsDimension = srsDimension;
331
- return childContext;
332
- }
333
- return context;
353
+ return context;
334
354
  }
335
- //# sourceMappingURL=parse-gml.js.map