mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Brings in the wildlife sightings layer (#1591, iNaturalist and Acartia sightings). Its badges, density glow and privacy cells draw through the draw port: the badges and the glow are icons sets (iconCollection.js batches point writes into one upsert per task), and the privacy cells are ground-clamped shapes and lines sets swapped whole. The eye, the view rectangle, clicks, projection, ground readiness and frames come from the camera, query, input, globe and frame ports, so the layer, its card and its placement no longer import Cesium. Differences from main: the density glow is drawn as pixel-sized splats (56 px) instead of metre-sized ones with a near fade; the card's pan eases with cubicOut, the contract's nearest ease-out; ground heights are resampled when the globe's load progress settles or its surface changes, rather than on tileset load events. Also fixes two things the last merge left: a double-click that starts on the followed track and ends off it reaches the renderer's own follow again (a press that cannot end a double-click on the track gives its hold back at its release), and the Active Fires heat drapes under the weather imagery, so weather turned on after it stacks above. CURRENT-STATE notes that the 2D and Columbus scene-mode checks are gone.
113 lines
3.4 KiB
JavaScript
113 lines
3.4 KiB
JavaScript
/**
|
|
* Drapes the Active Fires heat raster over the globe as one full-extent
|
|
* image on the renderer's imagery (`globe.imagery`, the globe port), like
|
|
* the wind layer's scalar field. It drapes on whatever the map stack draws
|
|
* (the globe's surface, or the 3D tiles). Owns the canvas and the imagery
|
|
* layer; nothing else in the fires layer touches imagery.
|
|
*
|
|
* `show` is only for the layer being on or off. The zoom hand-off fades
|
|
* `alpha` instead: a renderer may unmap a hidden imagery layer from the
|
|
* surface and re-map it when shown, so a show toggle at the band edge left
|
|
* a beat with neither markers nor heat. At alpha 0 the layer stays mapped
|
|
* and costs no draw.
|
|
*/
|
|
|
|
const WORLD = Object.freeze({ west: -180, south: -90, east: 180, north: 90 });
|
|
|
|
/**
|
|
* Drawn over the port's other imagery (zOrder 0) and under the weather
|
|
* layers (`WEATHER_IMAGERY_Z` starts at 1), so weather turned on after the
|
|
* heat stacks above it, as each weather frame went on top of the stack.
|
|
*/
|
|
export const HEAT_IMAGERY_Z = 0.5;
|
|
|
|
const defaultCanvas = (width, height) => {
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
return canvas;
|
|
};
|
|
|
|
/**
|
|
* @param {object} options
|
|
* @param {() => {globe: object|null, kind: string}|null} options.getHost
|
|
* Where draped imagery goes now: the renderer's globe port, and the kind
|
|
* of surface the active map stack drapes on (`'none'`: nothing to drape
|
|
* on, so nothing is draped).
|
|
* @param {(width: number, height: number) => object} [options.createCanvas]
|
|
*/
|
|
export function createHeatImagery({ getHost, createCanvas = defaultCanvas }) {
|
|
let raster = null;
|
|
let layer = null;
|
|
/** The host the layer is draped on: its globe port and kind. */
|
|
let globe = null;
|
|
let kind = 'none';
|
|
let show = true;
|
|
let opacity = 1;
|
|
|
|
const hostNow = () => {
|
|
const host = getHost?.();
|
|
return host?.globe && host.kind !== 'none'
|
|
? host
|
|
: { globe: null, kind: 'none' };
|
|
};
|
|
|
|
function detach() {
|
|
layer?.remove();
|
|
layer = null;
|
|
globe = null;
|
|
kind = 'none';
|
|
}
|
|
|
|
function attach() {
|
|
detach();
|
|
if (!raster) return;
|
|
const host = hostNow();
|
|
if (!host.globe) return;
|
|
const canvas = createCanvas(raster.width, raster.height);
|
|
const ctx = canvas.getContext('2d');
|
|
const image = ctx.createImageData(raster.width, raster.height);
|
|
image.data.set(raster.rgba);
|
|
ctx.putImageData(image, 0, 0);
|
|
layer = host.globe.imagery.add({
|
|
kind: 'single-image',
|
|
url: canvas.toDataURL('image/png'),
|
|
rectangle: WORLD,
|
|
zOrder: HEAT_IMAGERY_Z,
|
|
});
|
|
globe = host.globe;
|
|
kind = host.kind;
|
|
layer.show = show;
|
|
layer.alpha = opacity;
|
|
}
|
|
|
|
return {
|
|
setRaster(next) {
|
|
raster = next;
|
|
attach();
|
|
},
|
|
/** True once a raster was handed over (painted or waiting for a host). */
|
|
hasRaster() {
|
|
return raster !== null;
|
|
},
|
|
setShow(value) {
|
|
show = Boolean(value);
|
|
if (layer) layer.show = show;
|
|
},
|
|
/** Hand-off fade, 0..1; the layer stays mapped at 0. */
|
|
setOpacity(value) {
|
|
opacity = Math.min(1, Math.max(0, Number(value) || 0));
|
|
if (layer) layer.alpha = opacity;
|
|
},
|
|
/** Drape again when the map stack's surface has changed. */
|
|
rehome() {
|
|
const host = hostNow();
|
|
if (host.globe !== globe || host.kind !== kind) attach();
|
|
},
|
|
destroy() {
|
|
detach();
|
|
raster = null;
|
|
},
|
|
};
|
|
}
|