Files
gods-eye-view/src/layers/wildlifeSightings/index.js
T
Yehe LiuandClaude Opus 5.5 14f88b3e08 feat: Wildlife Sightings layer from iNaturalist and Acartia
Recent community wildlife observations, as a new Wildlife group in the
layer panel.

- Server: keyless iNaturalist proxy (v2 observations with only the
  projected fields; undocumented v1 UTFGrid density tiles, decoded on the
  server) sharing one paced queue (burst 4, ~1/s, 60/min, 8,000/day budget,
  up to four in flight), in-memory caches and upstream-only cooldowns;
  Acartia Salish Sea marine-mammal feed rounded to 0.01 degrees with
  comments dropped.
- Layer: grid counts drawn as a soft view-ranked density glow; real sampled
  sightings as taxon badges at their true positions with ambient photo
  thumbnails and labels; obscured records stay privacy cells; a clicked
  sighting stays pinned through camera moves and refreshes.
- Anchored photo card per selection with the single iNaturalist link;
  attribution in the layer row and the Data attribution popover.
- Filters (CONFIRMED, taxa presets) round-trip in share links with token 9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 16:17:12 -05:00

131 lines
3.3 KiB
JavaScript

import * as Cesium from 'cesium';
import { horizonOccluder } from '../../data/iconOrientation.js';
import { createPhotoSlots } from './photos.js';
import { createRendering } from './rendering.js';
import { createSelection } from './selection.js';
import { createControls } from './controls.js';
import { createLifecycle } from './lifecycle.js';
/** Compose recent wildlife observations without acquiring data at construction. */
export function createWildlifeSightingsLayer({
source,
overlayHost = null,
screenSpaceEventHandlerFactory = null,
picking = null,
pointer = null,
sprites = null,
badgeSprites = null,
render = null,
context = null,
focus = null,
groundFloor = null,
now = () => Date.now(),
setTimer = (fn, delay) => setTimeout(fn, delay),
clearTimer = (timer) => clearTimeout(timer),
requestIdleCallback,
cancelIdleCallback,
imageFactory,
eventTarget = globalThis.window,
cesium = Cesium,
project = (scene, position) =>
Cesium.SceneTransforms.worldToWindowCoordinates(scene, position),
occluderFactory = horizonOccluder,
} = {}) {
if (typeof source?.getSnapshot !== 'function')
throw new TypeError('Wildlife sightings require a snapshot source');
const state = {
viewer: null,
enabled: false,
destroyed: false,
manager: null,
request: null,
background: null,
cameraTimer: null,
removeCamera: null,
removeContext: null,
clickHandler: null,
rows: new Map(),
renderedRows: [],
rowById: new Map(),
points: null,
pointById: new Map(),
positions: new Map(),
cells: [],
staging: null,
selectedId: null,
selectedRow: null,
carriers: new Map(),
contextIds: new Set(),
publishingContext: false,
ambientIds: [],
ambientRows: [],
confirmed: false,
taxa: 'all',
drawnParams: null,
pendingParams: null,
failedParams: null,
controlsListener: null,
lastUpdate: null,
error: null,
stale: false,
loading: false,
gridCells: [],
gridParams: null,
gridAvailable: false,
gridTotal: 0,
labelRows: [],
query: null,
band: null,
lastQueryKey: null,
retryAt: 0,
failures: 0,
};
const parts = {};
const services = {
source,
overlayHost,
screenSpaceEventHandlerFactory,
picking,
pointer,
sprites,
badgeSprites,
render,
context,
focus,
groundFloor,
now,
setTimer,
clearTimer,
requestIdleCallback,
cancelIdleCallback,
eventTarget,
cesium,
project,
occluderFactory,
};
const owner = { state, services, parts };
parts.photos = createPhotoSlots({
imageFactory,
now,
setTimer,
clearTimer,
onChange() {
if (!state.enabled) return;
parts.selection.publishAmbient();
},
});
parts.rendering = createRendering(owner);
parts.selection = createSelection(owner);
parts.controls = createControls(owner);
parts.lifecycle = createLifecycle(owner);
return Object.assign({}, parts.controls.methods, parts.lifecycle.methods, {
selectSighting: parts.selection.selectAndFocus,
clearSightingSelection: parts.selection.clearAndRebuild,
subscribeSelection: parts.selection.subscribe,
/** Return the current surface anchor for a retained observation. */
getSightingPosition(id) {
return state.positions.get(id) || null;
},
});
}