Skip to content

Commit 08ca606

Browse files
committed
Get User Drawn tests passing
1 parent 7255587 commit 08ca606

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

lib/parser/to_geojson.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,27 +376,35 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
376376
&& raw.event.detail.shape.link?.Style
377377
) {
378378
if (raw.event.detail.shape.link.Style.LineStyle?.color) {
379-
const rawColor = raw.event.detail.shape.link.Style.LineStyle.color._text.startsWith('#')
380-
? raw.event.detail.shape.link.Style.LineStyle.color._text
381-
: '#' + raw.event.detail.shape.link.Style.LineStyle.color._text;
379+
let rawColor = raw.event.detail.shape.link.Style.LineStyle.color._text;
380+
if (rawColor.startsWith('#')) rawColor = rawColor.substring(1);
382381

383-
const strokeColor = new Color(rawColor);
382+
const a = parseInt(rawColor.substring(0, 2), 16);
383+
const b = parseInt(rawColor.substring(2, 4), 16);
384+
const g = parseInt(rawColor.substring(4, 6), 16);
385+
const r = parseInt(rawColor.substring(6, 8), 16);
386+
387+
const strokeColor = new Color([a, r, g, b]);
384388
feat.properties.stroke = strokeColor.as_hex();
385389

386-
feat.properties['stroke-opacity'] = strokeColor.as_opacity();
390+
feat.properties['stroke-opacity'] = strokeColor.as_opacity() / 255;
387391
}
388392

389393
if (raw.event.detail.shape.link.Style.LineStyle?.width) {
390394
feat.properties['stroke-width'] = Number(raw.event.detail.shape.link.Style.LineStyle.width._text);
391395
}
392396

393397
if (raw.event.detail.shape.link.Style.PolyStyle?.color) {
394-
const rawColor = raw.event.detail.shape.link.Style.PolyStyle.color._text.startsWith('#')
395-
? raw.event.detail.shape.link.Style.PolyStyle.color._text
396-
: '#' + raw.event.detail.shape.link.Style.PolyStyle.color._text;
398+
let rawColor = raw.event.detail.shape.link.Style.PolyStyle.color._text;
399+
if (rawColor.startsWith('#')) rawColor = rawColor.substring(1);
400+
401+
const a = parseInt(rawColor.substring(0, 2), 16);
402+
const b = parseInt(rawColor.substring(2, 4), 16);
403+
const g = parseInt(rawColor.substring(4, 6), 16);
404+
const r = parseInt(rawColor.substring(6, 8), 16);
397405

398-
const fillColor = new Color(rawColor);
399-
feat.properties['fill-opacity'] = fillColor.as_opacity();
406+
const fillColor = new Color([a, r, g, b]);
407+
feat.properties['fill-opacity'] = fillColor.as_opacity() / 255;
400408
feat.properties['fill'] = fillColor.as_hex();
401409
}
402410
}

test/cot-user-draw.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ test('Parse u-d-c-c (Circle - Transparent)', async (t) => {
8585
precisionlocation: {
8686
altsrc: 'DTED2'
8787
},
88-
stroke: '#FFFF77',
89-
'stroke-opacity': 0,
88+
stroke: '#0077FF',
89+
'stroke-opacity': 1,
9090
'stroke-width': 3,
9191
'stroke-style': 'solid',
9292
'fill-opacity': 0,
93-
fill: '#00FF77',
93+
fill: '#0077FF',
9494
shape: {
9595
ellipse: {
9696
major: 2535.9708862816324,
@@ -263,12 +263,12 @@ test('Parse u-d-c-c (Circle - Filled)', async (t) => {
263263
precisionlocation: {
264264
altsrc: 'DTED2'
265265
},
266-
stroke: '#FFFF77',
267-
'stroke-opacity': 0,
266+
stroke: '#0077FF',
267+
'stroke-opacity': 1,
268268
'stroke-width': 3,
269269
'stroke-style': 'solid',
270-
'fill-opacity': 0,
271-
fill: '#FFFF77',
270+
'fill-opacity': 1,
271+
fill: '#0077FF',
272272
shape: {
273273
ellipse: {
274274
major: 2908.096601511143,

0 commit comments

Comments
 (0)