@tak-ps/node-cot 14.58.1 → 14.60.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/.oxlintrc.json +100 -0
- package/CHANGELOG.md +9 -0
- package/README.md +13 -0
- package/cli.ts +21 -22
- package/dist/cli.js +18 -19
- package/dist/cli.js.map +1 -1
- package/dist/lib/builders/chat.d.ts +4 -4
- package/dist/lib/builders/chat.js +3 -6
- package/dist/lib/builders/chat.js.map +1 -1
- package/dist/lib/builders/route.js +2 -2
- package/dist/lib/cot.js +44 -56
- package/dist/lib/cot.js.map +1 -1
- package/dist/lib/data-package.d.ts +3 -3
- package/dist/lib/data-package.js +68 -81
- package/dist/lib/data-package.js.map +1 -1
- package/dist/lib/parser/from_geojson.js +27 -30
- package/dist/lib/parser/from_geojson.js.map +1 -1
- package/dist/lib/parser/normalize_geojson.js +22 -22
- package/dist/lib/parser/normalize_geojson.js.map +1 -1
- package/dist/lib/parser/to_geojson.js +97 -86
- package/dist/lib/parser/to_geojson.js.map +1 -1
- package/dist/lib/parser-normalize.d.ts +5 -0
- package/dist/lib/parser-normalize.js +25 -8
- package/dist/lib/parser-normalize.js.map +1 -1
- package/dist/lib/parser.js +96 -81
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/sensor.js +11 -5
- package/dist/lib/sensor.js.map +1 -1
- package/dist/lib/type.js +5 -10
- package/dist/lib/type.js.map +1 -1
- package/dist/lib/types/cot-types.js +4 -4
- package/dist/lib/types/cot-types.js.map +1 -1
- package/dist/lib/types/feature.d.ts +782 -752
- package/dist/lib/types/feature.js +2 -1
- package/dist/lib/types/feature.js.map +1 -1
- package/dist/lib/types/types.d.ts +81 -9
- package/dist/lib/types/types.js +33 -3
- package/dist/lib/types/types.js.map +1 -1
- package/dist/lib/utils/2525.js +139 -92
- package/dist/lib/utils/2525.js.map +1 -1
- package/dist/lib/utils/color.js +1 -1
- package/dist/lib/utils/color.js.map +1 -1
- package/dist/lib/utils/type.js +5 -10
- package/dist/lib/utils/type.js.map +1 -1
- package/dist/lib/utils/util.d.ts +5 -0
- package/dist/lib/utils/util.js +25 -16
- package/dist/lib/utils/util.js.map +1 -1
- package/dist/lib/xml/basemap.js +10 -9
- package/dist/lib/xml/basemap.js.map +1 -1
- package/dist/lib/xml/iconset.js +1 -1
- package/dist/lib/xml/iconset.js.map +1 -1
- package/dist/lib/xml-document.d.ts +1 -1
- package/dist/lib/xml-document.js +6 -3
- package/dist/lib/xml-document.js.map +1 -1
- package/dist/package.json +7 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/builders/chat.ts +3 -3
- package/lib/builders/route.ts +2 -2
- package/lib/cot.ts +42 -47
- package/lib/data-package.ts +72 -76
- package/lib/parser/from_geojson.ts +28 -29
- package/lib/parser/normalize_geojson.ts +22 -26
- package/lib/parser/to_geojson.ts +109 -94
- package/lib/parser-normalize.ts +30 -9
- package/lib/parser.ts +121 -92
- package/lib/sensor.ts +12 -5
- package/lib/type.ts +5 -5
- package/lib/types/cot-types.ts +4 -4
- package/lib/types/feature.ts +2 -0
- package/lib/types/types.ts +37 -3
- package/lib/utils/2525.ts +147 -96
- package/lib/utils/color.ts +1 -1
- package/lib/utils/type.ts +5 -5
- package/lib/utils/util.ts +31 -15
- package/lib/xml/basemap.ts +10 -9
- package/lib/xml/iconset.ts +1 -1
- package/lib/xml-document.ts +7 -4
- package/package.json +7 -7
- package/eslint.config.js +0 -15
package/lib/parser/to_geojson.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Err from '@openaddresses/batch-error';
|
|
|
2
2
|
import type { Static } from '@sinclair/typebox';
|
|
3
3
|
import type {
|
|
4
4
|
Feature,
|
|
5
|
-
Polygon,
|
|
6
5
|
FeaturePropertyMission,
|
|
7
6
|
FeaturePropertyMissionChange,
|
|
8
7
|
FeaturePropertyMissionLayer,
|
|
@@ -21,11 +20,13 @@ import type {
|
|
|
21
20
|
BioMeasurement,
|
|
22
21
|
BioMeasurementLevel,
|
|
23
22
|
BioMeasurementLevelAttributes,
|
|
23
|
+
MissionChanges,
|
|
24
24
|
} from '../types/types.js'
|
|
25
25
|
import Ellipse from '@turf/ellipse';
|
|
26
26
|
import Truncate from '@turf/truncate';
|
|
27
27
|
import { destination } from '@turf/destination';
|
|
28
28
|
import Color from '../utils/color.js';
|
|
29
|
+
import { jsonClone, toNumber } from '../utils/util.js';
|
|
29
30
|
import Type2525 from '../utils/2525.js';
|
|
30
31
|
import JSONCoT from '../types/types.js'
|
|
31
32
|
import CoT from '../cot.js';
|
|
@@ -34,6 +35,10 @@ import CoT from '../cot.js';
|
|
|
34
35
|
const COORDINATE_PRECISION = 6;
|
|
35
36
|
const ELLIPSE_TYPE_PREFIXES = ['u-d-c-c', 'u-r-b-c-c', 'u-d-c-e'];
|
|
36
37
|
|
|
38
|
+
function hasFlowAttributes(flow: unknown): flow is { _attributes: Record<string, string> } {
|
|
39
|
+
return typeof flow === 'object' && flow !== null && '_attributes' in flow && Boolean(flow._attributes);
|
|
40
|
+
}
|
|
41
|
+
|
|
37
42
|
export interface ToGeoJSONOptions {
|
|
38
43
|
/**
|
|
39
44
|
* If a numeric 2525D/E SIDC is present in the milicon detail, surface it
|
|
@@ -49,17 +54,17 @@ export async function to_geojson(
|
|
|
49
54
|
cot: CoT,
|
|
50
55
|
opts: ToGeoJSONOptions = {}
|
|
51
56
|
): Promise<Static<typeof Feature>> {
|
|
52
|
-
const raw: Static<typeof JSONCoT> =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
const raw: Static<typeof JSONCoT> = jsonClone(cot.raw);
|
|
58
|
+
raw.event.detail ??= {};
|
|
59
|
+
raw.event.detail.contact ??= { _attributes: { callsign: 'UNKNOWN' } };
|
|
60
|
+
raw.event.detail.contact._attributes ??= { callsign: 'UNKNOWN' };
|
|
56
61
|
|
|
57
62
|
const feat: Static<typeof Feature> = {
|
|
58
63
|
id: raw.event._attributes.uid,
|
|
59
64
|
type: 'Feature',
|
|
60
65
|
properties: {
|
|
61
66
|
callsign: raw.event.detail.contact._attributes.callsign || 'UNKNOWN',
|
|
62
|
-
center: [
|
|
67
|
+
center: [ toNumber(raw.event.point._attributes.lon), toNumber(raw.event.point._attributes.lat), toNumber(raw.event.point._attributes.hae) ],
|
|
63
68
|
type: raw.event._attributes.type,
|
|
64
69
|
how: raw.event._attributes.how || '',
|
|
65
70
|
time: raw.event._attributes.time,
|
|
@@ -68,13 +73,13 @@ export async function to_geojson(
|
|
|
68
73
|
},
|
|
69
74
|
geometry: {
|
|
70
75
|
type: 'Point',
|
|
71
|
-
coordinates: [
|
|
76
|
+
coordinates: [ toNumber(raw.event.point._attributes.lon), toNumber(raw.event.point._attributes.lat), toNumber(raw.event.point._attributes.hae) ]
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
79
|
|
|
75
|
-
const contact =
|
|
80
|
+
const contact = jsonClone(raw.event.detail.contact._attributes);
|
|
76
81
|
delete contact.callsign;
|
|
77
|
-
if (Object.keys(contact).length) {
|
|
82
|
+
if (Object.keys(contact).length > 0) {
|
|
78
83
|
feat.properties.contact = contact;
|
|
79
84
|
}
|
|
80
85
|
|
|
@@ -89,7 +94,7 @@ export async function to_geojson(
|
|
|
89
94
|
if (raw.event.detail.fileshare) {
|
|
90
95
|
feat.properties.fileshare = raw.event.detail.fileshare._attributes;
|
|
91
96
|
if (typeof feat.properties.fileshare?.sizeInBytes === 'string') {
|
|
92
|
-
feat.properties.fileshare.sizeInBytes =
|
|
97
|
+
feat.properties.fileshare.sizeInBytes = Math.trunc(Number(feat.properties.fileshare.sizeInBytes))
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
|
|
@@ -128,12 +133,12 @@ export async function to_geojson(
|
|
|
128
133
|
|
|
129
134
|
if (rad.radmeasurement) {
|
|
130
135
|
const measurements = Array.isArray(rad.radmeasurement) ? rad.radmeasurement : [rad.radmeasurement];
|
|
131
|
-
feat.properties.radsensordetail.radmeasurement = measurements.map((m: Static<typeof RadMeasurement>) =>
|
|
136
|
+
feat.properties.radsensordetail.radmeasurement = measurements.map((m: Static<typeof RadMeasurement>) => m._attributes);
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
if (rad.physical_module) {
|
|
135
140
|
const modules = Array.isArray(rad.physical_module) ? rad.physical_module : [rad.physical_module];
|
|
136
|
-
feat.properties.radsensordetail.physical_module = modules.map((m: Static<typeof RadPhysicalModule>) =>
|
|
141
|
+
feat.properties.radsensordetail.physical_module = modules.map((m: Static<typeof RadPhysicalModule>) => m._attributes);
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
if (rad.search_algorithm) {
|
|
@@ -142,12 +147,12 @@ export async function to_geojson(
|
|
|
142
147
|
|
|
143
148
|
if (rad.spectrum) {
|
|
144
149
|
const spectra = Array.isArray(rad.spectrum) ? rad.spectrum : [rad.spectrum];
|
|
145
|
-
feat.properties.radsensordetail.spectrum = spectra.map((s: Static<typeof RadSpectrum>) =>
|
|
150
|
+
feat.properties.radsensordetail.spectrum = spectra.map((s: Static<typeof RadSpectrum>) => s._attributes);
|
|
146
151
|
}
|
|
147
152
|
|
|
148
153
|
if (rad.isotope) {
|
|
149
154
|
const isotopes = Array.isArray(rad.isotope) ? rad.isotope : [rad.isotope];
|
|
150
|
-
feat.properties.radsensordetail.isotope = isotopes.map((i: Static<typeof RadIsotope>) =>
|
|
155
|
+
feat.properties.radsensordetail.isotope = isotopes.map((i: Static<typeof RadIsotope>) => i._attributes);
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
if (rad.data_permissions) {
|
|
@@ -167,7 +172,7 @@ export async function to_geojson(
|
|
|
167
172
|
|
|
168
173
|
if (chem.detection) {
|
|
169
174
|
const detections = Array.isArray(chem.detection) ? chem.detection : [chem.detection];
|
|
170
|
-
feat.properties.chemsensordetail.detection = detections.map((d: Static<typeof ChemDetection>) =>
|
|
175
|
+
feat.properties.chemsensordetail.detection = detections.map((d: Static<typeof ChemDetection>) => d._attributes);
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -180,10 +185,10 @@ export async function to_geojson(
|
|
|
180
185
|
if (bio.measurement) {
|
|
181
186
|
const measurements = Array.isArray(bio.measurement) ? bio.measurement : [bio.measurement];
|
|
182
187
|
feat.properties.biosensordetail.measurement = measurements.map((m: Static<typeof BioMeasurement>) => {
|
|
183
|
-
const measurement: { level?: Array<Static<typeof BioMeasurementLevelAttributes>> } & typeof m._attributes =
|
|
188
|
+
const measurement: { level?: Array<Static<typeof BioMeasurementLevelAttributes>> } & typeof m._attributes = m._attributes;
|
|
184
189
|
if (m.level) {
|
|
185
190
|
const levels = Array.isArray(m.level) ? m.level : [m.level];
|
|
186
|
-
measurement.level = levels.map((l: Static<typeof BioMeasurementLevel>) =>
|
|
191
|
+
measurement.level = levels.map((l: Static<typeof BioMeasurementLevel>) => l._attributes);
|
|
187
192
|
}
|
|
188
193
|
return measurement;
|
|
189
194
|
});
|
|
@@ -243,12 +248,13 @@ export async function to_geojson(
|
|
|
243
248
|
}
|
|
244
249
|
|
|
245
250
|
if (raw.event.detail.attachment_list) {
|
|
251
|
+
// oxlint-disable-next-line typescript/no-unsafe-assignment
|
|
246
252
|
feat.properties.attachments = JSON.parse(raw.event.detail.attachment_list._attributes.hashes);
|
|
247
253
|
}
|
|
248
254
|
|
|
249
255
|
if (raw.event.detail.image) {
|
|
250
256
|
feat.properties.image = {
|
|
251
|
-
...
|
|
257
|
+
...raw.event.detail.image._attributes,
|
|
252
258
|
data: raw.event.detail.image._text
|
|
253
259
|
};
|
|
254
260
|
}
|
|
@@ -271,7 +277,7 @@ export async function to_geojson(
|
|
|
271
277
|
});
|
|
272
278
|
}
|
|
273
279
|
|
|
274
|
-
if (
|
|
280
|
+
if (feat.properties.links.length === 0) delete feat.properties.links;
|
|
275
281
|
}
|
|
276
282
|
|
|
277
283
|
if (raw.event.detail.archive) {
|
|
@@ -283,14 +289,16 @@ export async function to_geojson(
|
|
|
283
289
|
}
|
|
284
290
|
|
|
285
291
|
if (raw.event.detail.__chat) {
|
|
292
|
+
const chatgrp: unknown = raw.event.detail.__chat.chatgrp;
|
|
286
293
|
feat.properties.chat = {
|
|
287
294
|
...raw.event.detail.__chat._attributes,
|
|
288
|
-
chatgrp
|
|
295
|
+
chatgrp
|
|
289
296
|
}
|
|
290
297
|
} else if (raw.event.detail.__chatreceipt) {
|
|
298
|
+
const chatgrp: unknown = raw.event.detail.__chatreceipt.chatgrp;
|
|
291
299
|
feat.properties.chat = {
|
|
292
300
|
...raw.event.detail.__chatreceipt._attributes,
|
|
293
|
-
chatgrp
|
|
301
|
+
chatgrp
|
|
294
302
|
}
|
|
295
303
|
}
|
|
296
304
|
|
|
@@ -342,8 +350,9 @@ export async function to_geojson(
|
|
|
342
350
|
feat.properties.group = raw.event.detail.__group._attributes;
|
|
343
351
|
}
|
|
344
352
|
|
|
345
|
-
|
|
346
|
-
|
|
353
|
+
const flow: unknown = raw.event.detail['_flow-tags_'];
|
|
354
|
+
if (hasFlowAttributes(flow)) {
|
|
355
|
+
feat.properties.flow = flow._attributes;
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
if (raw.event.detail.status?._attributes) {
|
|
@@ -356,30 +365,33 @@ export async function to_geojson(
|
|
|
356
365
|
};
|
|
357
366
|
|
|
358
367
|
if (raw.event.detail.mission.MissionChanges) {
|
|
359
|
-
const
|
|
368
|
+
const missionChanges: Array<Static<typeof MissionChanges>> =
|
|
360
369
|
Array.isArray(raw.event.detail.mission.MissionChanges)
|
|
361
370
|
? raw.event.detail.mission.MissionChanges
|
|
362
371
|
: [ raw.event.detail.mission.MissionChanges ]
|
|
363
372
|
|
|
373
|
+
const changes = missionChanges.flatMap((missionChange) => missionChange.MissionChange);
|
|
374
|
+
|
|
364
375
|
mission.missionChanges = []
|
|
365
376
|
for (const change of changes) {
|
|
366
377
|
const mc: Static<typeof FeaturePropertyMissionChange> = {
|
|
367
|
-
contentUid: change.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
378
|
+
contentUid: change.contentUid ? change.contentUid._text : undefined,
|
|
379
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
380
|
+
creatorUid: change.creatorUid._text as string,
|
|
381
|
+
isFederatedChange: change.isFederatedChange._text,
|
|
382
|
+
missionName: change.missionName._text,
|
|
383
|
+
timestamp: change.timestamp._text,
|
|
384
|
+
type: change.type._text,
|
|
373
385
|
};
|
|
374
386
|
|
|
375
|
-
if (change.
|
|
376
|
-
const cr = change.
|
|
387
|
+
if (change.contentResource) {
|
|
388
|
+
const cr = change.contentResource;
|
|
377
389
|
mc.contentResource = {
|
|
378
390
|
uid: cr.uid._text,
|
|
379
391
|
expiration: cr.expiration._text,
|
|
380
392
|
hash: cr.hash._text,
|
|
381
393
|
name: cr.name._text,
|
|
382
|
-
size:
|
|
394
|
+
size: Math.trunc(toNumber(cr.size._text)),
|
|
383
395
|
submissionTime: cr.submissionTime._text,
|
|
384
396
|
submitter: cr.submitter._text,
|
|
385
397
|
filename: cr.filename ? cr.filename._text : undefined,
|
|
@@ -387,21 +399,22 @@ export async function to_geojson(
|
|
|
387
399
|
};
|
|
388
400
|
}
|
|
389
401
|
|
|
390
|
-
if (change.
|
|
391
|
-
const mp = change.
|
|
402
|
+
if (change.content?.MissionProperty) {
|
|
403
|
+
const mp = change.content.MissionProperty;
|
|
392
404
|
mc.missionProperty = {
|
|
393
405
|
key: mp.key._text,
|
|
394
406
|
value: mp.value?._text ?? '',
|
|
395
407
|
};
|
|
396
408
|
}
|
|
397
409
|
|
|
398
|
-
if (change.
|
|
410
|
+
if (change.details) {
|
|
411
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
399
412
|
mc.details = {
|
|
400
|
-
...change.
|
|
401
|
-
...change.
|
|
402
|
-
? change.
|
|
413
|
+
...change.details._attributes,
|
|
414
|
+
...change.details.location
|
|
415
|
+
? change.details.location._attributes
|
|
403
416
|
: {}
|
|
404
|
-
};
|
|
417
|
+
} as Static<typeof FeaturePropertyMissionChange>['details'];
|
|
405
418
|
}
|
|
406
419
|
|
|
407
420
|
mission.missionChanges.push(mc)
|
|
@@ -435,14 +448,19 @@ export async function to_geojson(
|
|
|
435
448
|
feat.properties.precisionlocation = raw.event.detail.precisionlocation._attributes;
|
|
436
449
|
}
|
|
437
450
|
|
|
451
|
+
if (raw.event.detail.__address?._attributes?.text) {
|
|
452
|
+
feat.properties.address = raw.event.detail.__address._attributes;
|
|
453
|
+
}
|
|
454
|
+
|
|
438
455
|
if (raw.event.detail.strokeColor?._attributes?.value !== undefined) {
|
|
439
|
-
const stroke = new Color(
|
|
456
|
+
const stroke = new Color(toNumber(raw.event.detail.strokeColor._attributes.value));
|
|
440
457
|
feat.properties.stroke = stroke.as_hex();
|
|
441
458
|
feat.properties['stroke-opacity'] = stroke.as_opacity() / 255;
|
|
442
459
|
}
|
|
443
460
|
|
|
444
|
-
|
|
445
|
-
|
|
461
|
+
const strokeWeight = raw.event.detail.strokeWeight?._attributes?.value ?? 0;
|
|
462
|
+
if (strokeWeight) {
|
|
463
|
+
feat.properties['stroke-width'] = toNumber(strokeWeight);
|
|
446
464
|
}
|
|
447
465
|
|
|
448
466
|
if (raw.event.detail.strokeStyle?._attributes?.value) {
|
|
@@ -454,7 +472,7 @@ export async function to_geojson(
|
|
|
454
472
|
|
|
455
473
|
if (Array.isArray(raw.event.detail.color) && raw.event.detail.color.length > 1) {
|
|
456
474
|
color = raw.event.detail.color[0];
|
|
457
|
-
|
|
475
|
+
color._attributes ??= {};
|
|
458
476
|
|
|
459
477
|
for (let i = raw.event.detail.color.length - 1; i >= 1; i--) {
|
|
460
478
|
if (raw.event.detail.color[i]._attributes) {
|
|
@@ -467,8 +485,9 @@ export async function to_geojson(
|
|
|
467
485
|
color = raw.event.detail.color;
|
|
468
486
|
}
|
|
469
487
|
|
|
470
|
-
|
|
471
|
-
|
|
488
|
+
const argb = color?._attributes?.argb ?? 0;
|
|
489
|
+
if (argb) {
|
|
490
|
+
const parsedColor = new Color(toNumber(argb));
|
|
472
491
|
feat.properties['marker-color'] = parsedColor.as_hex();
|
|
473
492
|
feat.properties['marker-opacity'] = parsedColor.as_opacity() / 255;
|
|
474
493
|
}
|
|
@@ -480,12 +499,12 @@ export async function to_geojson(
|
|
|
480
499
|
|
|
481
500
|
for (const l of raw.event.detail.link) {
|
|
482
501
|
if (!l._attributes.point) continue;
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
);
|
|
502
|
+
const coord = l._attributes.point.split(',')
|
|
503
|
+
.map((p: string) => { return Number(p.trim()) })
|
|
504
|
+
.splice(0, 2);
|
|
505
|
+
coord.reverse();
|
|
506
|
+
|
|
507
|
+
coordinates.push(coord);
|
|
489
508
|
}
|
|
490
509
|
|
|
491
510
|
// Range & Bearing Line
|
|
@@ -495,7 +514,7 @@ export async function to_geojson(
|
|
|
495
514
|
if (!detail.range) throw new Error('Range value not provided')
|
|
496
515
|
if (!detail.bearing) throw new Error('Bearing value not provided')
|
|
497
516
|
|
|
498
|
-
//
|
|
517
|
+
// Inclination is not yet supported
|
|
499
518
|
const dest = destination(
|
|
500
519
|
cot.position(),
|
|
501
520
|
detail.range._attributes.value / 1000,
|
|
@@ -506,7 +525,7 @@ export async function to_geojson(
|
|
|
506
525
|
type: 'LineString',
|
|
507
526
|
coordinates: [cot.position(), dest]
|
|
508
527
|
};
|
|
509
|
-
} else if (raw.event._attributes.type === 'u-d-r' || (coordinates[0][0] === coordinates
|
|
528
|
+
} else if (raw.event._attributes.type === 'u-d-r' || (coordinates[0][0] === coordinates.at(-1)?.[0] && coordinates[0][1] === coordinates.at(-1)?.[1])) {
|
|
510
529
|
if (raw.event._attributes.type === 'u-d-r') {
|
|
511
530
|
// CoT rectangles are only 4 points - GeoJSON needs to be closed
|
|
512
531
|
coordinates.push(coordinates[0])
|
|
@@ -518,7 +537,7 @@ export async function to_geojson(
|
|
|
518
537
|
}
|
|
519
538
|
|
|
520
539
|
if (raw.event.detail.fillColor?._attributes?.value !== undefined) {
|
|
521
|
-
const fill = new Color(
|
|
540
|
+
const fill = new Color(toNumber(raw.event.detail.fillColor._attributes.value));
|
|
522
541
|
feat.properties['fill-opacity'] = fill.as_opacity() / 255;
|
|
523
542
|
feat.properties['fill'] = fill.as_hex();
|
|
524
543
|
}
|
|
@@ -531,10 +550,7 @@ export async function to_geojson(
|
|
|
531
550
|
} else if (ELLIPSE_TYPE_PREFIXES.some((prefix) => raw.event._attributes.type.startsWith(prefix))) {
|
|
532
551
|
if (!raw.event.detail.shape) throw new Err(400, null, `${raw.event._attributes.type} (Circle) must define shape value`)
|
|
533
552
|
|
|
534
|
-
if (
|
|
535
|
-
!raw.event.detail.shape.ellipse
|
|
536
|
-
|| !raw.event.detail.shape.ellipse._attributes
|
|
537
|
-
) throw new Err(400, null, `${raw.event._attributes.type} (Circle) must define ellipse shape value`)
|
|
553
|
+
if (!raw.event.detail.shape.ellipse?._attributes) throw new Err(400, null, `${raw.event._attributes.type} (Circle) must define ellipse shape value`)
|
|
538
554
|
|
|
539
555
|
const ellipse: {
|
|
540
556
|
major: number;
|
|
@@ -542,18 +558,18 @@ export async function to_geojson(
|
|
|
542
558
|
angle: number;
|
|
543
559
|
swapAxis?: boolean;
|
|
544
560
|
} = {
|
|
545
|
-
major:
|
|
546
|
-
minor:
|
|
547
|
-
angle:
|
|
561
|
+
major: toNumber(raw.event.detail.shape.ellipse._attributes.major),
|
|
562
|
+
minor: toNumber(raw.event.detail.shape.ellipse._attributes.minor),
|
|
563
|
+
angle: toNumber(raw.event.detail.shape.ellipse._attributes.angle)
|
|
548
564
|
}
|
|
549
565
|
|
|
550
566
|
if (raw.event.detail.shape.ellipse._attributes.swapAxis !== undefined) {
|
|
551
|
-
ellipse.swapAxis =
|
|
567
|
+
ellipse.swapAxis = raw.event.detail.shape.ellipse._attributes.swapAxis;
|
|
552
568
|
}
|
|
553
569
|
|
|
554
570
|
// ATAK puts circle fill in detail.fillColor; KML PolyStyle (below) may override.
|
|
555
571
|
if (raw.event.detail.fillColor?._attributes?.value !== undefined) {
|
|
556
|
-
const fill = new Color(
|
|
572
|
+
const fill = new Color(toNumber(raw.event.detail.fillColor._attributes.value));
|
|
557
573
|
feat.properties['fill-opacity'] = fill.as_opacity() / 255;
|
|
558
574
|
feat.properties['fill'] = fill.as_hex();
|
|
559
575
|
}
|
|
@@ -564,18 +580,18 @@ export async function to_geojson(
|
|
|
564
580
|
: [raw.event.detail.shape.link])
|
|
565
581
|
: [];
|
|
566
582
|
const styleLink = styleLinks.find((link) => (
|
|
567
|
-
link?._attributes?.type === 'b-x-KmlStyle' && link.Style
|
|
583
|
+
link?._attributes?.type === 'b-x-KmlStyle' && link.Style !== undefined
|
|
568
584
|
));
|
|
569
585
|
|
|
570
586
|
if (styleLink?.Style) {
|
|
571
587
|
if (styleLink.Style.LineStyle?.color) {
|
|
572
588
|
let rawColor = styleLink.Style.LineStyle.color._text;
|
|
573
|
-
if (rawColor.startsWith('#')) rawColor = rawColor.
|
|
589
|
+
if (rawColor.startsWith('#')) rawColor = rawColor.slice(1);
|
|
574
590
|
|
|
575
|
-
const a = parseInt(rawColor.
|
|
576
|
-
const r = parseInt(rawColor.
|
|
577
|
-
const g = parseInt(rawColor.
|
|
578
|
-
const b = parseInt(rawColor.
|
|
591
|
+
const a = parseInt(rawColor.slice(0, 2), 16);
|
|
592
|
+
const r = parseInt(rawColor.slice(2, 4), 16);
|
|
593
|
+
const g = parseInt(rawColor.slice(4, 6), 16);
|
|
594
|
+
const b = parseInt(rawColor.slice(6, 8), 16);
|
|
579
595
|
|
|
580
596
|
const strokeColor = new Color([a, r, g, b]);
|
|
581
597
|
feat.properties.stroke = strokeColor.as_hex();
|
|
@@ -584,17 +600,17 @@ export async function to_geojson(
|
|
|
584
600
|
}
|
|
585
601
|
|
|
586
602
|
if (styleLink.Style.LineStyle?.width) {
|
|
587
|
-
feat.properties['stroke-width'] =
|
|
603
|
+
feat.properties['stroke-width'] = toNumber(styleLink.Style.LineStyle.width._text);
|
|
588
604
|
}
|
|
589
605
|
|
|
590
606
|
if (styleLink.Style.PolyStyle?.color) {
|
|
591
607
|
let rawColor = styleLink.Style.PolyStyle.color._text;
|
|
592
|
-
if (rawColor.startsWith('#')) rawColor = rawColor.
|
|
608
|
+
if (rawColor.startsWith('#')) rawColor = rawColor.slice(1);
|
|
593
609
|
|
|
594
|
-
const a = parseInt(rawColor.
|
|
595
|
-
const r = parseInt(rawColor.
|
|
596
|
-
const g = parseInt(rawColor.
|
|
597
|
-
const b = parseInt(rawColor.
|
|
610
|
+
const a = parseInt(rawColor.slice(0, 2), 16);
|
|
611
|
+
const r = parseInt(rawColor.slice(2, 4), 16);
|
|
612
|
+
const g = parseInt(rawColor.slice(4, 6), 16);
|
|
613
|
+
const b = parseInt(rawColor.slice(6, 8), 16);
|
|
598
614
|
|
|
599
615
|
const fillColor = new Color([a, r, g, b]);
|
|
600
616
|
feat.properties['fill-opacity'] = fillColor.as_opacity() / 255;
|
|
@@ -603,9 +619,9 @@ export async function to_geojson(
|
|
|
603
619
|
}
|
|
604
620
|
|
|
605
621
|
feat.geometry = Truncate(Ellipse(
|
|
606
|
-
feat.
|
|
607
|
-
|
|
608
|
-
|
|
622
|
+
feat.properties.center,
|
|
623
|
+
ellipse.major / 1000,
|
|
624
|
+
ellipse.minor / 1000,
|
|
609
625
|
{
|
|
610
626
|
angle: 90 - ellipse.angle
|
|
611
627
|
}
|
|
@@ -613,7 +629,7 @@ export async function to_geojson(
|
|
|
613
629
|
precision: COORDINATE_PRECISION,
|
|
614
630
|
coordinates: 3,
|
|
615
631
|
mutate: true
|
|
616
|
-
}).geometry
|
|
632
|
+
}).geometry;
|
|
617
633
|
|
|
618
634
|
feat.properties.shape = {};
|
|
619
635
|
feat.properties.shape.ellipse = ellipse;
|
|
@@ -623,8 +639,8 @@ export async function to_geojson(
|
|
|
623
639
|
|
|
624
640
|
const vertices = Array.isArray(raw.event.detail.shape.polyline.vertex) ? raw.event.detail.shape.polyline.vertex : [raw.event.detail.shape.polyline.vertex];
|
|
625
641
|
for (const v of vertices) {
|
|
626
|
-
const coord = [
|
|
627
|
-
if (v._attributes.hae !== undefined) coord.push(
|
|
642
|
+
const coord = [toNumber(v._attributes.lon), toNumber(v._attributes.lat)];
|
|
643
|
+
if (v._attributes.hae !== undefined) coord.push(toNumber(v._attributes.hae));
|
|
628
644
|
coordinates.push(coord);
|
|
629
645
|
}
|
|
630
646
|
|
|
@@ -632,8 +648,8 @@ export async function to_geojson(
|
|
|
632
648
|
feat.geometry = { type: 'Point', coordinates: coordinates[0] }
|
|
633
649
|
} else if (raw.event.detail.shape.polyline._attributes?.closed === true) {
|
|
634
650
|
const first = coordinates[0];
|
|
635
|
-
const last = coordinates
|
|
636
|
-
if (first[0] !== last[0] || first[1] !== last[1]) coordinates.push(first);
|
|
651
|
+
const last = coordinates.at(-1);
|
|
652
|
+
if (first[0] !== last?.[0] || first[1] !== last[1]) coordinates.push(first);
|
|
637
653
|
|
|
638
654
|
feat.geometry = { type: 'Polygon', coordinates: [coordinates] }
|
|
639
655
|
} else {
|
|
@@ -653,16 +669,15 @@ export async function to_geojson(
|
|
|
653
669
|
feat.properties['stroke-opacity'] = stroke.as_opacity() / 255;
|
|
654
670
|
}
|
|
655
671
|
}
|
|
656
|
-
} else if (
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
}
|
|
672
|
+
} else if (
|
|
673
|
+
raw.event._attributes.type === 'b-m-p-s-m'
|
|
674
|
+
&& raw.event.detail.usericon?._attributes?.iconsetpath
|
|
675
|
+
&& raw.event.detail.usericon._attributes.iconsetpath.startsWith('COT_MAPPING_SPOTMAP/b-m-p-s-m/')
|
|
676
|
+
) {
|
|
677
|
+
const spot = new Color(Number(raw.event.detail.usericon._attributes.iconsetpath.split('/')[2]));
|
|
678
|
+
feat.properties['marker-color'] = spot.as_hex();
|
|
679
|
+
feat.properties['marker-opacity'] = spot.as_opacity() / 255;
|
|
680
|
+
delete feat.properties.icon;
|
|
666
681
|
}
|
|
667
682
|
|
|
668
683
|
feat.properties.metadata = cot.metadata;
|
package/lib/parser-normalize.ts
CHANGED
|
@@ -5,6 +5,10 @@ export type ParsedAttributeVisitor = (
|
|
|
5
5
|
path: string[]
|
|
6
6
|
) => void;
|
|
7
7
|
|
|
8
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
9
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export function visitElementAttributes(
|
|
9
13
|
input: unknown,
|
|
10
14
|
visitor: ParsedAttributeVisitor,
|
|
@@ -18,18 +22,15 @@ export function visitElementAttributes(
|
|
|
18
22
|
return;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
if (!input
|
|
25
|
+
if (!isRecord(input)) {
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const [attributeKey, attributeValue] of Object.entries(attributes)) {
|
|
31
|
-
visitor(attributeKey, attributeValue, attributes, [...path, key]);
|
|
32
|
-
visitElementAttributes(attributes[attributeKey], visitor, [...path, key, attributeKey]);
|
|
29
|
+
for (const [key, value] of Object.entries(input)) {
|
|
30
|
+
if (key === '_attributes' && isRecord(value)) {
|
|
31
|
+
for (const [attributeKey, attributeValue] of Object.entries(value)) {
|
|
32
|
+
visitor(attributeKey, attributeValue, value, [...path, key]);
|
|
33
|
+
visitElementAttributes(value[attributeKey], visitor, [...path, key, attributeKey]);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
continue;
|
|
@@ -53,3 +54,23 @@ export function normalizeBooleanAttributeValues(input: unknown): void {
|
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* xml-js leaves a circular `_parent` reference on every element that is still
|
|
60
|
+
* open when the input ends
|
|
61
|
+
*/
|
|
62
|
+
export function hasUnclosedElements(input: unknown): boolean {
|
|
63
|
+
if (Array.isArray(input)) {
|
|
64
|
+
return input.some((value) => hasUnclosedElements(value));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!isRecord(input)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if ('_parent' in input) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Object.values(input).some((value) => hasUnclosedElements(value));
|
|
76
|
+
}
|