Build aircraft shapes
This commit is contained in:
@@ -11,14 +11,6 @@ import {adjustedInterval} from '@ztimson/utils';
|
||||
|
||||
const API = BASE + '/api'
|
||||
|
||||
const COLORS: Record<string, string> = {
|
||||
'cargo': '#00ff00',
|
||||
'military': '#ff0000',
|
||||
'private': '#8450ea',
|
||||
'passenger': '#009dff',
|
||||
'unknown': '#fad106',
|
||||
}
|
||||
|
||||
const SPEED_UNITS = {
|
||||
knots: { label: 'KTS', convert: (v: number) => Math.round(v) },
|
||||
kph: { label: 'KPH', convert: (v: number) => Math.round(v * 1.852) },
|
||||
@@ -58,13 +50,6 @@ function getAltColor(alt: number): [number, number, number] {
|
||||
return [Math.round(128 * r), 0, 139]
|
||||
}
|
||||
|
||||
function buildPlaneIcon(plane: any, shapes: any): string {
|
||||
const color = COLORS[plane.type] || COLORS['unknown']
|
||||
const shape = shapes[plane.aircraft?.toLowerCase()] || shapes['unknown'];
|
||||
const paths = (Array.isArray(shape.path) ? shape.path : [shape.path]).map((p: string) => `<path d="${p}" fill="${color}" stroke="#000" stroke-width="${shape.stroke || 1}"/>`).join('')
|
||||
return `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${shape.w * 2}" height="${shape.h * 2}" viewBox="${shape.viewBox}">${paths}</svg>`)}`
|
||||
}
|
||||
|
||||
function buildNavballSvg(data: any): string {
|
||||
const heading = data.heading ?? 0
|
||||
const airspeedKnots = data.speed || 0
|
||||
@@ -268,7 +253,7 @@ export class AirTrafficLayer {
|
||||
f.set('planeData', plane)
|
||||
f.setStyle(new Style({
|
||||
image: new Icon({
|
||||
src: buildPlaneIcon(plane, this.shapes),
|
||||
src: `data:image/svg+xml,${encodeURIComponent(plane.icon)}`,
|
||||
scale: 1,
|
||||
rotation: (plane.heading ?? 0) * (Math.PI / 180),
|
||||
anchor: [0.5, 0.5],
|
||||
|
||||
Reference in New Issue
Block a user