/**
* @module vesselSprites
* @description The map sprites of the vessel layer, as SVG data URIs: one hull
* per vessel kind (`vesselKind` in vesselTypes.js), seen from above with its
* bow up (north), and one buoy for every aid to navigation, standing upright.
*
* Every sprite is white with dark detail, drawn on the 96-unit frame of
* aircraftIcons.js (centre 48,48). The layer tints it at draw time (the
* kind's colour, white while selected), so one image serves every colour and
* state, as the aircraft glyphs do: one icon-atlas slot per shape. Hulls
* share one length and differ in shape only; widths are exaggerated so they
* read at small sizes.
*/
const VIEW = 96;
const C = VIEW / 2;
/** Raster size of every vessel sprite (px): sharp at its largest drawn size. */
export const VESSEL_SPRITE_PX = 64;
/** The hull edge: dark so a light tint still reads on light ground. */
const EDGE =
'stroke="rgba(4,18,24,0.9)" stroke-width="2.1" stroke-linejoin="round"';
/** Superstructure and deck detail: dark, so tinting leaves it dark. */
const DETAIL = 'fill="rgba(4,18,24,0.42)"';
/** Each kind's hull and detail, centred, bow toward −Y. */
const HULLS = {
// Container ship: fine bow, long parallel sides, square stern; container
// rows forward and the bridge aft.
cargo: `
`,
// Tanker: full bow, a pipe run down the centre line with its manifold
// across, the bridge aft.
tanker: `
`,
// Passenger ship or ferry: a superstructure covering nearly the whole deck.
passenger: `
`,
// High-speed craft: a catamaran, two slim bows and a square stern.
highspeed: `
`,
// Fishing vessel: a narrow hull, the wheelhouse forward and outrigger
// booms across amidships.
fishing: `
`,
// Tug, pilot or service boat: short, wide and blunt, the wheelhouse
// amidships and two towing bitts aft.
tug: `
`,
// Sailing boat: a rounded hull with its sail filled to one side.
sailing: `
`,
// Pleasure craft: a motor yacht, fine bow and a long cabin.
pleasure: `
`,
// Military, law enforcement or rescue: a patrol boat, sharp bow, a gun
// forward of the bridge.
military: `
`,
// Any other vessel: a plain hull with a deckhouse aft.
other: `
`,
};
/**
* The buoy every aid to navigation is drawn as, seen from the side: a
* flared float with a dark waterline band, a tapering body, a lantern and a
* round top-mark, centred on the frame. No halo; it is never turned.
*/
const BUOY = `
`;
const cache = new Map();
const b64 = (s) =>
typeof btoa === 'function'
? btoa(s)
: Buffer.from(s, 'utf8').toString('base64');
function sprite(key, body) {
let uri = cache.get(key);
if (!uri) {
const px = VESSEL_SPRITE_PX;
const svg = ``;
uri = 'data:image/svg+xml;base64,' + b64(svg);
cache.set(key, uri);
}
return uri;
}
/**
* The hull sprite of a vessel kind (`other` for one it does not know).
* @param {string} kind One of `VESSEL_KINDS`.
* @returns {string} SVG data URI.
*/
export function vesselSprite(kind) {
const k = HULLS[kind] ? kind : 'other';
return sprite(k, HULLS[k]);
}
/**
* The buoy sprite of every aid to navigation.
* @returns {string} SVG data URI.
*/
export function aidSprite() {
return sprite('aid', BUOY);
}