Skip to content

Commit ab2c706

Browse files
committed
Bidirectonal KML Color writing
1 parent 08ca606 commit ab2c706

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

lib/parser/from_geojson.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ export async function from_geojson(
357357
},
358358
Style: {
359359
LineStyle: {
360-
color: { _text: strokeColor.as_hexa().slice(1) },
360+
color: { _text: strokeColor.as_kml() },
361361
width: { _text: cot.event.detail.strokeWeight?._attributes?.value ? cot.event.detail.strokeWeight._attributes.value : 3 }
362362
},
363363
PolyStyle: {
364-
color: { _text: fillColor.as_hexa().slice(1) },
364+
color: { _text: fillColor.as_kml() },
365365
}
366366
}
367367
}

lib/utils/color.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ export default class Color {
5252
}).hexa();
5353
}
5454

55+
as_kml(): string {
56+
const a = Math.round(this.a).toString(16).padStart(2, '0');
57+
const b = Math.round(this.b).toString(16).padStart(2, '0');
58+
const g = Math.round(this.g).toString(16).padStart(2, '0');
59+
const r = Math.round(this.r).toString(16).padStart(2, '0');
60+
61+
return `${a}${b}${g}${r}`.toUpperCase();
62+
}
63+
5564
as_32bit(): number {
5665
return (this.a << 24) | (this.r << 16) | (this.g << 8) | this.b;
5766
}

test/cot-shapes.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ test.only('Basic Circle', async (t) => {
162162
labels: true,
163163
archived: true,
164164
precisionlocation: { altsrc: 'DTED0' },
165-
stroke: '#FFFF77',
166-
'stroke-opacity': 0,
165+
stroke: '#0077FF',
166+
'stroke-opacity': 1,
167167
'stroke-width': 3,
168168
'stroke-style': 'solid',
169169
'marker-color': '#FF7700',
170170
'marker-opacity': 1,
171171
'fill-opacity': 0,
172-
fill: '#00FF77',
172+
fill: '#0077FF',
173173
shape: { ellipse: { major: 185753.64687066682, minor: 185753.64687066682, angle: 360 } },
174174
metadata: {}
175175
},
@@ -264,7 +264,7 @@ test.only('Basic Circle', async (t) => {
264264
archive: { _attributes: {} },
265265
creator: { _attributes: { uid: 'ANDROID-764679f74013dfe2', callsign: 'COTAK Admin Ingalls', time: '2025-07-09T22:12:06.038Z', type: 'a-f-G-E-V-C' } },
266266
precisionlocation: { _attributes: { altsrc: 'DTED0' } },
267-
strokeColor: { "_attributes": { "value": 16777079 } },
267+
strokeColor: { "_attributes": { "value": -16746497 } },
268268
strokeWeight: { "_attributes": { "value": 3 } },
269269
labels_on: { "_attributes": { "value": true } },
270270
tog: { "_attributes": { "enabled": "0" } },

0 commit comments

Comments
 (0)