@tak-ps/node-cot 2.3.0 → 2.4.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,10 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v2.4.0
14
+
15
+ - :tada: `from_geojson(Feature.LineString)` Support
16
+
13
17
  ### v2.3.0
14
18
 
15
19
  - :tada: `from_geojson(Feature.Polygon)` Support
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tak-ps/node-cot",
3
3
  "type": "module",
4
- "version": "2.3.0",
4
+ "version": "2.4.0",
5
5
  "description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/xml.js CHANGED
@@ -55,22 +55,34 @@ export default class XMLCot {
55
55
  }
56
56
 
57
57
  if (!feature.geometry) throw new Error('Must have Geometry');
58
- if (!['Point', 'Polygon'].includes(feature.geometry.type)) throw new Error('Unsupported Geoemtry Type');
58
+ if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) throw new Error('Unsupported Geoemtry Type');
59
59
 
60
60
  if (feature.geometry.type === 'Point') {
61
61
  cot.event.point._attributes.lon = feature.geometry.coordinates[0];
62
62
  cot.event.point._attributes.lat = feature.geometry.coordinates[1];
63
- } else if (feature.geometry.type === 'Polygon') {
64
- // Inner rings are not yet supported
65
-
66
- cot.event.detail.link = [];
67
- feature.geometry.coordinates[0].pop(); // Dont' Close Loop in COT
68
- for (const coord of feature.geometry.coordinates[0]) {
69
- cot.event.detail.link.push({
70
- _attributes: {
71
- point: `${coord[1]},${coord[0]}`
72
- }
73
- });
63
+ } else if (['Polygon', 'LineString'].includes(feature.geometry.type)) {
64
+ cot.event._attributes.type = 'u-d-f';
65
+
66
+ if (feature.geometry.type === 'Polygon') {
67
+ cot.event._attributes.type = 'u-d-r';
68
+
69
+ // Inner rings are not yet supported
70
+ cot.event.detail.link = [];
71
+ feature.geometry.coordinates[0].pop(); // Dont' Close Loop in COT
72
+ for (const coord of feature.geometry.coordinates[0]) {
73
+ cot.event.detail.link.push({
74
+ _attributes: { point: `${coord[1]},${coord[0]}` }
75
+ });
76
+ }
77
+ } else if (feature.geometry.type === 'LineString') {
78
+ cot.event._attributes.type = 'u-d-f';
79
+
80
+ cot.event.detail.link = [];
81
+ for (const coord of feature.geometry.coordinates) {
82
+ cot.event.detail.link.push({
83
+ _attributes: { point: `${coord[1]},${coord[0]}` }
84
+ });
85
+ }
74
86
  }
75
87
 
76
88
  cot.event.detail.labels_on = { _attributes: { value: 'false' } };
@@ -1,7 +1,7 @@
1
1
  import test from 'tape';
2
2
  import { XML } from '../index.js';
3
3
 
4
- test('XML.from_geojson - point', (t) => {
4
+ test('XML.from_geojson - Point', (t) => {
5
5
  const geo = XML.from_geojson({
6
6
  type: 'Feature',
7
7
  properties: {},
@@ -30,7 +30,7 @@ test('XML.from_geojson - point', (t) => {
30
30
  t.end();
31
31
  });
32
32
 
33
- test('XML.from_geojson - polygon', (t) => {
33
+ test('XML.from_geojson - Polygon', (t) => {
34
34
  const geo = XML.from_geojson({
35
35
  type: 'Feature',
36
36
  properties: {},
@@ -47,7 +47,7 @@ test('XML.from_geojson - polygon', (t) => {
47
47
  });
48
48
 
49
49
  t.equals(geo.raw.event._attributes.version, '2.0');
50
- t.equals(geo.raw.event._attributes.type, 'a-f-G');
50
+ t.equals(geo.raw.event._attributes.type, 'u-d-r');
51
51
  t.equals(geo.raw.event._attributes.how, 'm-g');
52
52
  t.equals(geo.raw.event._attributes.uid.length, 36);
53
53
  t.equals(geo.raw.event._attributes.time.length, 24);
@@ -76,3 +76,51 @@ test('XML.from_geojson - polygon', (t) => {
76
76
 
77
77
  t.end();
78
78
  });
79
+
80
+ test('XML.from_geojson - LineString', (t) => {
81
+ const geo = XML.from_geojson({
82
+ type: 'Feature',
83
+ properties: {},
84
+ geometry: {
85
+ type: 'LineString',
86
+ coordinates: [
87
+ [-108.587, 39.098],
88
+ [-108.587, 39.032],
89
+ [-108.505, 39.032],
90
+ [-108.505, 39.098],
91
+ [-108.587, 39.098]
92
+ ]
93
+ }
94
+ });
95
+
96
+ t.equals(geo.raw.event._attributes.version, '2.0');
97
+ t.equals(geo.raw.event._attributes.type, 'u-d-f');
98
+ t.equals(geo.raw.event._attributes.how, 'm-g');
99
+ t.equals(geo.raw.event._attributes.uid.length, 36);
100
+ t.equals(geo.raw.event._attributes.time.length, 24);
101
+ t.equals(geo.raw.event._attributes.start.length, 24);
102
+ t.equals(geo.raw.event._attributes.stale.length, 24);
103
+
104
+ t.deepEquals(geo.raw.event.point, {
105
+ _attributes: { lat: 39.098, lon: -108.505, hae: 0, ce: 9999999, le: 9999999 }
106
+ });
107
+
108
+ t.deepEquals(geo.raw.event.detail, {
109
+ contact: { _attributes: { callsign: 'UNKNOWN' } },
110
+ link: [
111
+ { _attributes: { point: '39.098,-108.587' } },
112
+ { _attributes: { point: '39.032,-108.587' } },
113
+ { _attributes: { point: '39.032,-108.505' } },
114
+ { _attributes: { point: '39.098,-108.505' } },
115
+ { _attributes: { point: '39.098,-108.587' } }
116
+ ],
117
+ labels_on: { _attributes: { value: 'false' } },
118
+ tog: { _attributes: { enabled: '0' } },
119
+ strokeColor: { _attributes: { value: '-256' } },
120
+ strokeWeight: { _attributes: { value: '3.0' } },
121
+ strokeStyle: { _attributes: { value: 'solid' } },
122
+ fillColor: { _attributes: { value: '-1761607936' } }
123
+ });
124
+
125
+ t.end();
126
+ });