@tak-ps/node-cot 2.8.0 → 3.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/.eslintrc.json +4 -52
- package/.github/workflows/release.yml +4 -1
- package/CHANGELOG.md +8 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/{lib → dist/lib}/color.js +15 -13
- package/dist/lib/color.js.map +1 -0
- package/dist/lib/util.js +101 -0
- package/dist/lib/util.js.map +1 -0
- package/dist/lib/xml.js +171 -0
- package/dist/lib/xml.js.map +1 -0
- package/dist/test/cot.test.js +231 -0
- package/dist/test/cot.test.js.map +1 -0
- package/dist/test/from_geojson.test.js +158 -0
- package/dist/test/from_geojson.test.js.map +1 -0
- package/dist/test/util.test.js +25 -0
- package/dist/test/util.test.js.map +1 -0
- package/lib/color.ts +53 -0
- package/lib/util.ts +123 -0
- package/lib/{xml.js → xml.ts} +68 -23
- package/package.json +19 -7
- package/tsconfig.json +26 -0
- package/lib/util.js +0 -111
- package/package-lock.json +0 -2567
- /package/{index.js → index.ts} +0 -0
- /package/test/{cot.test.js → cot.test.ts} +0 -0
- /package/test/{from_geojson.test.js → from_geojson.test.ts} +0 -0
- /package/test/{util.test.js → util.test.ts} +0 -0
package/.eslintrc.json
CHANGED
|
@@ -1,54 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "eslint:recommended",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
},
|
|
7
|
-
"globals": {
|
|
8
|
-
"Map": true,
|
|
9
|
-
"Promise": true,
|
|
10
|
-
"FormData": true,
|
|
11
|
-
"Blob": true
|
|
12
|
-
},
|
|
13
|
-
"parserOptions": {
|
|
14
|
-
"ecmaVersion": 13,
|
|
15
|
-
"sourceType": "module"
|
|
16
|
-
},
|
|
17
|
-
"plugins": [ "node" ],
|
|
18
|
-
"rules": {
|
|
19
|
-
"no-console": 0,
|
|
20
|
-
"arrow-parens": [ "error", "always" ],
|
|
21
|
-
"no-var": "error",
|
|
22
|
-
"prefer-const": "error",
|
|
23
|
-
"array-bracket-spacing": [ "error", "never" ],
|
|
24
|
-
"comma-dangle": [ "error", "never" ],
|
|
25
|
-
"computed-property-spacing": [ "error", "never" ],
|
|
26
|
-
"eol-last": "error",
|
|
27
|
-
"eqeqeq": [ "error", "smart" ],
|
|
28
|
-
"indent": [ "error", 4, { "SwitchCase": 1 } ],
|
|
29
|
-
"no-confusing-arrow": [ "error", { "allowParens": false } ],
|
|
30
|
-
"no-extend-native": "error",
|
|
31
|
-
"no-mixed-spaces-and-tabs": "error",
|
|
32
|
-
"func-call-spacing": [ "error", "never" ],
|
|
33
|
-
"no-trailing-spaces": "error",
|
|
34
|
-
"no-unused-vars": "error",
|
|
35
|
-
"no-use-before-define": [ "error", "nofunc" ],
|
|
36
|
-
"object-curly-spacing": [ "error", "always" ],
|
|
37
|
-
"prefer-arrow-callback": "error",
|
|
38
|
-
"quotes": [ "error", "single", "avoid-escape" ],
|
|
39
|
-
"semi": [ "error", "always" ],
|
|
40
|
-
"space-infix-ops": "error",
|
|
41
|
-
"spaced-comment": [ "error", "always" ],
|
|
42
|
-
"keyword-spacing": [ "error", { "before": true, "after": true } ],
|
|
43
|
-
"template-curly-spacing": [ "error", "never" ],
|
|
44
|
-
"semi-spacing": "error",
|
|
45
|
-
"strict": "error",
|
|
46
|
-
"node/no-missing-require": "error",
|
|
47
|
-
"valid-jsdoc": ["error", {
|
|
48
|
-
"requireParamDescription": false,
|
|
49
|
-
"requireReturnDescription": false,
|
|
50
|
-
"requireReturnType": false,
|
|
51
|
-
"requireReturn": false
|
|
52
|
-
}]
|
|
53
|
-
}
|
|
2
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": ["@typescript-eslint"],
|
|
5
|
+
"root": true
|
|
54
6
|
}
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _color from 'color';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Helper functions for working with CoT Colours
|
|
5
4
|
*
|
|
@@ -7,40 +6,43 @@ import _color from 'color';
|
|
|
7
6
|
* @class
|
|
8
7
|
*/
|
|
9
8
|
export default class Color {
|
|
9
|
+
r;
|
|
10
|
+
g;
|
|
11
|
+
b;
|
|
12
|
+
a;
|
|
10
13
|
constructor(color) {
|
|
11
14
|
if (!isNaN(Number(color))) {
|
|
15
|
+
color = Number(color);
|
|
12
16
|
this.r = (color >> 16) & 255;
|
|
13
|
-
this.g = (color >>
|
|
17
|
+
this.g = (color >> 8) & 255;
|
|
14
18
|
this.b = (color >> 0) & 255;
|
|
15
19
|
this.a = ((color >> 24) & 255) / 255;
|
|
16
|
-
}
|
|
20
|
+
}
|
|
21
|
+
else if (Array.isArray(color)) {
|
|
17
22
|
this.a = color[0];
|
|
18
23
|
this.r = color[1];
|
|
19
24
|
this.g = color[2];
|
|
20
25
|
this.b = color[3];
|
|
21
|
-
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
22
28
|
const c = _color(color);
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.b = c.color[2];
|
|
29
|
+
this.a = c.alpha();
|
|
30
|
+
this.r = c.red();
|
|
31
|
+
this.g = c.green();
|
|
32
|
+
this.b = c.blue();
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
|
|
31
35
|
as_32bit() {
|
|
32
36
|
return (this.a << 24) | (this.r << 16) | (this.g << 8) | this.b;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
38
|
as_opacity() {
|
|
36
39
|
return this.a;
|
|
37
40
|
}
|
|
38
|
-
|
|
39
41
|
as_argb() {
|
|
40
42
|
return [this.a, this.r, this.b, this.g];
|
|
41
43
|
}
|
|
42
|
-
|
|
43
44
|
as_rgb() {
|
|
44
45
|
return [this.r, this.b, this.g];
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../lib/color.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,OAAO,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACtB,CAAC,CAAS;IACV,CAAC,CAAS;IACV,CAAC,CAAS;IACV,CAAC,CAAS;IAEV,YAAY,KAAwB;QAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;YACvB,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAEtB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC;YAC7B,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAK,CAAC,CAAC,GAAG,GAAG,CAAC;YAC7B,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;YAC5B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;SACxC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;SACrB;aAAM;YACH,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAExB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;YACjB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;SACrB;IACL,CAAC;IAED,QAAQ;QACJ,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;CACJ"}
|
package/dist/lib/util.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions for generating CoT data
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export default class Util {
|
|
7
|
+
/**
|
|
8
|
+
* Return an event._attributes object with as many defaults as possible
|
|
9
|
+
*
|
|
10
|
+
* @param type CoT Type
|
|
11
|
+
* @param how CoT how
|
|
12
|
+
* @param time Time of CoT Message - if omitted, current time is used
|
|
13
|
+
* @param start Start Time of CoT - if omitted, current time is used
|
|
14
|
+
* @param stale Expiration of CoT - if null now+20s is used. Alternative an integer representing the ms offset
|
|
15
|
+
*/
|
|
16
|
+
static cot_event_attr(type, how, time, start, stale) {
|
|
17
|
+
if (!type)
|
|
18
|
+
throw new Error('type param required');
|
|
19
|
+
if (!how)
|
|
20
|
+
throw new Error('how param required');
|
|
21
|
+
return {
|
|
22
|
+
version: Util.cot_version(),
|
|
23
|
+
uid: Util.cot_uuid(),
|
|
24
|
+
type,
|
|
25
|
+
how,
|
|
26
|
+
...Util.cot_date(time, start, stale)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return an event.detail object with as many defaults as possible
|
|
31
|
+
*
|
|
32
|
+
* @param [callsign=UNKNOWN] Display Callsign
|
|
33
|
+
*/
|
|
34
|
+
static cot_event_detail(callsign = 'UNKNOWN') {
|
|
35
|
+
return {
|
|
36
|
+
contact: {
|
|
37
|
+
_attributes: { callsign }
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generate a random UUID
|
|
43
|
+
*/
|
|
44
|
+
static cot_uuid() {
|
|
45
|
+
return randomUUID();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Return the current version number this library supports
|
|
49
|
+
*/
|
|
50
|
+
static cot_version() {
|
|
51
|
+
return '2.0';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generate Null Island CoT point object
|
|
55
|
+
*/
|
|
56
|
+
static cot_point() {
|
|
57
|
+
return {
|
|
58
|
+
'_attributes': {
|
|
59
|
+
'lat': '0.000000',
|
|
60
|
+
'lon': '0.000000',
|
|
61
|
+
'hae': '0.0',
|
|
62
|
+
'ce': '9999999.0',
|
|
63
|
+
'le': '9999999.0'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate CoT date objects
|
|
69
|
+
*
|
|
70
|
+
* cot_date() - Time: now, Start: now, Stale: now + 20s
|
|
71
|
+
*
|
|
72
|
+
* @param time Time of CoT Message - if omitted, current time is used
|
|
73
|
+
* @param start Start Time of CoT - if omitted, current time is used
|
|
74
|
+
* @param stale Expiration of CoT - if null now+20s is used. Alternative an integer representing the ms offset
|
|
75
|
+
*/
|
|
76
|
+
static cot_date(time, start, stale) {
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
if (!stale) {
|
|
79
|
+
return {
|
|
80
|
+
time: (new Date(time || now)).toISOString(),
|
|
81
|
+
start: (new Date(start || now)).toISOString(),
|
|
82
|
+
stale: (new Date(new Date(start || now).getTime() + 20 * 1000)).toISOString()
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else if (!isNaN(parseInt(String(stale)))) {
|
|
86
|
+
return {
|
|
87
|
+
time: (new Date(time || now)).toISOString(),
|
|
88
|
+
start: (new Date(start || now)).toISOString(),
|
|
89
|
+
stale: (new Date(new Date(start || now).getTime() + Number(stale))).toISOString()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return {
|
|
94
|
+
time: (new Date(time || now)).toISOString(),
|
|
95
|
+
start: (new Date(start || now)).toISOString(),
|
|
96
|
+
stale: String(stale)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../lib/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAOnC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACrB;;;;;;;;OAQG;IACH,MAAM,CAAC,cAAc,CACjB,IAAY,EACZ,GAAW,EACX,IAA2B,EAC3B,KAA4B,EAC5B,KAAqC;QAErC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,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AC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;aAChF,CAAC;SACL;aAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACxC,OAAO;gBACH,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE;gBAC3C,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE;gBAC7C,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;aACpF,CAAC;SACL;aAAM;YACH,OAAO;gBACH,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE;gBAC3C,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE;gBAC7C,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;aACvB,CAAC;SACL;IACL,CAAC;CACJ"}
|
package/dist/lib/xml.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import xmljs from 'xml-js';
|
|
2
|
+
import Util from './util.js';
|
|
3
|
+
import Color from './color.js';
|
|
4
|
+
import PointOnFeature from '@turf/point-on-feature';
|
|
5
|
+
import AJV from 'ajv';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
const ajv = (new AJV({ allErrors: true }))
|
|
8
|
+
.compile(JSON.parse(String(fs.readFileSync(new URL('./schema.json', import.meta.url)))));
|
|
9
|
+
/**
|
|
10
|
+
* Convert to and from an XML CoT message
|
|
11
|
+
* @class
|
|
12
|
+
*
|
|
13
|
+
* @param cot A string/buffer containing the XML representation or the xml-js object tree
|
|
14
|
+
*
|
|
15
|
+
* @prop raw Raw XML-JS representation of CoT
|
|
16
|
+
*/
|
|
17
|
+
export default class XMLCot {
|
|
18
|
+
raw;
|
|
19
|
+
constructor(cot) {
|
|
20
|
+
if (typeof cot === 'string' || cot instanceof Buffer) {
|
|
21
|
+
if (cot instanceof Buffer)
|
|
22
|
+
cot = String(cot);
|
|
23
|
+
const raw = xmljs.xml2js(cot, { compact: true });
|
|
24
|
+
this.raw = raw;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.raw = cot;
|
|
28
|
+
}
|
|
29
|
+
// Attempt to cast all point to numerics
|
|
30
|
+
for (const key of Object.keys(this.raw.event.point._attributes)) {
|
|
31
|
+
if (!isNaN(parseFloat(String(this.raw.event.point._attributes[key])))) {
|
|
32
|
+
this.raw.event.point._attributes[key] = parseFloat(String(this.raw.event.point._attributes[key]));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!this.raw.event._attributes.uid)
|
|
36
|
+
this.raw.event._attributes.uuid = Util.cot_uuid();
|
|
37
|
+
ajv(this.raw);
|
|
38
|
+
if (ajv.errors)
|
|
39
|
+
throw new Error(ajv.errors[0].message);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Return an XMLCot Message
|
|
43
|
+
*
|
|
44
|
+
* @param {Object} feature GeoJSON Point Feature
|
|
45
|
+
*
|
|
46
|
+
* @return {XMLCot}
|
|
47
|
+
*/
|
|
48
|
+
static from_geojson(feature) {
|
|
49
|
+
if (feature.type !== 'Feature')
|
|
50
|
+
throw new Error('Must be GeoJSON Feature');
|
|
51
|
+
if (!feature.properties)
|
|
52
|
+
throw new Error('Feature must have properties');
|
|
53
|
+
const cot = {
|
|
54
|
+
event: {
|
|
55
|
+
_attributes: Util.cot_event_attr(feature.properties.type || 'a-f-G', feature.properties.how || 'm-g', feature.properties.time, feature.properties.start, feature.properties.stale),
|
|
56
|
+
point: Util.cot_point(),
|
|
57
|
+
detail: Util.cot_event_detail(feature.properties.callsign)
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (feature.id)
|
|
61
|
+
cot.event._attributes.uid = String(feature.id);
|
|
62
|
+
if (feature.properties.callsign && !feature.id)
|
|
63
|
+
cot.event._attributes.uid = feature.properties.callsign;
|
|
64
|
+
if (!feature.geometry)
|
|
65
|
+
throw new Error('Must have Geometry');
|
|
66
|
+
if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type))
|
|
67
|
+
throw new Error('Unsupported Geometry Type');
|
|
68
|
+
if (feature.geometry.type === 'Point') {
|
|
69
|
+
cot.event.point._attributes.lon = String(feature.geometry.coordinates[0]);
|
|
70
|
+
cot.event.point._attributes.lat = String(feature.geometry.coordinates[1]);
|
|
71
|
+
}
|
|
72
|
+
else if (['Polygon', 'LineString'].includes(feature.geometry.type)) {
|
|
73
|
+
const stroke = new Color(feature.properties.stroke || -1761607936);
|
|
74
|
+
if (feature.properties['stroke-opacity'])
|
|
75
|
+
stroke.a = feature.properties['stroke-opacity'];
|
|
76
|
+
cot.event.detail.strokeColor = { _attributes: { value: stroke.as_32bit() } };
|
|
77
|
+
if (!feature.properties['stroke-width'])
|
|
78
|
+
feature.properties['stroke-width'] = 3;
|
|
79
|
+
cot.event.detail.strokeWeight = { _attributes: {
|
|
80
|
+
value: feature.properties['stroke-width']
|
|
81
|
+
} };
|
|
82
|
+
if (!feature.properties['stroke-style'])
|
|
83
|
+
feature.properties['stroke-style'] = 'solid';
|
|
84
|
+
cot.event.detail.strokeStyle = { _attributes: {
|
|
85
|
+
value: feature.properties['stroke-style']
|
|
86
|
+
} };
|
|
87
|
+
if (feature.geometry.type === 'LineString') {
|
|
88
|
+
cot.event._attributes.type = 'u-d-f';
|
|
89
|
+
cot.event.detail.link = [];
|
|
90
|
+
for (const coord of feature.geometry.coordinates) {
|
|
91
|
+
cot.event.detail.link.push({
|
|
92
|
+
_attributes: { point: `${coord[1]},${coord[0]}` }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (feature.geometry.type === 'Polygon') {
|
|
97
|
+
cot.event._attributes.type = 'u-d-r';
|
|
98
|
+
// Inner rings are not yet supported
|
|
99
|
+
cot.event.detail.link = [];
|
|
100
|
+
feature.geometry.coordinates[0].pop(); // Dont' Close Loop in COT
|
|
101
|
+
for (const coord of feature.geometry.coordinates[0]) {
|
|
102
|
+
cot.event.detail.link.push({
|
|
103
|
+
_attributes: { point: `${coord[1]},${coord[0]}` }
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const fill = new Color(feature.properties.fill || -1761607936);
|
|
107
|
+
if (feature.properties['fill-opacity'])
|
|
108
|
+
fill.a = feature.properties['fill-opacity'];
|
|
109
|
+
cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
|
|
110
|
+
}
|
|
111
|
+
cot.event.detail.labels_on = { _attributes: { value: 'false' } };
|
|
112
|
+
cot.event.detail.tog = { _attributes: { enabled: '0' } };
|
|
113
|
+
const centre = PointOnFeature(feature);
|
|
114
|
+
cot.event.point._attributes.lon = String(centre.geometry.coordinates[0]);
|
|
115
|
+
cot.event.point._attributes.lat = String(centre.geometry.coordinates[1]);
|
|
116
|
+
}
|
|
117
|
+
return new XMLCot(cot);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Return a GeoJSON Feature from an XML CoT message
|
|
121
|
+
*/
|
|
122
|
+
to_geojson() {
|
|
123
|
+
const raw = JSON.parse(JSON.stringify(this.raw));
|
|
124
|
+
if (!raw.event.detail)
|
|
125
|
+
raw.event.detail = {};
|
|
126
|
+
if (!raw.event.detail.contact)
|
|
127
|
+
raw.event.detail.contact = {};
|
|
128
|
+
if (!raw.event.detail.contact._attributes)
|
|
129
|
+
raw.event.detail.contact._attributes = {};
|
|
130
|
+
const geojson = {
|
|
131
|
+
id: raw.event._attributes.uid,
|
|
132
|
+
type: 'Feature',
|
|
133
|
+
properties: {
|
|
134
|
+
callsign: raw.event.detail.contact._attributes.callsign || 'UNKNOWN',
|
|
135
|
+
type: raw.event._attributes.type,
|
|
136
|
+
how: raw.event._attributes.how,
|
|
137
|
+
time: raw.event._attributes.time,
|
|
138
|
+
start: raw.event._attributes.start,
|
|
139
|
+
stale: raw.event._attributes.stale
|
|
140
|
+
},
|
|
141
|
+
geometry: {
|
|
142
|
+
type: 'Point',
|
|
143
|
+
coordinates: [
|
|
144
|
+
raw.event.point._attributes.lon,
|
|
145
|
+
raw.event.point._attributes.lon
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return geojson;
|
|
150
|
+
}
|
|
151
|
+
to_xml() {
|
|
152
|
+
return xmljs.js2xml(this.raw, {
|
|
153
|
+
compact: true
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Return a CoT Message
|
|
158
|
+
*
|
|
159
|
+
* @returns {XMLCot}
|
|
160
|
+
*/
|
|
161
|
+
static ping() {
|
|
162
|
+
return new XMLCot({
|
|
163
|
+
event: {
|
|
164
|
+
_attributes: Util.cot_event_attr('t-x-c-t', 'h-g-i-g-o'),
|
|
165
|
+
detail: {},
|
|
166
|
+
point: Util.cot_point()
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=xml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../../lib/xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,QAAQ,CAAC;AAG3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,cAAc,MAAM,wBAAwB,CAAC;AACpD,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,MAAM,I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