@tak-ps/node-cot 2.1.2 → 2.2.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/CHANGELOG.md CHANGED
@@ -10,6 +10,15 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v2.2.0
14
+
15
+ - :bug: Bugfixes in default values
16
+ - :bug: Ensure `to_geojson` is a function call that doesn't modify underlying message
17
+
18
+ ### v2.1.3
19
+
20
+ - :bug: Continue squashing a ton of small expectation issues to get an MVP of a point on TAK
21
+
13
22
  ### v2.1.2
14
23
 
15
24
  - :bug: Parse GeoJSON Point coords into COT
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
1
  import XML from './src/xml.js';
2
2
 
3
- export {
4
- XML
5
- };
3
+ export { XML };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tak-ps/node-cot",
3
3
  "type": "module",
4
- "version": "2.1.2",
4
+ "version": "2.2.0",
5
5
  "description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/util.js CHANGED
@@ -26,6 +26,21 @@ export default class Util {
26
26
  };
27
27
  }
28
28
 
29
+ /**
30
+ * Return an event.display object with as many defaults as possible
31
+ *
32
+ * @param {String} [callsign=UNKNOWN] Display Callsign
33
+ *
34
+ * @returns {Object}
35
+ */
36
+ static cot_event_display(callsign = 'UNKNOWN') {
37
+ return {
38
+ contact: {
39
+ _attributes: { callsign }
40
+ }
41
+ };
42
+ }
43
+
29
44
  /**
30
45
  * Generate a random UUID
31
46
  *
package/src/xml.js CHANGED
@@ -40,12 +40,16 @@ export default class XMLCot {
40
40
  if (!feature.properties) throw new Error('Feature must have properties');
41
41
 
42
42
  const cot = {
43
- 'event': {
44
- '_attributes': Util.cot_event_attr(feature.properties.type || 'a-f-G', feature.properties.how || 'm-g'),
45
- 'point': Util.cot_point()
43
+ event: {
44
+ _attributes: Util.cot_event_attr(feature.properties.type || 'a-f-G', feature.properties.how || 'm-g'),
45
+ point: Util.cot_point(),
46
+ display: Util.cot_event_display(feature.properties.callsign)
46
47
  }
47
48
  };
48
49
 
50
+ if (feature.id) cot.event._attributes.uid = feature.id;
51
+ if (feature.properties.callsign && !feature.id) cot.event._attributes.uid = feature.properties.callsign;
52
+
49
53
  for (const key of ['time', 'start', 'stale', 'type', 'how']) {
50
54
  if (feature.properties[key]) cot.event._attributes[key] = feature.properties[key];
51
55
  }
@@ -62,19 +66,27 @@ export default class XMLCot {
62
66
  * @returns {Object}
63
67
  */
64
68
  to_geojson() {
69
+ const raw = JSON.parse(JSON.stringify(this.raw));
70
+ if (!raw.event.detail) raw.event.detail = {};
71
+ if (!raw.event.detail.contact) raw.event.detail.contact = {};
72
+ if (!raw.event.detail.contact._attributes) raw.event.detail.contact._attributes = {};
73
+
65
74
  const geojson = {
66
- id: this.raw.event._attributes.uid,
75
+ id: raw.event._attributes.uid,
67
76
  type: 'Feature',
68
77
  properties: {
69
- time: this.raw.event._attributes.time,
70
- start: this.raw.event._attributes.start,
71
- stale: this.raw.event._attributes.stale
78
+ callsign: raw.event.detail.contact._attributes.callsign || 'UNKNOWN',
79
+ type: raw.event._attributes.type,
80
+ how: raw.event._attributes.how,
81
+ time: raw.event._attributes.time,
82
+ start: raw.event._attributes.start,
83
+ stale: raw.event._attributes.stale
72
84
  },
73
85
  geometry: {
74
86
  type: 'Point',
75
87
  coordinates: [
76
- this.raw.event.point._attributes.lon,
77
- this.raw.event.point._attributes.lon
88
+ raw.event.point._attributes.lon,
89
+ raw.event.point._attributes.lon
78
90
  ]
79
91
  }
80
92
  };
@@ -94,11 +106,11 @@ export default class XMLCot {
94
106
  * @returns {XMLCot}
95
107
  */
96
108
  static ping() {
97
- return {
109
+ return new XMLCot({
98
110
  event: {
99
111
  _attributes: Util.cot_event_attr('t-x-c-t', 'h-g-i-g-o'),
100
112
  point: Util.cot_point()
101
113
  }
102
- };
114
+ });
103
115
  }
104
116
  }