@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.ts
CHANGED
|
@@ -17,19 +17,23 @@ import type {
|
|
|
17
17
|
import {
|
|
18
18
|
InputFeature,
|
|
19
19
|
} from './types/feature.js';
|
|
20
|
-
import { normalizeBooleanAttributeValues } from './parser-normalize.js';
|
|
20
|
+
import { hasUnclosedElements, normalizeBooleanAttributeValues } from './parser-normalize.js';
|
|
21
21
|
import JSONCoT, { Detail } from './types/types.js'
|
|
22
22
|
import CoT from './cot.js';
|
|
23
23
|
import type { CoTOptions } from './cot.js';
|
|
24
24
|
import AJV from 'ajv';
|
|
25
25
|
import fs from 'fs';
|
|
26
26
|
import path from 'node:path';
|
|
27
|
-
import { fileURLToPath } from 'node:url';
|
|
28
27
|
|
|
29
|
-
const protoPath = path.join(
|
|
28
|
+
const protoPath = path.join(import.meta.dirname, 'proto', 'takmessage.proto');
|
|
30
29
|
const RootMessage = await protobuf.load(protoPath);
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
function isObject(input: unknown): input is Record<string, unknown> {
|
|
32
|
+
return typeof input === 'object' && input !== null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pkg: unknown = JSON.parse(String(fs.readFileSync(new URL('../package.json', import.meta.url))));
|
|
36
|
+
const pkgVersion = isObject(pkg) ? String(pkg.version) : 'undefined';
|
|
33
37
|
|
|
34
38
|
const checkXML = (new AJV({
|
|
35
39
|
allErrors: true,
|
|
@@ -47,33 +51,51 @@ export interface CoTParseError {
|
|
|
47
51
|
event: unknown;
|
|
48
52
|
}
|
|
49
53
|
|
|
54
|
+
interface ProtoLong {
|
|
55
|
+
toNumber: () => number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isProtoLong(input: unknown): input is ProtoLong {
|
|
59
|
+
return isObject(input) && typeof input.toNumber === 'function';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function protoTime(input: unknown): string {
|
|
63
|
+
if (!isProtoLong(input)) throw new Err(400, null, 'Invalid cotEvent Time');
|
|
64
|
+
return new Date(input.toNumber()).toISOString();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function toArray(input: unknown): unknown[] {
|
|
68
|
+
if (Array.isArray(input)) return input;
|
|
69
|
+
return [input];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function unvalidated(input: unknown): Static<typeof JSONCoT> {
|
|
73
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
74
|
+
return input as Static<typeof JSONCoT>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function stripServerFlowTags(tags: Record<string, unknown>): void {
|
|
78
|
+
for (const key of Object.keys(tags)) {
|
|
79
|
+
if (key !== '_attributes' && key.startsWith('TAK-Server')) {
|
|
80
|
+
delete tags[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
50
85
|
function resetFlowTags(cot: CoT): void {
|
|
51
|
-
const flowTags = cot.raw.event.detail?.['_flow-tags_'];
|
|
86
|
+
const flowTags: unknown = cot.raw.event.detail?.['_flow-tags_'];
|
|
52
87
|
|
|
53
|
-
if (!flowTags ||
|
|
88
|
+
if (!isObject(flowTags) || Array.isArray(flowTags)) {
|
|
54
89
|
return;
|
|
55
90
|
}
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
for (const key of Object.keys(tags)) {
|
|
59
|
-
if (key !== '_attributes' && key.startsWith('TAK-Server')) {
|
|
60
|
-
delete tags[key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
92
|
+
stripServerFlowTags(flowTags);
|
|
64
93
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
'_attributes' in flowTags
|
|
69
|
-
&& flowTags._attributes
|
|
70
|
-
&& typeof flowTags._attributes === 'object'
|
|
71
|
-
&& !Array.isArray(flowTags._attributes)
|
|
72
|
-
) {
|
|
73
|
-
stripServerFlowTags(flowTags._attributes as Record<string, unknown>);
|
|
94
|
+
if (isObject(flowTags._attributes) && !Array.isArray(flowTags._attributes)) {
|
|
95
|
+
stripServerFlowTags(flowTags._attributes);
|
|
74
96
|
}
|
|
75
97
|
|
|
76
|
-
flowTags[`NodeCoT-${
|
|
98
|
+
flowTags[`NodeCoT-${pkgVersion}`] = new Date().toISOString();
|
|
77
99
|
}
|
|
78
100
|
|
|
79
101
|
/**
|
|
@@ -100,27 +122,23 @@ const PROTO_DETAIL_ELEMENTS: Record<string, string> = Object.fromEntries(
|
|
|
100
122
|
export class CoTParser {
|
|
101
123
|
static validate(
|
|
102
124
|
cot: CoT,
|
|
103
|
-
opts
|
|
125
|
+
opts?: {
|
|
104
126
|
flow: boolean
|
|
105
|
-
} = {
|
|
106
|
-
flow: true
|
|
107
127
|
}
|
|
108
128
|
): CoT {
|
|
109
|
-
if (opts.flow === undefined) opts.flow = true;
|
|
110
|
-
|
|
111
129
|
checkXML(cot.raw);
|
|
112
130
|
if (checkXML.errors) {
|
|
113
131
|
throw new Err(400, null, `${checkXML.errors[0].message} (${checkXML.errors[0].instancePath})`);
|
|
114
132
|
}
|
|
115
133
|
|
|
116
|
-
if (opts
|
|
117
|
-
|
|
134
|
+
if (opts?.flow ?? true) {
|
|
135
|
+
cot.raw.event.detail ??= {};
|
|
118
136
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
137
|
+
const existing: unknown = cot.raw.event.detail['_flow-tags_'];
|
|
138
|
+
const flowTags = isObject(existing) ? existing : {};
|
|
139
|
+
cot.raw.event.detail['_flow-tags_'] = flowTags;
|
|
122
140
|
|
|
123
|
-
|
|
141
|
+
flowTags[`NodeCoT-${pkgVersion}`] = new Date().toISOString()
|
|
124
142
|
}
|
|
125
143
|
|
|
126
144
|
return cot;
|
|
@@ -134,32 +152,32 @@ export class CoTParser {
|
|
|
134
152
|
static async isDiff(
|
|
135
153
|
aCoT: CoT,
|
|
136
154
|
bCoT: CoT,
|
|
137
|
-
opts
|
|
138
|
-
diffMetadata:
|
|
139
|
-
diffStaleStartTime:
|
|
140
|
-
diffDest:
|
|
141
|
-
diffFlow:
|
|
155
|
+
opts?: {
|
|
156
|
+
diffMetadata: boolean,
|
|
157
|
+
diffStaleStartTime: boolean,
|
|
158
|
+
diffDest: boolean,
|
|
159
|
+
diffFlow: boolean
|
|
142
160
|
}
|
|
143
161
|
): Promise<boolean> {
|
|
144
162
|
const a = await this.to_geojson(aCoT) as Static<typeof InputFeature>;
|
|
145
163
|
const b = await this.to_geojson(bCoT) as Static<typeof InputFeature>;
|
|
146
164
|
|
|
147
|
-
if (!opts
|
|
165
|
+
if (!opts?.diffDest) {
|
|
148
166
|
delete a.properties.dest;
|
|
149
167
|
delete b.properties.dest;
|
|
150
168
|
}
|
|
151
169
|
|
|
152
|
-
if (!opts
|
|
170
|
+
if (!opts?.diffMetadata) {
|
|
153
171
|
delete a.properties.metadata;
|
|
154
172
|
delete b.properties.metadata;
|
|
155
173
|
}
|
|
156
174
|
|
|
157
|
-
if (!opts
|
|
175
|
+
if (!opts?.diffFlow) {
|
|
158
176
|
delete a.properties.flow;
|
|
159
177
|
delete b.properties.flow;
|
|
160
178
|
}
|
|
161
179
|
|
|
162
|
-
if (!opts
|
|
180
|
+
if (!opts?.diffStaleStartTime) {
|
|
163
181
|
delete a.properties.time;
|
|
164
182
|
delete a.properties.stale;
|
|
165
183
|
delete a.properties.start;
|
|
@@ -180,18 +198,22 @@ export class CoTParser {
|
|
|
180
198
|
): CoT {
|
|
181
199
|
const str = String(raw);
|
|
182
200
|
|
|
183
|
-
let parsed:
|
|
201
|
+
let parsed: unknown;
|
|
184
202
|
try {
|
|
185
|
-
parsed = xml2js(str, { compact: true })
|
|
203
|
+
parsed = xml2js(str, { compact: true });
|
|
186
204
|
} catch (err) {
|
|
187
205
|
console.error(`Failed to parse CoT XML: ${str}`);
|
|
188
206
|
throw err;
|
|
189
207
|
}
|
|
190
208
|
|
|
209
|
+
if (hasUnclosedElements(parsed)) {
|
|
210
|
+
throw new Err(400, null, 'Malformed XML: unclosed element');
|
|
211
|
+
}
|
|
212
|
+
|
|
191
213
|
normalizeBooleanAttributeValues(parsed);
|
|
192
214
|
|
|
193
215
|
const cot = new CoT(
|
|
194
|
-
parsed,
|
|
216
|
+
unvalidated(parsed),
|
|
195
217
|
opts
|
|
196
218
|
);
|
|
197
219
|
|
|
@@ -207,22 +229,28 @@ export class CoTParser {
|
|
|
207
229
|
} {
|
|
208
230
|
const str = String(raw);
|
|
209
231
|
|
|
210
|
-
let parsed:
|
|
232
|
+
let parsed: unknown;
|
|
211
233
|
try {
|
|
212
|
-
parsed = xml2js(str, { compact: true })
|
|
234
|
+
parsed = xml2js(str, { compact: true });
|
|
213
235
|
} catch (err) {
|
|
214
236
|
console.error(`Failed to parse CoT XML Document: ${str}`);
|
|
215
237
|
throw err;
|
|
216
238
|
}
|
|
217
239
|
|
|
240
|
+
if (hasUnclosedElements(parsed)) {
|
|
241
|
+
throw new Err(400, null, 'Malformed XML: unclosed element');
|
|
242
|
+
}
|
|
243
|
+
|
|
218
244
|
normalizeBooleanAttributeValues(parsed);
|
|
219
245
|
|
|
220
246
|
let events: unknown[] = [];
|
|
221
|
-
if (parsed
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
events =
|
|
247
|
+
if (isObject(parsed)) {
|
|
248
|
+
const hasEvent = Boolean(parsed.event);
|
|
249
|
+
|
|
250
|
+
if (isObject(parsed.events) && Boolean(parsed.events.event)) {
|
|
251
|
+
events = toArray(parsed.events.event);
|
|
252
|
+
} else if (hasEvent) {
|
|
253
|
+
events = toArray(parsed.event);
|
|
226
254
|
}
|
|
227
255
|
}
|
|
228
256
|
|
|
@@ -232,7 +260,7 @@ export class CoTParser {
|
|
|
232
260
|
for (const event of events) {
|
|
233
261
|
try {
|
|
234
262
|
cots.push(this.validate(
|
|
235
|
-
new CoT({ event: structuredClone(event) }
|
|
263
|
+
new CoT(unvalidated({ event: structuredClone(event) }), opts),
|
|
236
264
|
{ flow: false }
|
|
237
265
|
));
|
|
238
266
|
} catch (err) {
|
|
@@ -265,7 +293,7 @@ export class CoTParser {
|
|
|
265
293
|
version = 1,
|
|
266
294
|
opts?: SerializerOptions
|
|
267
295
|
): Promise<Uint8Array> {
|
|
268
|
-
if (version
|
|
296
|
+
if (version !== 1) throw new Err(400, null, `Unsupported Proto Version: ${version}`);
|
|
269
297
|
const ProtoMessage = RootMessage.lookupType(`atakmap.commoncommo.protobuf.v${version}.TakMessage`)
|
|
270
298
|
|
|
271
299
|
if (opts?.resetFlow) {
|
|
@@ -274,16 +302,17 @@ export class CoTParser {
|
|
|
274
302
|
|
|
275
303
|
// The spread operator is important to make sure the delete doesn't modify the underlying detail object
|
|
276
304
|
const detail = { ...cot.raw.event.detail };
|
|
277
|
-
const
|
|
305
|
+
const protoDetail: Record<string, unknown> = {
|
|
306
|
+
xmlDetail: ''
|
|
307
|
+
};
|
|
308
|
+
const msg = {
|
|
278
309
|
cotEvent: {
|
|
279
310
|
...cot.raw.event._attributes,
|
|
280
311
|
sendTime: new Date(cot.raw.event._attributes.time).getTime(),
|
|
281
312
|
startTime: new Date(cot.raw.event._attributes.start).getTime(),
|
|
282
313
|
staleTime: new Date(cot.raw.event._attributes.stale).getTime(),
|
|
283
314
|
...cot.raw.event.point._attributes,
|
|
284
|
-
detail:
|
|
285
|
-
xmlDetail: ''
|
|
286
|
-
}
|
|
315
|
+
detail: protoDetail
|
|
287
316
|
}
|
|
288
317
|
};
|
|
289
318
|
|
|
@@ -291,12 +320,13 @@ export class CoTParser {
|
|
|
291
320
|
for (key in detail) {
|
|
292
321
|
const field = PROTO_DETAIL_FIELDS[key];
|
|
293
322
|
if (field) {
|
|
294
|
-
|
|
323
|
+
const element: unknown = detail[key];
|
|
324
|
+
protoDetail[field] = isObject(element) ? element._attributes : undefined;
|
|
295
325
|
delete detail[key]
|
|
296
326
|
}
|
|
297
327
|
}
|
|
298
328
|
|
|
299
|
-
|
|
329
|
+
protoDetail.xmlDetail = js2xml({
|
|
300
330
|
...detail,
|
|
301
331
|
metadata: cot.metadata
|
|
302
332
|
}, { compact: true });
|
|
@@ -308,7 +338,7 @@ export class CoTParser {
|
|
|
308
338
|
* Return a GeoJSON Feature from an XML CoT message
|
|
309
339
|
*/
|
|
310
340
|
static async to_geojson(cot: CoT, opts: ToGeoJSONOptions = {}): Promise<Static<typeof Feature>> {
|
|
311
|
-
return
|
|
341
|
+
return to_geojson(cot, opts);
|
|
312
342
|
}
|
|
313
343
|
|
|
314
344
|
/**
|
|
@@ -321,58 +351,57 @@ export class CoTParser {
|
|
|
321
351
|
): Promise<CoT> {
|
|
322
352
|
const ProtoMessage = RootMessage.lookupType(`atakmap.commoncommo.protobuf.v${version}.TakMessage`)
|
|
323
353
|
|
|
324
|
-
|
|
325
|
-
const msg: any = ProtoMessage.decode(raw);
|
|
354
|
+
const cotEvent: unknown = ProtoMessage.decode(raw).cotEvent;
|
|
326
355
|
|
|
327
|
-
if (!
|
|
356
|
+
if (!isObject(cotEvent)) throw new Err(400, null, 'No cotEvent Data');
|
|
328
357
|
|
|
329
|
-
const detail
|
|
358
|
+
const protoDetail = isObject(cotEvent.detail) ? cotEvent.detail : {};
|
|
359
|
+
|
|
360
|
+
const detail: Record<string, unknown> = {};
|
|
330
361
|
const metadata: Record<string, unknown> = {};
|
|
331
|
-
for (const key in
|
|
362
|
+
for (const key in protoDetail) {
|
|
332
363
|
if (key === 'xmlDetail') {
|
|
333
|
-
const
|
|
364
|
+
const xmlDetail = typeof protoDetail.xmlDetail === 'string' ? protoDetail.xmlDetail : '';
|
|
365
|
+
const parsed: unknown = xml2js(`<detail>${xmlDetail}</detail>`, { compact: true });
|
|
334
366
|
normalizeBooleanAttributeValues(parsed);
|
|
335
|
-
Object.assign(detail, parsed.detail);
|
|
367
|
+
if (isObject(parsed)) Object.assign(detail, parsed.detail);
|
|
336
368
|
|
|
337
|
-
if (detail.metadata) {
|
|
338
|
-
for (const
|
|
339
|
-
|
|
369
|
+
if (isObject(detail.metadata)) {
|
|
370
|
+
for (const metadataKey in detail.metadata) {
|
|
371
|
+
const entry = detail.metadata[metadataKey];
|
|
372
|
+
metadata[metadataKey] = isObject(entry) ? entry._text : undefined;
|
|
340
373
|
}
|
|
341
374
|
delete detail.metadata;
|
|
342
375
|
}
|
|
343
|
-
} else if (key === 'group') {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
} else if (PROTO_DETAIL_ELEMENTS[key]) {
|
|
348
|
-
if (msg.cotEvent.detail[key]) {
|
|
349
|
-
detail[PROTO_DETAIL_ELEMENTS[key]] = { _attributes: msg.cotEvent.detail[key] };
|
|
350
|
-
}
|
|
376
|
+
} else if (key === 'group' && Boolean(protoDetail[key])) {
|
|
377
|
+
detail.__group = { _attributes: protoDetail[key] };
|
|
378
|
+
} else if (PROTO_DETAIL_ELEMENTS[key] && Boolean(protoDetail[key])) {
|
|
379
|
+
detail[PROTO_DETAIL_ELEMENTS[key]] = { _attributes: protoDetail[key] };
|
|
351
380
|
}
|
|
352
381
|
}
|
|
353
382
|
|
|
354
|
-
const cot = new CoT({
|
|
383
|
+
const cot = new CoT(unvalidated({
|
|
355
384
|
event: {
|
|
356
385
|
_attributes: {
|
|
357
386
|
version: '2.0',
|
|
358
|
-
uid:
|
|
359
|
-
qos:
|
|
360
|
-
time:
|
|
361
|
-
start:
|
|
362
|
-
stale:
|
|
387
|
+
uid: cotEvent.uid, type: cotEvent.type, how: cotEvent.how,
|
|
388
|
+
qos: cotEvent.qos, opex: cotEvent.opex, access: cotEvent.access,
|
|
389
|
+
time: protoTime(cotEvent.sendTime),
|
|
390
|
+
start: protoTime(cotEvent.startTime),
|
|
391
|
+
stale: protoTime(cotEvent.staleTime),
|
|
363
392
|
},
|
|
364
393
|
detail,
|
|
365
394
|
point: {
|
|
366
395
|
_attributes: {
|
|
367
|
-
lat:
|
|
368
|
-
lon:
|
|
369
|
-
hae:
|
|
370
|
-
le:
|
|
371
|
-
ce:
|
|
396
|
+
lat: cotEvent.lat,
|
|
397
|
+
lon: cotEvent.lon,
|
|
398
|
+
hae: cotEvent.hae,
|
|
399
|
+
le: cotEvent.le,
|
|
400
|
+
ce: cotEvent.ce,
|
|
372
401
|
},
|
|
373
402
|
}
|
|
374
403
|
}
|
|
375
|
-
}, opts);
|
|
404
|
+
}), opts);
|
|
376
405
|
|
|
377
406
|
cot.metadata = metadata;
|
|
378
407
|
|
package/lib/sensor.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { Position, Polygon } from './types/feature.js';
|
|
|
3
3
|
import { SensorAttributes } from './types/types.js';
|
|
4
4
|
import { sector } from '@turf/sector';
|
|
5
5
|
|
|
6
|
+
function orZero(value?: number): number {
|
|
7
|
+
const defined = value ?? 0;
|
|
8
|
+
return Number.isNaN(defined) ? 0 : defined;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export default class Sensor {
|
|
7
12
|
center: Static<typeof Position>;
|
|
8
13
|
sensor: Static<typeof SensorAttributes>;
|
|
@@ -20,15 +25,17 @@ export default class Sensor {
|
|
|
20
25
|
* `range` is a slant range so it is projected to the ground via the elevation
|
|
21
26
|
*/
|
|
22
27
|
to_geojson(): Static<typeof Polygon> | null {
|
|
23
|
-
|
|
28
|
+
const range = orZero(this.sensor.range);
|
|
29
|
+
if (range === 0) return null;
|
|
24
30
|
if (typeof this.sensor.azimuth !== 'number') return null;
|
|
25
|
-
|
|
31
|
+
const fov = orZero(this.sensor.fov);
|
|
32
|
+
if (fov === 0) return null;
|
|
26
33
|
|
|
27
|
-
const elevation = this.sensor.elevation
|
|
28
|
-
const ground =
|
|
34
|
+
const elevation = orZero(this.sensor.elevation);
|
|
35
|
+
const ground = range * Math.cos(elevation * Math.PI / 180);
|
|
29
36
|
if (ground < 1) return null;
|
|
30
37
|
|
|
31
|
-
const half =
|
|
38
|
+
const half = fov / 2;
|
|
32
39
|
|
|
33
40
|
return sector(
|
|
34
41
|
this.center,
|
package/lib/type.ts
CHANGED
|
@@ -14,11 +14,11 @@ export default class TypeValidator {
|
|
|
14
14
|
body: unknown,
|
|
15
15
|
opts?: TypeOpts
|
|
16
16
|
): Static<T> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
opts ??= {};
|
|
18
|
+
opts.verbose ??= false;
|
|
19
|
+
opts.default ??= true;
|
|
20
|
+
opts.convert ??= true;
|
|
21
|
+
opts.clean ??= true;
|
|
22
22
|
|
|
23
23
|
if (opts.default) {
|
|
24
24
|
Value.Default(type, body)
|
package/lib/types/cot-types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fsp from 'node:fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import { xml2js } from '@tak-ps/xml-js';
|
|
3
3
|
import type { Static } from '@sinclair/typebox';
|
|
4
4
|
import TypeValidator from '../utils/type.js';
|
|
5
5
|
import MilSymType, { StandardIdentity, Domain } from '../utils/2525.js';
|
|
@@ -82,7 +82,7 @@ export default class CoTTypes {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
static async load(): Promise<CoTTypes> {
|
|
85
|
-
const xml =
|
|
85
|
+
const xml = xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true })
|
|
86
86
|
|
|
87
87
|
const types = TypeValidator.type(TypeFormat, xml);
|
|
88
88
|
|
|
@@ -125,13 +125,13 @@ export default class CoTTypes {
|
|
|
125
125
|
const filtered: Set<Static<typeof AugmentedType>> = new Set();
|
|
126
126
|
|
|
127
127
|
for (const cot of this.cots.values()) {
|
|
128
|
-
if (opts.domain) {
|
|
128
|
+
if (opts.domain !== undefined) {
|
|
129
129
|
if (!cot.cot.startsWith(`${opts.domain}-`)) {
|
|
130
130
|
continue;
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
if (cot.cot
|
|
134
|
+
if (/^a-.-/.test(cot.cot)) {
|
|
135
135
|
const type = cot.cot.replace(/^a-.-/, `a-${si}-`);
|
|
136
136
|
|
|
137
137
|
filtered.add({
|
package/lib/types/feature.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
StatusAttributes,
|
|
9
9
|
ContactAttributes,
|
|
10
10
|
PrecisionLocationAttributes,
|
|
11
|
+
AddressAttributes,
|
|
11
12
|
VideoConnectionEntryAttributes,
|
|
12
13
|
MartiDestAttributes,
|
|
13
14
|
TakVersionAttributes,
|
|
@@ -213,6 +214,7 @@ export const Properties = Type.Object({
|
|
|
213
214
|
group: Type.Optional(GroupAttributes),
|
|
214
215
|
status: Type.Optional(StatusAttributes),
|
|
215
216
|
precisionlocation: Type.Optional(PrecisionLocationAttributes),
|
|
217
|
+
address: Type.Optional(AddressAttributes),
|
|
216
218
|
flow: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
217
219
|
radsensordetail: Type.Optional(FeaturePropertyRadSensorDetail),
|
|
218
220
|
chemsensordetail: Type.Optional(FeaturePropertyChemSensorDetail),
|
package/lib/types/types.ts
CHANGED
|
@@ -95,11 +95,11 @@ export const RouteInfo = Type.Object({
|
|
|
95
95
|
})
|
|
96
96
|
|
|
97
97
|
export const Emergency = Type.Object({
|
|
98
|
-
_attributes: Type.Object({
|
|
98
|
+
_attributes: Type.Optional(Type.Object({
|
|
99
99
|
cancel: Type.Optional(Type.Boolean()),
|
|
100
100
|
type: Type.Optional(Type.String())
|
|
101
|
-
}),
|
|
102
|
-
_text: Type.String()
|
|
101
|
+
})),
|
|
102
|
+
_text: Type.Optional(Type.String())
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
export const Link = Type.Object({
|
|
@@ -216,6 +216,20 @@ export const GenericNumberAttributes = Type.Object({
|
|
|
216
216
|
}))
|
|
217
217
|
})
|
|
218
218
|
|
|
219
|
+
export const Height = Type.Object({
|
|
220
|
+
_attributes: Type.Optional(Type.Object({
|
|
221
|
+
value: Type.Optional(Type.Number())
|
|
222
|
+
})),
|
|
223
|
+
_text: Type.Optional(Type.Number())
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
export const HeightUnit = Type.Object({
|
|
227
|
+
_attributes: Type.Optional(Type.Object({
|
|
228
|
+
value: Type.Optional(Type.Integer())
|
|
229
|
+
})),
|
|
230
|
+
_text: Type.Optional(Type.Integer())
|
|
231
|
+
})
|
|
232
|
+
|
|
219
233
|
export const GenericOptionalText = Type.Object({
|
|
220
234
|
_text: Type.Optional(Type.String())
|
|
221
235
|
})
|
|
@@ -779,6 +793,22 @@ export const PrecisionLocationAttributes = Type.Object({
|
|
|
779
793
|
altsrc: Type.Optional(Type.String())
|
|
780
794
|
})
|
|
781
795
|
|
|
796
|
+
export const AddressAttributes = Type.Object({
|
|
797
|
+
text: Type.String({
|
|
798
|
+
description: 'Geocoded street address shown in the ATAK point details panel'
|
|
799
|
+
}),
|
|
800
|
+
geocoder: Type.Optional(Type.String({
|
|
801
|
+
description: 'Name of the geocoder that produced the address'
|
|
802
|
+
})),
|
|
803
|
+
time: Type.Optional(Type.String({
|
|
804
|
+
description: 'Lookup time of the address'
|
|
805
|
+
})),
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
export const Address = Type.Object({
|
|
809
|
+
_attributes: AddressAttributes
|
|
810
|
+
});
|
|
811
|
+
|
|
782
812
|
export const PrecisionLocation = Type.Object({
|
|
783
813
|
_attributes: PrecisionLocationAttributes
|
|
784
814
|
})
|
|
@@ -1246,6 +1276,7 @@ export const BioSensorDetail = Type.Object({
|
|
|
1246
1276
|
export const Detail = Type.Object({
|
|
1247
1277
|
contact: Type.Optional(Contact),
|
|
1248
1278
|
tog: Type.Optional(TogAttributes),
|
|
1279
|
+
'__address': Type.Optional(Address),
|
|
1249
1280
|
'__group': Type.Optional(Group),
|
|
1250
1281
|
'__chat': Type.Optional(Chat),
|
|
1251
1282
|
'__chatreceipt': Type.Optional(Chat),
|
|
@@ -1273,6 +1304,9 @@ export const Detail = Type.Object({
|
|
|
1273
1304
|
// Controls the display of distance calculation labels on the edge of line/polygon features
|
|
1274
1305
|
labels_on: Type.Optional(GenericBooleanAttributes),
|
|
1275
1306
|
fillColor: Type.Optional(GenericIntegerAttributes),
|
|
1307
|
+
height: Type.Optional(Height),
|
|
1308
|
+
height_unit: Type.Optional(HeightUnit),
|
|
1309
|
+
extrudeMode: Type.Optional(GenericStringAttributes),
|
|
1276
1310
|
mission: Type.Optional(Mission),
|
|
1277
1311
|
shape: Type.Optional(Shape),
|
|
1278
1312
|
|