@tmcw/togeojson 5.8.1 → 6.0.0

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Convert KML, GPX, and TCX to GeoJSON.
2
2
 
3
+ [![NPM Version](https://img.shields.io/npm/v/%40tmcw%2Ftogeojson)](https://www.npmjs.com/package/@tmcw/togeojson)
4
+
3
5
  _togeojson development is supported by 🌎 [placemark.io](https://placemark.io/)_
4
6
 
5
7
  This converts [KML](https://developers.google.com/kml/documentation/), [TCX](https://en.wikipedia.org/wiki/Training_Center_XML), & [GPX](http://www.topografix.com/gpx.asp)
package/dist/index.d.ts CHANGED
@@ -31,7 +31,7 @@ declare function tcxGen(node: Document): Generator<Feature>;
31
31
  */
32
32
  declare function tcx(node: Document): FeatureCollection;
33
33
 
34
- declare type F = Feature<Geometry | null>;
34
+ type F = Feature<Geometry | null>;
35
35
 
36
36
  /**
37
37
  * Options to customize KML output.
@@ -141,4 +141,4 @@ declare function kmlGen(node: Document, options?: KMLOptions): Generator<F>;
141
141
  */
142
142
  declare function kml(node: Document, options?: KMLOptions): FeatureCollection<Geometry | null>;
143
143
 
144
- export { F, Folder, KMLOptions, Root, gpx, gpxGen, kml, kmlGen, kmlWithFolders, tcx, tcxGen };
144
+ export { type F, type Folder, type KMLOptions, type Root, gpx, gpxGen, kml, kmlGen, kmlWithFolders, tcx, tcxGen };
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  function $(element, tagName) {
6
4
  return Array.from(element.getElementsByTagName(tagName));
7
5
  }
@@ -16,7 +14,7 @@ function $ns(element, tagName, ns) {
16
14
  */
17
15
  function nodeVal(node) {
18
16
  node?.normalize();
19
- return (node && node.textContent) || "";
17
+ return node?.textContent || "";
20
18
  }
21
19
  /**
22
20
  * Get one Y child of X, if any, otherwise null
@@ -46,16 +44,16 @@ function val1(node, tagName, callback) {
46
44
  return {};
47
45
  }
48
46
  function $num(node, tagName, callback) {
49
- const val = parseFloat(nodeVal(get1(node, tagName)));
50
- if (isNaN(val))
47
+ const val = Number.parseFloat(nodeVal(get1(node, tagName)));
48
+ if (Number.isNaN(val))
51
49
  return undefined;
52
50
  if (val && callback)
53
51
  return callback(val) || {};
54
52
  return {};
55
53
  }
56
54
  function num1(node, tagName, callback) {
57
- const val = parseFloat(nodeVal(get1(node, tagName)));
58
- if (isNaN(val))
55
+ const val = Number.parseFloat(nodeVal(get1(node, tagName)));
56
+ if (Number.isNaN(val))
59
57
  return undefined;
60
58
  if (callback)
61
59
  callback(val);
@@ -74,20 +72,6 @@ function isElement(node) {
74
72
  return node?.nodeType === 1;
75
73
  }
76
74
 
77
- function getLineStyle(node) {
78
- return get(node, "line", (lineStyle) => {
79
- const val = Object.assign({}, val1(lineStyle, "color", (color) => {
80
- return { stroke: `#${color}` };
81
- }), $num(lineStyle, "opacity", (opacity) => {
82
- return { "stroke-opacity": opacity };
83
- }), $num(lineStyle, "width", (width) => {
84
- // GPX width is in mm, convert to px with 96 px per inch
85
- return { "stroke-width": (width * 96) / 25.4 };
86
- }));
87
- return val;
88
- });
89
- }
90
-
91
75
  function getExtensions(node) {
92
76
  let values = [];
93
77
  if (node === null)
@@ -112,16 +96,16 @@ function abbreviateName(name) {
112
96
  return ["heart", "gpxtpx:hr", "hr"].includes(name) ? "heart" : name;
113
97
  }
114
98
  function parseNumeric(val) {
115
- const num = parseFloat(val);
116
- return isNaN(num) ? val : num;
99
+ const num = Number.parseFloat(val);
100
+ return Number.isNaN(num) ? val : num;
117
101
  }
118
102
 
119
103
  function coordPair$1(node) {
120
104
  const ll = [
121
- parseFloat(node.getAttribute("lon") || ""),
122
- parseFloat(node.getAttribute("lat") || ""),
105
+ Number.parseFloat(node.getAttribute("lon") || ""),
106
+ Number.parseFloat(node.getAttribute("lat") || ""),
123
107
  ];
124
- if (isNaN(ll[0]) || isNaN(ll[1])) {
108
+ if (Number.isNaN(ll[0]) || Number.isNaN(ll[1])) {
125
109
  return null;
126
110
  }
127
111
  num1(node, "ele", (val) => {
@@ -135,7 +119,21 @@ function coordPair$1(node) {
135
119
  };
136
120
  }
137
121
 
138
- function extractProperties(node) {
122
+ function getLineStyle(node) {
123
+ return get(node, "line", (lineStyle) => {
124
+ const val = Object.assign({}, val1(lineStyle, "color", (color) => {
125
+ return { stroke: `#${color}` };
126
+ }), $num(lineStyle, "opacity", (opacity) => {
127
+ return { "stroke-opacity": opacity };
128
+ }), $num(lineStyle, "width", (width) => {
129
+ // GPX width is in mm, convert to px with 96 px per inch
130
+ return { "stroke-width": (width * 96) / 25.4 };
131
+ }));
132
+ return val;
133
+ });
134
+ }
135
+
136
+ function extractProperties(ns, node) {
139
137
  const properties = getMulti(node, [
140
138
  "name",
141
139
  "cmt",
@@ -144,10 +142,9 @@ function extractProperties(node) {
144
142
  "time",
145
143
  "keywords",
146
144
  ]);
147
- const extensions = Array.from(node.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*"));
148
- for (const child of extensions) {
149
- if (child.parentNode?.parentNode === node) {
150
- properties[child.tagName.replace(":", "_")] = nodeVal(child);
145
+ for (const [n, url] of ns) {
146
+ for (const child of Array.from(node.getElementsByTagNameNS(url, "*"))) {
147
+ properties[child.tagName.replace(":", "_")] = nodeVal(child)?.trim();
151
148
  }
152
149
  }
153
150
  const links = $(node, "link");
@@ -174,7 +171,7 @@ function getPoints$1(node, pointname) {
174
171
  if (c.time)
175
172
  times.push(c.time);
176
173
  for (const [name, val] of c.extendedValues) {
177
- const plural = name === "heart" ? name : name.replace("gpxtpx:", "") + "s";
174
+ const plural = name === "heart" ? name : `${name.replace("gpxtpx:", "")}s`;
178
175
  if (!extendedValues[plural]) {
179
176
  extendedValues[plural] = Array(pts.length).fill(null);
180
177
  }
@@ -193,20 +190,20 @@ function getPoints$1(node, pointname) {
193
190
  * Extract a LineString geometry from a rte
194
191
  * element.
195
192
  */
196
- function getRoute(node) {
193
+ function getRoute(ns, node) {
197
194
  const line = getPoints$1(node, "rtept");
198
195
  if (!line)
199
196
  return;
200
197
  return {
201
198
  type: "Feature",
202
- properties: Object.assign({ _gpxType: "rte" }, extractProperties(node), getLineStyle(get1(node, "extensions"))),
199
+ properties: Object.assign({ _gpxType: "rte" }, extractProperties(ns, node), getLineStyle(get1(node, "extensions"))),
203
200
  geometry: {
204
201
  type: "LineString",
205
202
  coordinates: line.line,
206
203
  },
207
204
  };
208
205
  }
209
- function getTrack(node) {
206
+ function getTrack(ns, node) {
210
207
  const segments = $(node, "trkseg");
211
208
  const track = [];
212
209
  const times = [];
@@ -215,14 +212,14 @@ function getTrack(node) {
215
212
  const line = getPoints$1(segment, "trkpt");
216
213
  if (line) {
217
214
  extractedLines.push(line);
218
- if (line.times && line.times.length)
215
+ if (line.times?.length)
219
216
  times.push(line.times);
220
217
  }
221
218
  }
222
219
  if (extractedLines.length === 0)
223
220
  return null;
224
221
  const multi = extractedLines.length > 1;
225
- const properties = Object.assign({ _gpxType: "trk" }, extractProperties(node), getLineStyle(get1(node, "extensions")), times.length
222
+ const properties = Object.assign({ _gpxType: "trk" }, extractProperties(ns, node), getLineStyle(get1(node, "extensions")), times.length
226
223
  ? {
227
224
  coordinateProperties: {
228
225
  times: multi ? times : times[0],
@@ -267,8 +264,8 @@ function getTrack(node) {
267
264
  * Extract a point, if possible, from a given node,
268
265
  * which is usually a wpt or trkpt
269
266
  */
270
- function getPoint(node) {
271
- const properties = Object.assign(extractProperties(node), getMulti(node, ["sym"]));
267
+ function getPoint(ns, node) {
268
+ const properties = Object.assign(extractProperties(ns, node), getMulti(node, ["sym"]));
272
269
  const pair = coordPair$1(node);
273
270
  if (!pair)
274
271
  return null;
@@ -287,18 +284,30 @@ function getPoint(node) {
287
284
  * that yields output feature by feature.
288
285
  */
289
286
  function* gpxGen(node) {
287
+ const GPXX = "gpxx";
288
+ const GPXX_URI = "http://www.garmin.com/xmlschemas/GpxExtensions/v3";
289
+ // Namespaces
290
+ const ns = [[GPXX, GPXX_URI]];
291
+ const attrs = node.getElementsByTagName("gpx")[0]?.attributes;
292
+ if (attrs) {
293
+ for (const attr of Array.from(attrs)) {
294
+ if (attr.name?.startsWith("xmlns:") && attr.value !== GPXX_URI) {
295
+ ns.push([attr.name, attr.value]);
296
+ }
297
+ }
298
+ }
290
299
  for (const track of $(node, "trk")) {
291
- const feature = getTrack(track);
300
+ const feature = getTrack(ns, track);
292
301
  if (feature)
293
302
  yield feature;
294
303
  }
295
304
  for (const route of $(node, "rte")) {
296
- const feature = getRoute(route);
305
+ const feature = getRoute(ns, route);
297
306
  if (feature)
298
307
  yield feature;
299
308
  }
300
309
  for (const waypoint of $(node, "wpt")) {
301
- const point = getPoint(waypoint);
310
+ const point = getPoint(ns, waypoint);
302
311
  if (point)
303
312
  yield point;
304
313
  }
@@ -350,8 +359,8 @@ function getProperties(node, attributeNames) {
350
359
  elem = elements[0];
351
360
  }
352
361
  }
353
- const val = parseFloat(nodeVal(elem));
354
- if (!isNaN(val)) {
362
+ const val = Number.parseFloat(nodeVal(elem));
363
+ if (!Number.isNaN(val)) {
355
364
  properties.push([alias, val]);
356
365
  }
357
366
  }
@@ -360,23 +369,23 @@ function getProperties(node, attributeNames) {
360
369
  function coordPair(node) {
361
370
  const ll = [num1(node, "LongitudeDegrees"), num1(node, "LatitudeDegrees")];
362
371
  if (ll[0] === undefined ||
363
- isNaN(ll[0]) ||
372
+ Number.isNaN(ll[0]) ||
364
373
  ll[1] === undefined ||
365
- isNaN(ll[1])) {
374
+ Number.isNaN(ll[1])) {
366
375
  return null;
367
376
  }
368
377
  const heartRate = get1(node, "HeartRateBpm");
369
378
  const time = nodeVal(get1(node, "Time"));
370
379
  get1(node, "AltitudeMeters", (alt) => {
371
- const a = parseFloat(nodeVal(alt));
372
- if (!isNaN(a)) {
380
+ const a = Number.parseFloat(nodeVal(alt));
381
+ if (!Number.isNaN(a)) {
373
382
  ll.push(a);
374
383
  }
375
384
  });
376
385
  return {
377
386
  coordinates: ll,
378
387
  time: time || null,
379
- heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
388
+ heartRate: heartRate ? Number.parseFloat(nodeVal(heartRate)) : null,
380
389
  extensions: getProperties(node, TRACKPOINT_ATTRIBUTES),
381
390
  };
382
391
  }
@@ -508,17 +517,18 @@ function tcx(node) {
508
517
 
509
518
  function fixColor(v, prefix) {
510
519
  const properties = {};
511
- const colorProp = prefix == "stroke" || prefix === "fill" ? prefix : prefix + "-color";
520
+ const colorProp = prefix === "stroke" || prefix === "fill" ? prefix : `${prefix}-color`;
512
521
  if (v[0] === "#") {
513
522
  v = v.substring(1);
514
523
  }
515
524
  if (v.length === 6 || v.length === 3) {
516
- properties[colorProp] = "#" + v;
525
+ properties[colorProp] = `#${v}`;
517
526
  }
518
527
  else if (v.length === 8) {
519
- properties[prefix + "-opacity"] = parseInt(v.substring(0, 2), 16) / 255;
528
+ properties[`${prefix}-opacity`] =
529
+ Number.parseInt(v.substring(0, 2), 16) / 255;
520
530
  properties[colorProp] =
521
- "#" + v.substring(6, 8) + v.substring(4, 6) + v.substring(2, 4);
531
+ `#${v.substring(6, 8)}${v.substring(4, 6)}${v.substring(2, 4)}`;
522
532
  }
523
533
  return properties;
524
534
  }
@@ -544,11 +554,11 @@ function extractIconHref(node) {
544
554
  function extractIcon(node) {
545
555
  return get(node, "IconStyle", (iconStyle) => {
546
556
  return Object.assign(getColor(iconStyle, "icon"), numericProperty(iconStyle, "scale", "icon-scale"), numericProperty(iconStyle, "heading", "icon-heading"), get(iconStyle, "hotSpot", (hotspot) => {
547
- const left = parseFloat(hotspot.getAttribute("x") || "");
548
- const top = parseFloat(hotspot.getAttribute("y") || "");
557
+ const left = Number.parseFloat(hotspot.getAttribute("x") || "");
558
+ const top = Number.parseFloat(hotspot.getAttribute("y") || "");
549
559
  const xunits = hotspot.getAttribute("xunits") || "";
550
560
  const yunits = hotspot.getAttribute("yunits") || "";
551
- if (!isNaN(left) && !isNaN(top))
561
+ if (!Number.isNaN(left) && !Number.isNaN(top))
552
562
  return {
553
563
  "icon-offset": [left, top],
554
564
  "icon-offset-units": [xunits, yunits],
@@ -582,71 +592,6 @@ function extractStyle(node) {
582
592
  return Object.assign({}, extractPoly(node), extractLine(node), extractLabel(node), extractIcon(node));
583
593
  }
584
594
 
585
- const toNumber = (x) => Number(x);
586
- const typeConverters = {
587
- string: (x) => x,
588
- int: toNumber,
589
- uint: toNumber,
590
- short: toNumber,
591
- ushort: toNumber,
592
- float: toNumber,
593
- double: toNumber,
594
- bool: (x) => Boolean(x),
595
- };
596
- function extractExtendedData(node, schema) {
597
- return get(node, "ExtendedData", (extendedData, properties) => {
598
- for (const data of $(extendedData, "Data")) {
599
- properties[data.getAttribute("name") || ""] = nodeVal(get1(data, "value"));
600
- }
601
- for (const simpleData of $(extendedData, "SimpleData")) {
602
- const name = simpleData.getAttribute("name") || "";
603
- const typeConverter = schema[name] || typeConverters.string;
604
- properties[name] = typeConverter(nodeVal(simpleData));
605
- }
606
- return properties;
607
- });
608
- }
609
- function getMaybeHTMLDescription(node) {
610
- const descriptionNode = get1(node, "description");
611
- for (const c of Array.from(descriptionNode?.childNodes || [])) {
612
- if (c.nodeType === 4) {
613
- return {
614
- description: {
615
- "@type": "html",
616
- value: nodeVal(c),
617
- },
618
- };
619
- }
620
- }
621
- return {};
622
- }
623
- function extractTimeSpan(node) {
624
- return get(node, "TimeSpan", (timeSpan) => {
625
- return {
626
- timespan: {
627
- begin: nodeVal(get1(timeSpan, "begin")),
628
- end: nodeVal(get1(timeSpan, "end")),
629
- },
630
- };
631
- });
632
- }
633
- function extractTimeStamp(node) {
634
- return get(node, "TimeStamp", (timeStamp) => {
635
- return { timestamp: nodeVal(get1(timeStamp, "when")) };
636
- });
637
- }
638
- function extractCascadedStyle(node, styleMap) {
639
- return val1(node, "styleUrl", (styleUrl) => {
640
- styleUrl = normalizeId(styleUrl);
641
- if (styleMap[styleUrl]) {
642
- return Object.assign({ styleUrl }, styleMap[styleUrl]);
643
- }
644
- // For backward-compatibility. Should we still include
645
- // styleUrl even if it's not resolved?
646
- return { styleUrl };
647
- });
648
- }
649
-
650
595
  const removeSpace = /\s*/g;
651
596
  const trimSpace = /^\s*|\s*$/g;
652
597
  const splitSpace = /\s+/;
@@ -657,8 +602,8 @@ function coord1(value) {
657
602
  return value
658
603
  .replace(removeSpace, "")
659
604
  .split(",")
660
- .map(parseFloat)
661
- .filter((num) => !isNaN(num))
605
+ .map(Number.parseFloat)
606
+ .filter((num) => !Number.isNaN(num))
662
607
  .slice(0, 3);
663
608
  }
664
609
  /**
@@ -679,7 +624,7 @@ function gxCoords(node) {
679
624
  elems = $ns(node, "coord", "*");
680
625
  }
681
626
  const coordinates = elems.map((elem) => {
682
- return nodeVal(elem).split(" ").map(parseFloat);
627
+ return nodeVal(elem).split(" ").map(Number.parseFloat);
683
628
  });
684
629
  if (coordinates.length === 0) {
685
630
  return null;
@@ -789,47 +734,69 @@ function getGeometry(node) {
789
734
  };
790
735
  }
791
736
 
792
- function geometryListToGeometry(geometries) {
793
- return geometries.length === 0
794
- ? null
795
- : geometries.length === 1
796
- ? geometries[0]
797
- : {
798
- type: "GeometryCollection",
799
- geometries,
800
- };
737
+ const toNumber = (x) => Number(x);
738
+ const typeConverters = {
739
+ string: (x) => x,
740
+ int: toNumber,
741
+ uint: toNumber,
742
+ short: toNumber,
743
+ ushort: toNumber,
744
+ float: toNumber,
745
+ double: toNumber,
746
+ bool: (x) => Boolean(x),
747
+ };
748
+ function extractExtendedData(node, schema) {
749
+ return get(node, "ExtendedData", (extendedData, properties) => {
750
+ for (const data of $(extendedData, "Data")) {
751
+ properties[data.getAttribute("name") || ""] = nodeVal(get1(data, "value"));
752
+ }
753
+ for (const simpleData of $(extendedData, "SimpleData")) {
754
+ const name = simpleData.getAttribute("name") || "";
755
+ const typeConverter = schema[name] || typeConverters.string;
756
+ properties[name] = typeConverter(nodeVal(simpleData));
757
+ }
758
+ return properties;
759
+ });
801
760
  }
802
- function getPlacemark(node, styleMap, schema, options) {
803
- const { coordTimes, geometries } = getGeometry(node);
804
- const geometry = geometryListToGeometry(geometries);
805
- if (!geometry && options.skipNullGeometry) {
806
- return null;
807
- }
808
- const feature = {
809
- type: "Feature",
810
- geometry,
811
- properties: Object.assign(getMulti(node, [
812
- "name",
813
- "address",
814
- "visibility",
815
- "open",
816
- "phoneNumber",
817
- "description",
818
- ]), getMaybeHTMLDescription(node), extractCascadedStyle(node, styleMap), extractStyle(node), extractExtendedData(node, schema), extractTimeSpan(node), extractTimeStamp(node), coordTimes.length
819
- ? {
820
- coordinateProperties: {
821
- times: coordTimes.length === 1 ? coordTimes[0] : coordTimes,
761
+ function getMaybeHTMLDescription(node) {
762
+ const descriptionNode = get1(node, "description");
763
+ for (const c of Array.from(descriptionNode?.childNodes || [])) {
764
+ if (c.nodeType === 4) {
765
+ return {
766
+ description: {
767
+ "@type": "html",
768
+ value: nodeVal(c),
822
769
  },
823
- }
824
- : {}),
825
- };
826
- if (feature.properties?.visibility !== undefined) {
827
- feature.properties.visibility = feature.properties.visibility !== "0";
770
+ };
771
+ }
828
772
  }
829
- const id = node.getAttribute("id");
830
- if (id !== null && id !== "")
831
- feature.id = id;
832
- return feature;
773
+ return {};
774
+ }
775
+ function extractTimeSpan(node) {
776
+ return get(node, "TimeSpan", (timeSpan) => {
777
+ return {
778
+ timespan: {
779
+ begin: nodeVal(get1(timeSpan, "begin")),
780
+ end: nodeVal(get1(timeSpan, "end")),
781
+ },
782
+ };
783
+ });
784
+ }
785
+ function extractTimeStamp(node) {
786
+ return get(node, "TimeStamp", (timeStamp) => {
787
+ return { timestamp: nodeVal(get1(timeStamp, "when")) };
788
+ });
789
+ }
790
+ function extractCascadedStyle(node, styleMap) {
791
+ return val1(node, "styleUrl", (styleUrl) => {
792
+ styleUrl = normalizeId(styleUrl);
793
+ if (styleMap[styleUrl]) {
794
+ return Object.assign({ styleUrl }, styleMap[styleUrl]);
795
+ }
796
+ // For backward-compatibility. Should we still include
797
+ // styleUrl even if it's not resolved?
798
+ return { styleUrl };
799
+ });
833
800
  }
834
801
 
835
802
  function getGroundOverlayBox(node) {
@@ -852,7 +819,7 @@ function rotateBox(bbox, coordinates, rotation) {
852
819
  coordinates[0].map((coordinate) => {
853
820
  const dy = coordinate[1] - center[1];
854
821
  const dx = coordinate[0] - center[0];
855
- const distance = Math.sqrt(Math.pow(dy, 2) + Math.pow(dx, 2));
822
+ const distance = Math.sqrt(dy ** 2 + dx ** 2);
856
823
  const angle = Math.atan2(dy, dx) + rotation * DEGREES_TO_RADIANS;
857
824
  return [
858
825
  center[0] + Math.cos(angle) * distance,
@@ -876,10 +843,10 @@ function getLatLonBox(node) {
876
843
  const bbox = [west, south, east, north];
877
844
  let coordinates = [
878
845
  [
879
- [west, north],
880
- [east, north],
881
- [east, south],
882
- [west, south],
846
+ [west, north], // top left
847
+ [east, north], // top right
848
+ [east, south], // top right
849
+ [west, south], // bottom left
883
850
  [west, north], // top left (again)
884
851
  ],
885
852
  ];
@@ -932,6 +899,49 @@ function getGroundOverlay(node, styleMap, schema, options) {
932
899
  return feature;
933
900
  }
934
901
 
902
+ function geometryListToGeometry(geometries) {
903
+ return geometries.length === 0
904
+ ? null
905
+ : geometries.length === 1
906
+ ? geometries[0]
907
+ : {
908
+ type: "GeometryCollection",
909
+ geometries,
910
+ };
911
+ }
912
+ function getPlacemark(node, styleMap, schema, options) {
913
+ const { coordTimes, geometries } = getGeometry(node);
914
+ const geometry = geometryListToGeometry(geometries);
915
+ if (!geometry && options.skipNullGeometry) {
916
+ return null;
917
+ }
918
+ const feature = {
919
+ type: "Feature",
920
+ geometry,
921
+ properties: Object.assign(getMulti(node, [
922
+ "name",
923
+ "address",
924
+ "visibility",
925
+ "open",
926
+ "phoneNumber",
927
+ "description",
928
+ ]), getMaybeHTMLDescription(node), extractCascadedStyle(node, styleMap), extractStyle(node), extractExtendedData(node, schema), extractTimeSpan(node), extractTimeStamp(node), coordTimes.length
929
+ ? {
930
+ coordinateProperties: {
931
+ times: coordTimes.length === 1 ? coordTimes[0] : coordTimes,
932
+ },
933
+ }
934
+ : {}),
935
+ };
936
+ if (feature.properties?.visibility !== undefined) {
937
+ feature.properties.visibility = feature.properties.visibility !== "0";
938
+ }
939
+ const id = node.getAttribute("id");
940
+ if (id !== null && id !== "")
941
+ feature.id = id;
942
+ return feature;
943
+ }
944
+
935
945
  function getStyleId(style) {
936
946
  let id = style.getAttribute("id");
937
947
  const parentNode = style.parentNode;
@@ -962,8 +972,7 @@ function buildSchema(node) {
962
972
  const schema = {};
963
973
  for (const field of $(node, "SimpleField")) {
964
974
  schema[field.getAttribute("name") || ""] =
965
- typeConverters[field.getAttribute("type") || ""] ||
966
- typeConverters["string"];
975
+ typeConverters[field.getAttribute("type") || ""] || typeConverters.string;
967
976
  }
968
977
  return schema;
969
978
  }