@tak-ps/node-cot 14.59.0 → 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 +5 -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 +24 -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 +94 -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 +755 -755
- package/dist/lib/types/types.d.ts +55 -9
- package/dist/lib/types/types.js +18 -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 +24 -29
- package/lib/parser/normalize_geojson.ts +22 -26
- package/lib/parser/to_geojson.ts +105 -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/types.ts +20 -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/data-package.ts
CHANGED
|
@@ -8,7 +8,7 @@ import StreamZip from 'node-stream-zip'
|
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
9
9
|
import CoT from './cot.js';
|
|
10
10
|
import { CoTParser } from './parser.js';
|
|
11
|
-
import
|
|
11
|
+
import { xml2js, js2xml } from '@tak-ps/xml-js';
|
|
12
12
|
import os from 'node:os';
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import fsp from 'node:fs/promises';
|
|
@@ -74,7 +74,7 @@ const checkManifest = (new AJV({
|
|
|
74
74
|
coerceTypes: true,
|
|
75
75
|
allowUnionTypes: true
|
|
76
76
|
}))
|
|
77
|
-
.compile(Manifest);
|
|
77
|
+
.compile<Static<typeof Manifest>>(Manifest);
|
|
78
78
|
|
|
79
79
|
async function materializeDataPackageInput(
|
|
80
80
|
input: string | URL | Buffer | Readable,
|
|
@@ -146,7 +146,7 @@ export class DataPackage {
|
|
|
146
146
|
path?: string
|
|
147
147
|
} = {}
|
|
148
148
|
) {
|
|
149
|
-
if (opts
|
|
149
|
+
if (opts?.path) {
|
|
150
150
|
this.path = opts.path;
|
|
151
151
|
} else {
|
|
152
152
|
this.path = os.tmpdir() + '/' + crypto.randomUUID();
|
|
@@ -199,13 +199,14 @@ export class DataPackage {
|
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
for (const key in this.settings) {
|
|
202
|
-
|
|
202
|
+
const value = this.settings[key];
|
|
203
|
+
if (value === undefined || value === false || value === '') continue;
|
|
203
204
|
manifest.MissionPackageManifest.Configuration.Parameter.push({
|
|
204
|
-
_attributes: { name: key, value: String(
|
|
205
|
+
_attributes: { name: key, value: String(value) }
|
|
205
206
|
})
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
const xml = `<?xml version="1.0" encoding="UTF-8"?>\n${
|
|
209
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>\n${js2xml(manifest, { compact: true })}`;
|
|
209
210
|
|
|
210
211
|
return xml;
|
|
211
212
|
}
|
|
@@ -215,15 +216,15 @@ export class DataPackage {
|
|
|
215
216
|
* Return true if the DataPackage is a MissionSync Archive
|
|
216
217
|
*/
|
|
217
218
|
isMissionArchive(): boolean {
|
|
218
|
-
return
|
|
219
|
+
return Boolean(this.settings.mission_guid) && Boolean(this.settings.mission_name);
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
/**
|
|
222
223
|
* When DataPackages are uploaded to TAK Server they generally use an EUD
|
|
223
224
|
* calculated Hash
|
|
224
225
|
*/
|
|
225
|
-
static async hash(
|
|
226
|
-
const input = fs.createReadStream(
|
|
226
|
+
static async hash(file: string): Promise<string> {
|
|
227
|
+
const input = fs.createReadStream(file);
|
|
227
228
|
const hash = createHash('sha256');
|
|
228
229
|
await pipeline(input, hash);
|
|
229
230
|
return hash.digest('hex');
|
|
@@ -234,7 +235,7 @@ export class DataPackage {
|
|
|
234
235
|
* calculated Hash
|
|
235
236
|
*/
|
|
236
237
|
async hash(entry: string): Promise<string> {
|
|
237
|
-
return
|
|
238
|
+
return DataPackage.hash(this.path + '/raw/' + entry);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
|
|
@@ -256,9 +257,9 @@ export class DataPackage {
|
|
|
256
257
|
name?: string
|
|
257
258
|
}
|
|
258
259
|
): Promise<DataPackage> {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
opts ??= {};
|
|
261
|
+
opts.strict ??= true;
|
|
262
|
+
opts.cleanup ??= true;
|
|
262
263
|
|
|
263
264
|
const source = await materializeDataPackageInput(input, opts.name);
|
|
264
265
|
|
|
@@ -270,20 +271,22 @@ export class DataPackage {
|
|
|
270
271
|
});
|
|
271
272
|
|
|
272
273
|
const preentries = await zip.entries();
|
|
274
|
+
const manifestEntry: unknown = preentries['MANIFEST/manifest.xml'];
|
|
273
275
|
|
|
274
|
-
if (opts.strict &&
|
|
276
|
+
if (opts.strict && manifestEntry === undefined) {
|
|
275
277
|
throw new Err(400, null, 'No MANIFEST/manifest.xml found in Data Package');
|
|
276
278
|
}
|
|
277
279
|
|
|
278
280
|
await fsp.mkdir(pkg.path + '/raw', { recursive: true });
|
|
279
281
|
await zip.extract(null, pkg.path + '/raw/');
|
|
280
282
|
|
|
281
|
-
if (
|
|
282
|
-
const
|
|
283
|
+
if (manifestEntry !== undefined) {
|
|
284
|
+
const manifest: unknown = xml2js(String(await fsp.readFile(pkg.path + '/raw/MANIFEST/manifest.xml')), { compact: true })
|
|
283
285
|
|
|
284
|
-
checkManifest(
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
if (!checkManifest(manifest)) {
|
|
287
|
+
const [error] = checkManifest.errors ?? [];
|
|
288
|
+
throw new Err(400, null, `${error?.message} (${error?.instancePath})`);
|
|
289
|
+
}
|
|
287
290
|
|
|
288
291
|
pkg.version = manifest.MissionPackageManifest._attributes.version;
|
|
289
292
|
|
|
@@ -295,7 +298,7 @@ export class DataPackage {
|
|
|
295
298
|
|
|
296
299
|
for (const param of manifest.MissionPackageManifest.Configuration.Parameter) {
|
|
297
300
|
if (['onReceiveImport', 'onReceiveDelete'].includes(param._attributes.name) && typeof param._attributes.value === 'string') {
|
|
298
|
-
pkg.settings[param._attributes.name] = param._attributes.value
|
|
301
|
+
pkg.settings[param._attributes.name] = param._attributes.value !== 'false';
|
|
299
302
|
} else {
|
|
300
303
|
pkg.settings[param._attributes.name] = param._attributes.value;
|
|
301
304
|
}
|
|
@@ -331,7 +334,7 @@ export class DataPackage {
|
|
|
331
334
|
#addContent(zipEntry: string, uid: string, name?: string, ignore = false): void {
|
|
332
335
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
333
336
|
|
|
334
|
-
//
|
|
337
|
+
// Seen in the wild but not currently implemented here:
|
|
335
338
|
// <Parameter name="contentType" value="KML"/>
|
|
336
339
|
// <Parameter name="visible" value="false"/>
|
|
337
340
|
|
|
@@ -353,20 +356,21 @@ export class DataPackage {
|
|
|
353
356
|
other attachment actions do not automatically populate this field other than the link
|
|
354
357
|
provided between a CoT and it's attachment in the MANIFEST file
|
|
355
358
|
*/
|
|
356
|
-
async cots(opts
|
|
357
|
-
respectIgnore:
|
|
358
|
-
parseAttachments:
|
|
359
|
+
async cots(opts?: {
|
|
360
|
+
respectIgnore: boolean,
|
|
361
|
+
parseAttachments: boolean
|
|
359
362
|
}): Promise<Array<CoT>> {
|
|
360
363
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
361
364
|
|
|
365
|
+
const respectIgnore = opts ? opts.respectIgnore : true;
|
|
366
|
+
const parseAttachments = opts ? opts.parseAttachments : true;
|
|
367
|
+
|
|
362
368
|
const cotsMap: Map<string, CoT> = new Map();
|
|
363
369
|
|
|
364
370
|
const cots: CoT[] = [];
|
|
365
371
|
for (const content of this.contents) {
|
|
366
|
-
if (!content) continue;
|
|
367
|
-
|
|
368
372
|
if (path.parse(content._attributes.zipEntry).ext !== '.cot') continue;
|
|
369
|
-
if (
|
|
373
|
+
if (respectIgnore && content._attributes.ignore) continue;
|
|
370
374
|
|
|
371
375
|
const cot = CoTParser.from_xml(await fsp.readFile(this.path + '/raw/' + content._attributes.zipEntry));
|
|
372
376
|
|
|
@@ -375,27 +379,22 @@ export class DataPackage {
|
|
|
375
379
|
cots.push(cot);
|
|
376
380
|
}
|
|
377
381
|
|
|
378
|
-
if (
|
|
379
|
-
const attachments = this.#attachments(cotsMap, {
|
|
380
|
-
respectIgnore: opts.respectIgnore
|
|
381
|
-
});
|
|
382
|
+
if (parseAttachments) {
|
|
383
|
+
const attachments = this.#attachments(cotsMap, { respectIgnore });
|
|
382
384
|
|
|
383
385
|
for (const cot of cots) {
|
|
384
|
-
|
|
385
|
-
cot.raw.event.detail = {};
|
|
386
|
-
}
|
|
386
|
+
cot.raw.event.detail ??= {};
|
|
387
387
|
|
|
388
388
|
const attaches = attachments.get(cot.uid());
|
|
389
389
|
if (!attaches) continue;
|
|
390
390
|
|
|
391
391
|
for (const attach of attaches) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
396
|
-
}
|
|
392
|
+
cot.raw.event.detail.attachment_list ??= {
|
|
393
|
+
_attributes: { hashes: '[]' }
|
|
394
|
+
};
|
|
397
395
|
|
|
398
|
-
const hashes:
|
|
396
|
+
const hashes: unknown = JSON.parse(cot.raw.event.detail.attachment_list._attributes.hashes)
|
|
397
|
+
if (!Array.isArray(hashes)) throw new Err(400, null, 'attachment_list hashes must be a JSON Array');
|
|
399
398
|
|
|
400
399
|
// Until told otherwise the FileHash appears to always be the directory name
|
|
401
400
|
const hash = await this.hash(attach._attributes.zipEntry);
|
|
@@ -413,29 +412,26 @@ export class DataPackage {
|
|
|
413
412
|
return cots;
|
|
414
413
|
}
|
|
415
414
|
|
|
416
|
-
#attachments(cots: Map<string, CoT>, opts
|
|
415
|
+
#attachments(cots: Map<string, CoT>, opts: { respectIgnore: boolean }): Map<string, Array<Static<typeof ManifestContent>>> {
|
|
417
416
|
const attachments: Map<string, Array<Static<typeof ManifestContent>>> = new Map();
|
|
418
417
|
|
|
419
418
|
for (const content of this.contents) {
|
|
420
|
-
if (!content) continue;
|
|
421
|
-
|
|
422
419
|
if (path.parse(content._attributes.zipEntry).ext === '.cot') continue;
|
|
423
420
|
if (opts.respectIgnore && content._attributes.ignore) continue;
|
|
421
|
+
if (!content.Parameter) continue;
|
|
424
422
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
423
|
+
const params = Array.isArray(content.Parameter) ? content.Parameter : [content.Parameter];
|
|
424
|
+
|
|
425
|
+
for (const param of params) {
|
|
426
|
+
if (param._attributes.name !== 'uid' || !cots.has(param._attributes.value)) continue;
|
|
427
|
+
|
|
428
|
+
const existing = attachments.get(param._attributes.value);
|
|
429
|
+
if (existing) {
|
|
430
|
+
existing.push(content);
|
|
431
|
+
} else {
|
|
432
|
+
attachments.set(param._attributes.value, [content]);
|
|
438
433
|
}
|
|
434
|
+
break;
|
|
439
435
|
}
|
|
440
436
|
}
|
|
441
437
|
|
|
@@ -446,8 +442,9 @@ export class DataPackage {
|
|
|
446
442
|
* Return a list of files that are NOT attachments or CoT markers
|
|
447
443
|
* The Set returned has a list of file paths that can be passed to getFile(path)
|
|
448
444
|
*/
|
|
449
|
-
async files(opts
|
|
450
|
-
const
|
|
445
|
+
async files(opts?: { respectIgnore: boolean }): Promise<Set<string>> {
|
|
446
|
+
const respectIgnore = opts ? opts.respectIgnore : true;
|
|
447
|
+
const attachments = await this.attachments({ respectIgnore });
|
|
451
448
|
const files: Set<string> = new Set();
|
|
452
449
|
|
|
453
450
|
const attachment_entries = new Set<string>();
|
|
@@ -458,9 +455,8 @@ export class DataPackage {
|
|
|
458
455
|
}
|
|
459
456
|
|
|
460
457
|
for (const content of this.contents) {
|
|
461
|
-
if (!content) continue;
|
|
462
458
|
if (path.parse(content._attributes.zipEntry).ext === '.cot') continue;
|
|
463
|
-
if (
|
|
459
|
+
if (respectIgnore && content._attributes.ignore) continue;
|
|
464
460
|
|
|
465
461
|
if (attachment_entries.has(content._attributes.zipEntry)) {
|
|
466
462
|
continue;
|
|
@@ -476,43 +472,45 @@ export class DataPackage {
|
|
|
476
472
|
* Return attachments that are associated in the Manifest with a given CoT
|
|
477
473
|
* Note: this does not return files that are NOT associated with a CoT
|
|
478
474
|
*/
|
|
479
|
-
async attachments(opts
|
|
475
|
+
async attachments(opts?: { respectIgnore: boolean }): Promise<Map<string, Array<Static<typeof ManifestContent>>>> {
|
|
476
|
+
const respectIgnore = opts ? opts.respectIgnore : true;
|
|
477
|
+
|
|
480
478
|
const cots: Map<string, CoT> = new Map();
|
|
481
479
|
for (const cot of await this.cots({
|
|
482
|
-
respectIgnore
|
|
480
|
+
respectIgnore,
|
|
483
481
|
parseAttachments: false
|
|
484
482
|
})) {
|
|
485
483
|
cots.set(cot.uid(), cot);
|
|
486
484
|
}
|
|
487
485
|
|
|
488
|
-
return this.#attachments(cots,
|
|
486
|
+
return this.#attachments(cots, { respectIgnore });
|
|
489
487
|
}
|
|
490
488
|
|
|
491
|
-
async getFileBuffer(
|
|
489
|
+
async getFileBuffer(file: string): Promise<Buffer> {
|
|
492
490
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
493
491
|
|
|
494
492
|
try {
|
|
495
|
-
await fsp.access(`${this.path}/raw/${
|
|
493
|
+
await fsp.access(`${this.path}/raw/${file}`)
|
|
496
494
|
} catch (err) {
|
|
497
495
|
throw new Err(400, err instanceof Error ? err : new Error(String(err)), 'Could not access file in Data Package');
|
|
498
496
|
}
|
|
499
497
|
|
|
500
|
-
return
|
|
498
|
+
return fsp.readFile(`${this.path}/raw/${file}`);
|
|
501
499
|
}
|
|
502
500
|
|
|
503
501
|
/**
|
|
504
502
|
* Get any file from a Package
|
|
505
503
|
*/
|
|
506
|
-
async getFile(
|
|
504
|
+
async getFile(file: string): Promise<Readable> {
|
|
507
505
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
508
506
|
|
|
509
507
|
try {
|
|
510
|
-
await fsp.access(`${this.path}/raw/${
|
|
508
|
+
await fsp.access(`${this.path}/raw/${file}`)
|
|
511
509
|
} catch (err) {
|
|
512
510
|
throw new Err(400, err instanceof Error ? err : new Error(String(err)), 'Could not access file in Data Package');
|
|
513
511
|
}
|
|
514
512
|
|
|
515
|
-
return fs.createReadStream(`${this.path}/raw/${
|
|
513
|
+
return fs.createReadStream(`${this.path}/raw/${file}`)
|
|
516
514
|
}
|
|
517
515
|
|
|
518
516
|
/**
|
|
@@ -532,7 +530,7 @@ export class DataPackage {
|
|
|
532
530
|
attachment?: string;
|
|
533
531
|
}): Promise<void> {
|
|
534
532
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
535
|
-
|
|
533
|
+
opts.ignore ??= false;
|
|
536
534
|
|
|
537
535
|
const uid = opts.uid ?? crypto.randomUUID();
|
|
538
536
|
|
|
@@ -544,16 +542,14 @@ export class DataPackage {
|
|
|
544
542
|
/**
|
|
545
543
|
* Add a CoT marker to the Package
|
|
546
544
|
*/
|
|
547
|
-
async addCoT(cot: CoT, opts
|
|
545
|
+
async addCoT(cot: CoT, opts?: {
|
|
548
546
|
ignore: boolean
|
|
549
|
-
} = {
|
|
550
|
-
ignore: false
|
|
551
547
|
}): Promise<void> {
|
|
552
548
|
if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
|
|
553
549
|
|
|
554
550
|
const name = cot.callsign();
|
|
555
551
|
|
|
556
|
-
this.#addContent(`${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, cot.raw.event._attributes.uid, name, opts
|
|
552
|
+
this.#addContent(`${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, cot.raw.event._attributes.uid, name, opts?.ignore);
|
|
557
553
|
await fsp.mkdir(`${this.path}/raw/${cot.raw.event._attributes.uid}/`, { recursive: true });
|
|
558
554
|
await fsp.writeFile(`${this.path}/raw/${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, CoTParser.to_xml(cot))
|
|
559
555
|
}
|
|
@@ -582,10 +578,10 @@ export class DataPackage {
|
|
|
582
578
|
const output = fs.createWriteStream(this.path + `/${this.settings.uid}.zip`)
|
|
583
579
|
archive.pipe(output);
|
|
584
580
|
output.on('close', () => {
|
|
585
|
-
|
|
581
|
+
resolve(this.path + `/${this.settings.uid}.zip`);
|
|
586
582
|
});
|
|
587
583
|
archive.directory(this.path + '/raw/', '/');
|
|
588
|
-
archive.finalize()
|
|
584
|
+
void archive.finalize()
|
|
589
585
|
});
|
|
590
586
|
}
|
|
591
587
|
}
|
|
@@ -13,11 +13,10 @@ import type {
|
|
|
13
13
|
import {
|
|
14
14
|
InputFeature,
|
|
15
15
|
} from '../types/feature.js';
|
|
16
|
-
import type { AllGeoJSON } from "@turf/helpers";
|
|
17
16
|
import TypeValidator from '../type.js';
|
|
18
17
|
import Type2525 from '../utils/2525.js';
|
|
19
18
|
import PointOnFeature from '@turf/point-on-feature';
|
|
20
|
-
import Util from '../utils/util.js';
|
|
19
|
+
import Util, { jsonClone } from '../utils/util.js';
|
|
21
20
|
import Color from '../utils/color.js';
|
|
22
21
|
import JSONCoT from '../types/types.js'
|
|
23
22
|
import CoT from '../cot.js';
|
|
@@ -39,20 +38,18 @@ export async function from_geojson(
|
|
|
39
38
|
const explicitType = typeof feature.properties?.type === 'string';
|
|
40
39
|
|
|
41
40
|
try {
|
|
42
|
-
feature =
|
|
41
|
+
feature = TypeValidator.type(InputFeature, feature, {
|
|
43
42
|
verbose: opts.verbose
|
|
44
43
|
});
|
|
45
44
|
} catch (err) {
|
|
46
|
-
throw new Err(400, null, `Validation Error: ${err}`);
|
|
45
|
+
throw new Err(400, null, `Validation Error: ${String(err)}`);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
// The type property can either be a traditional CoT Type or a numeric 2525D/2525E SIDC
|
|
50
49
|
if (feature.properties.type && Type2525.isNumericSIDCConvertable(feature.properties.type)) {
|
|
51
|
-
|
|
52
|
-
feature.properties.
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
}
|
|
50
|
+
feature.properties.milicon ??= {
|
|
51
|
+
id: feature.properties.type
|
|
52
|
+
};
|
|
56
53
|
|
|
57
54
|
feature.properties.type = Type2525.cotTypeFromNumericSIDC(feature.properties.type);
|
|
58
55
|
}
|
|
@@ -72,12 +69,12 @@ export async function from_geojson(
|
|
|
72
69
|
};
|
|
73
70
|
|
|
74
71
|
if (feature.id) {
|
|
75
|
-
cot.event._attributes.uid =
|
|
72
|
+
cot.event._attributes.uid = feature.id;
|
|
76
73
|
} else {
|
|
77
74
|
cot.event._attributes.uid = crypto.randomUUID();
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
|
|
77
|
+
cot.event.detail ??= {};
|
|
81
78
|
|
|
82
79
|
if (feature.properties.droid) {
|
|
83
80
|
cot.event.detail.uid = { _attributes: { Droid: feature.properties.droid } };
|
|
@@ -113,8 +110,8 @@ export async function from_geojson(
|
|
|
113
110
|
if (feature.properties.dest) {
|
|
114
111
|
const dest = !Array.isArray(feature.properties.dest) ? [ feature.properties.dest ] : feature.properties.dest;
|
|
115
112
|
|
|
116
|
-
cot.event.detail.marti.dest = dest.map((
|
|
117
|
-
return { _attributes: { ...
|
|
113
|
+
cot.event.detail.marti.dest = dest.map((d) => {
|
|
114
|
+
return { _attributes: { ...d } };
|
|
118
115
|
});
|
|
119
116
|
}
|
|
120
117
|
}
|
|
@@ -165,7 +162,7 @@ export async function from_geojson(
|
|
|
165
162
|
|| feature.properties.maxzoom !== undefined
|
|
166
163
|
|| feature.properties.rotate !== undefined
|
|
167
164
|
) {
|
|
168
|
-
if (!cot.event.detail.display
|
|
165
|
+
if (!cot.event.detail.display?._attributes) {
|
|
169
166
|
cot.event.detail.display = { _attributes: {} };
|
|
170
167
|
}
|
|
171
168
|
|
|
@@ -299,9 +296,9 @@ export async function from_geojson(
|
|
|
299
296
|
|
|
300
297
|
if (feature.properties.video) {
|
|
301
298
|
if (feature.properties.video.connection) {
|
|
302
|
-
const video =
|
|
299
|
+
const video = jsonClone(feature.properties.video);
|
|
303
300
|
|
|
304
|
-
const connection = video.connection;
|
|
301
|
+
const connection = jsonClone(feature.properties.video.connection);
|
|
305
302
|
delete video.connection;
|
|
306
303
|
|
|
307
304
|
cot.event.detail.__video = {
|
|
@@ -413,9 +410,7 @@ export async function from_geojson(
|
|
|
413
410
|
|
|
414
411
|
cot.event.detail.remarks = { _attributes: { }, _text: feature.properties.remarks || '' };
|
|
415
412
|
|
|
416
|
-
if (!feature.geometry) {
|
|
417
|
-
throw new Err(400, null, 'Must have Geometry');
|
|
418
|
-
} else if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) {
|
|
413
|
+
if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) {
|
|
419
414
|
throw new Err(400, null, 'Unsupported Geometry Type');
|
|
420
415
|
}
|
|
421
416
|
|
|
@@ -441,9 +436,11 @@ export async function from_geojson(
|
|
|
441
436
|
stroke.a = feature.properties['stroke-opacity'] !== undefined ? feature.properties['stroke-opacity'] * 255 : 128;
|
|
442
437
|
cot.event.detail.strokeColor = { _attributes: { value: stroke.as_32bit() } };
|
|
443
438
|
|
|
444
|
-
|
|
439
|
+
let strokeWidth = feature.properties['stroke-width'] ?? 0;
|
|
440
|
+
if (strokeWidth === 0) strokeWidth = 3;
|
|
441
|
+
feature.properties['stroke-width'] = strokeWidth;
|
|
445
442
|
cot.event.detail.strokeWeight = { _attributes: {
|
|
446
|
-
value:
|
|
443
|
+
value: strokeWidth
|
|
447
444
|
} };
|
|
448
445
|
|
|
449
446
|
if (!feature.properties['stroke-style']) feature.properties['stroke-style'] = 'solid';
|
|
@@ -455,15 +452,13 @@ export async function from_geojson(
|
|
|
455
452
|
const fill = new Color(feature.properties.fill || -1761607936);
|
|
456
453
|
fill.a = feature.properties['fill-opacity'] !== undefined ? feature.properties['fill-opacity'] * 255 : 128;
|
|
457
454
|
cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
|
|
458
|
-
} else if (feature.geometry.type === 'LineString') {
|
|
455
|
+
} else if (feature.geometry.type === 'LineString' && feature.properties.type !== 'b-m-r') {
|
|
459
456
|
// Ensure fill is fully transparent for LineStrings so that if Node treats the
|
|
460
457
|
// feature as a polygon (when first/last coordinates coincide), no fill is rendered.
|
|
461
458
|
// Exclude b-m-r (route) types as they are not user-drawn line features.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
|
|
466
|
-
}
|
|
459
|
+
const fill = new Color(feature.properties.fill || -1761607936);
|
|
460
|
+
fill.a = 0;
|
|
461
|
+
cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
|
|
467
462
|
}
|
|
468
463
|
|
|
469
464
|
if (feature.geometry.type === 'Polygon' && feature.properties.type && ELLIPSE_TYPES.has(feature.properties.type)) {
|
|
@@ -490,7 +485,7 @@ export async function from_geojson(
|
|
|
490
485
|
Style: {
|
|
491
486
|
LineStyle: {
|
|
492
487
|
color: { _text: strokeColor.as_kml() },
|
|
493
|
-
width: { _text:
|
|
488
|
+
width: { _text: strokeWidth }
|
|
494
489
|
},
|
|
495
490
|
PolyStyle: {
|
|
496
491
|
color: { _text: fillColor.as_kml() },
|
|
@@ -597,7 +592,7 @@ export async function from_geojson(
|
|
|
597
592
|
cot.event.point._attributes.hae = 0.0;
|
|
598
593
|
}
|
|
599
594
|
} else {
|
|
600
|
-
const centre = PointOnFeature(feature
|
|
595
|
+
const centre = PointOnFeature(feature);
|
|
601
596
|
cot.event.point._attributes.lon = centre.geometry.coordinates[0];
|
|
602
597
|
cot.event.point._attributes.lat = centre.geometry.coordinates[1];
|
|
603
598
|
cot.event.point._attributes.hae = 0.0;
|
|
@@ -17,9 +17,9 @@ export async function normalize_geojson(
|
|
|
17
17
|
feature: Static<typeof GeoJSONFeature>,
|
|
18
18
|
): Promise<Static<typeof Feature>> {
|
|
19
19
|
try {
|
|
20
|
-
feature =
|
|
20
|
+
feature = TypeValidator.type(GeoJSONFeature, feature);
|
|
21
21
|
} catch (err) {
|
|
22
|
-
throw new Err(400, null, `Validation Error: ${err}`);
|
|
22
|
+
throw new Err(400, null, `Validation Error: ${String(err)}`);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if (!feature.id) {
|
|
@@ -29,7 +29,7 @@ export async function normalize_geojson(
|
|
|
29
29
|
const props = feature.properties;
|
|
30
30
|
|
|
31
31
|
feature.properties = {
|
|
32
|
-
metadata: props
|
|
32
|
+
metadata: props
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (feature.geometry.type === 'Point') {
|
|
@@ -43,47 +43,42 @@ export async function normalize_geojson(
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
for (const color of ['marker-color', 'stroke', 'fill']) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
&& /^#?[0-9a-fA-F]{6}$/.test(props[color])
|
|
50
|
-
) {
|
|
51
|
-
feature.properties[color] = props[color].startsWith('#') ? props[color] : `#${props[color]}`;
|
|
46
|
+
const value = props[color];
|
|
47
|
+
if (typeof value === 'string' && /^#?[0-9a-fA-F]{6}$/.test(value)) {
|
|
48
|
+
feature.properties[color] = value.startsWith('#') ? value : `#${value}`;
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
for (const number of ['marker-opacity', 'stroke-opacity', 'stroke-width', 'fill-opacity']) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) {
|
|
60
|
-
feature.properties[number] = props[number];
|
|
53
|
+
const value = props[number];
|
|
54
|
+
if (typeof value === 'number' && value) {
|
|
55
|
+
feature.properties[number] = value;
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
// Callsign Options
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
let callsign = 'New Feature';
|
|
61
|
+
for (const key of ['callsign', 'title', 'name']) {
|
|
62
|
+
const value = props[key];
|
|
63
|
+
if (typeof value === 'string' && value) {
|
|
64
|
+
callsign = value;
|
|
68
65
|
break;
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
feature.properties.callsign = 'New Feature';
|
|
74
|
-
}
|
|
69
|
+
feature.properties.callsign = callsign;
|
|
75
70
|
|
|
76
71
|
// Remarks Options
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
let remarks = '';
|
|
73
|
+
for (const key of ['remarks', 'description']) {
|
|
74
|
+
const value = props[key];
|
|
75
|
+
if (typeof value === 'string' && value) {
|
|
76
|
+
remarks = value;
|
|
80
77
|
break;
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
feature.properties.remarks = '';
|
|
86
|
-
}
|
|
81
|
+
feature.properties.remarks = remarks;
|
|
87
82
|
|
|
88
83
|
feature.properties.time = new Date().toISOString();
|
|
89
84
|
feature.properties.start = new Date().toISOString();
|
|
@@ -100,5 +95,6 @@ export async function normalize_geojson(
|
|
|
100
95
|
coord.splice(3);
|
|
101
96
|
});
|
|
102
97
|
|
|
98
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
103
99
|
return feature as Static<typeof Feature>;
|
|
104
100
|
}
|