Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/parser/from_geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,18 @@ export async function from_geojson(
_attributes: { type: 'Troops In Contact' },
_text: feature.properties.callsign || 'UNKNOWN'
}
} else if (feature.properties.type === 'b-m-p-s-m') {
const spot = new Color(feature.properties['marker-color'] || -1761607936);
spot.a = feature.properties['marker-opacity'] !== undefined ? feature.properties['marker-opacity'] * 255 : 128;

cot.event.detail.usericon = {
_attributes: {
iconsetpath: `COT_MAPPING_SPOTMAP/b-m-p-s-m/${spot.as_32bit()}`
}
}
}


if (feature.properties.takv) {
cot.event.detail.takv = { _attributes: { ...feature.properties.takv } };
}
Expand Down
16 changes: 14 additions & 2 deletions lib/parser/to_geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
feat.properties.dest = dest.length === 1 ? dest[0] : dest
}

if (raw.event.detail.usericon && raw.event.detail.usericon._attributes && raw.event.detail.usericon._attributes.iconsetpath) {
if (
raw.event.detail.usericon?._attributes?.iconsetpath
&& !['b-m-p-s-m'].includes(raw.event._attributes.type)
) {
feat.properties.icon = raw.event.detail.usericon._attributes.iconsetpath;
}


if (raw.event.detail.uid && raw.event.detail.uid._attributes && raw.event.detail.uid._attributes.Droid) {
feat.properties.droid = raw.event.detail.uid._attributes.Droid;
}
Expand Down Expand Up @@ -430,6 +432,16 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
feat.properties['stroke-opacity'] = stroke.as_opacity() / 255;
}
}
} else if (raw.event._attributes.type === 'b-m-p-s-m') {
if (
raw.event.detail.usericon?._attributes?.iconsetpath
&& raw.event.detail.usericon._attributes.iconsetpath.startsWith('COT_MAPPING_SPOTMAP/b-m-p-s-m/')
) {
const spot = new Color(Number(raw.event.detail.usericon._attributes.iconsetpath.split('/')[2]));
feat.properties['marker-color'] = spot.as_hex();
feat.properties['marker-opacity'] = spot.as_opacity() / 255;
delete feat.properties.icon;
}
}

feat.properties.metadata = cot.metadata;
Expand Down
48 changes: 48 additions & 0 deletions test/cot-spotted.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import test from 'tape';
import { CoTParser } from '../index.js';

test('Parse b-m-p-s-m (Spotted)', async (t) => {
const cot = CoTParser.from_xml(`
<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'>
<point lat='38.85606343062312' lon='-77.0563755018233' hae='9999999.0' ce='9999999.0' le='9999999.0' />
<detail>
<status readiness='true'/>
<archive/>
<link uid='ANDROID-589520ccfcd20f01' production_time='2020-12-16T19:51:09.603Z' type='a-f-G-U-C' parent_callsign='HOPE' relation='p-p'/>
<contact callsign='R 1'/>
<remarks></remarks>
<archive/>
<color argb='-65536'/>
<precisionlocation altsrc='???'/>
<usericon iconsetpath='COT_MAPPING_SPOTMAP/b-m-p-s-m/-65536'/>
</detail>
</event>
`);

t.deepEquals(await CoTParser.to_geojson(cot), {
id: '9405e320-9356-41c4-8449-f46990aa17f8',
type: 'Feature',
path: '/',
properties: {
callsign: 'R 1',
center: [ -77.0563755018233, 38.85606343062312, 9999999 ],
type: 'b-m-p-s-m',
how: 'h-g-i-g-o',
time: '2020-12-16T19:59:34.913Z',
start: '2020-12-16T19:59:34.913Z',
stale: '2021-01-02T20:40:03.841Z',
archived: true,
status: { readiness: 'true' },
precisionlocation: { altsrc: '???' },
'marker-color': '#FF0000',
'marker-opacity': 1,
metadata: {}
},
geometry: {
type: 'Point',
coordinates: [ -77.0563755018233, 38.85606343062312, 9999999 ]
},
});

t.end();
});
21 changes: 21 additions & 0 deletions test/fixtures/b-m-p-s-m.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": "123",
"type": "Feature",
"path": "/",
"properties": {
"type": "b-m-p-s-m",
"how": "m-g",
"callsign": "BasicTest",
"marker-color": "#FFA500",
"marker-opacity": 0.4,
"center": [ 1.1, 2.2, 0 ],
"time": "2023-08-04T15:17:43.649Z",
"start": "2023-08-04T15:17:43.649Z",
"stale": "2023-08-04T15:17:43.649Z",
"metadata": {}
},
"geometry": {
"type": "Point",
"coordinates": [1.1, 2.2, 0]
}
}
Loading