Skip to content

Commit a75dac3

Browse files
authored
Merge pull request #114 from dfpc-coe/b-m-p-s-m
Spotted Map Parsing
2 parents 67489d7 + a1b82e2 commit a75dac3

4 files changed

Lines changed: 93 additions & 2 deletions

File tree

lib/parser/from_geojson.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,18 @@ export async function from_geojson(
109109
_attributes: { type: 'Troops In Contact' },
110110
_text: feature.properties.callsign || 'UNKNOWN'
111111
}
112+
} else if (feature.properties.type === 'b-m-p-s-m') {
113+
const spot = new Color(feature.properties['marker-color'] || -1761607936);
114+
spot.a = feature.properties['marker-opacity'] !== undefined ? feature.properties['marker-opacity'] * 255 : 128;
115+
116+
cot.event.detail.usericon = {
117+
_attributes: {
118+
iconsetpath: `COT_MAPPING_SPOTMAP/b-m-p-s-m/${spot.as_32bit()}`
119+
}
120+
}
112121
}
113122

123+
114124
if (feature.properties.takv) {
115125
cot.event.detail.takv = { _attributes: { ...feature.properties.takv } };
116126
}

lib/parser/to_geojson.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
164164
feat.properties.dest = dest.length === 1 ? dest[0] : dest
165165
}
166166

167-
if (raw.event.detail.usericon && raw.event.detail.usericon._attributes && raw.event.detail.usericon._attributes.iconsetpath) {
167+
if (
168+
raw.event.detail.usericon?._attributes?.iconsetpath
169+
&& !['b-m-p-s-m'].includes(raw.event._attributes.type)
170+
) {
168171
feat.properties.icon = raw.event.detail.usericon._attributes.iconsetpath;
169172
}
170173

171-
172174
if (raw.event.detail.uid && raw.event.detail.uid._attributes && raw.event.detail.uid._attributes.Droid) {
173175
feat.properties.droid = raw.event.detail.uid._attributes.Droid;
174176
}
@@ -430,6 +432,16 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
430432
feat.properties['stroke-opacity'] = stroke.as_opacity() / 255;
431433
}
432434
}
435+
} else if (raw.event._attributes.type === 'b-m-p-s-m') {
436+
if (
437+
raw.event.detail.usericon?._attributes?.iconsetpath
438+
&& raw.event.detail.usericon._attributes.iconsetpath.startsWith('COT_MAPPING_SPOTMAP/b-m-p-s-m/')
439+
) {
440+
const spot = new Color(Number(raw.event.detail.usericon._attributes.iconsetpath.split('/')[2]));
441+
feat.properties['marker-color'] = spot.as_hex();
442+
feat.properties['marker-opacity'] = spot.as_opacity() / 255;
443+
delete feat.properties.icon;
444+
}
433445
}
434446

435447
feat.properties.metadata = cot.metadata;

test/cot-spotted.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import test from 'tape';
2+
import { CoTParser } from '../index.js';
3+
4+
test('Parse b-m-p-s-m (Spotted)', async (t) => {
5+
const cot = CoTParser.from_xml(`
6+
<event version='2.0' uid='9405e320-9356-41c4-8449-f46990aa17f8' type='b-m-p-s-m' time='2020-12-16T19:59:34.913Z' start='2020-12-16T19:59:34.913Z' stale='2021-01-02T20:40:03.841Z' how='h-g-i-g-o'>
7+
<point lat='38.85606343062312' lon='-77.0563755018233' hae='9999999.0' ce='9999999.0' le='9999999.0' />
8+
<detail>
9+
<status readiness='true'/>
10+
<archive/>
11+
<link uid='ANDROID-589520ccfcd20f01' production_time='2020-12-16T19:51:09.603Z' type='a-f-G-U-C' parent_callsign='HOPE' relation='p-p'/>
12+
<contact callsign='R 1'/>
13+
<remarks></remarks>
14+
<archive/>
15+
<color argb='-65536'/>
16+
<precisionlocation altsrc='???'/>
17+
<usericon iconsetpath='COT_MAPPING_SPOTMAP/b-m-p-s-m/-65536'/>
18+
</detail>
19+
</event>
20+
`);
21+
22+
t.deepEquals(await CoTParser.to_geojson(cot), {
23+
id: '9405e320-9356-41c4-8449-f46990aa17f8',
24+
type: 'Feature',
25+
path: '/',
26+
properties: {
27+
callsign: 'R 1',
28+
center: [ -77.0563755018233, 38.85606343062312, 9999999 ],
29+
type: 'b-m-p-s-m',
30+
how: 'h-g-i-g-o',
31+
time: '2020-12-16T19:59:34.913Z',
32+
start: '2020-12-16T19:59:34.913Z',
33+
stale: '2021-01-02T20:40:03.841Z',
34+
archived: true,
35+
status: { readiness: 'true' },
36+
precisionlocation: { altsrc: '???' },
37+
'marker-color': '#FF0000',
38+
'marker-opacity': 1,
39+
metadata: {}
40+
},
41+
geometry: {
42+
type: 'Point',
43+
coordinates: [ -77.0563755018233, 38.85606343062312, 9999999 ]
44+
},
45+
});
46+
47+
t.end();
48+
});

test/fixtures/b-m-p-s-m.geojson

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id": "123",
3+
"type": "Feature",
4+
"path": "/",
5+
"properties": {
6+
"type": "b-m-p-s-m",
7+
"how": "m-g",
8+
"callsign": "BasicTest",
9+
"marker-color": "#FFA500",
10+
"marker-opacity": 0.4,
11+
"center": [ 1.1, 2.2, 0 ],
12+
"time": "2023-08-04T15:17:43.649Z",
13+
"start": "2023-08-04T15:17:43.649Z",
14+
"stale": "2023-08-04T15:17:43.649Z",
15+
"metadata": {}
16+
},
17+
"geometry": {
18+
"type": "Point",
19+
"coordinates": [1.1, 2.2, 0]
20+
}
21+
}

0 commit comments

Comments
 (0)