Files
gods-eye-view/src/layers/submarineCables/state.js
T
Sameh Khamis b86014244d fix(input): no double-click follow or zoom on the map
The globe viewer's own double-click tracked a picked entity with a
position or zoomed to one without. Layers moving onto the draw port had it
re-created one by one (data/stockFollow.js); following is a click in GEV,
so the viewer's handler is removed where the viewer is made and every
re-creation goes: earthquakes, cyclones, air quality, news, perimeters,
drone airspace, ghost maps, places, radio, cables, CCTV, ALPR, launches,
bikeshare, Local ADS-B, installations, directions, trails, data packs,
annotations, the library's view and local GeoJSON. The Cockpit's own
double-click and the draw tool's finishing double-click stay.
2026-11-14 09:10:14 -08:00

108 lines
2.6 KiB
JavaScript

import {
createCableReferenceSweepGate,
createCableOverlayPublisher,
} from './overlay.js';
import { BASE_CABLE_COLOR, BASE_LANDING_COLOR } from './policy.js';
export function createState({ sweepClock, overlayHost }) {
const state = {};
state._viewer = null;
state._enabled = false;
state._loading = false;
state._loaded = false;
state._count = 0;
state._error = null;
state._lastUpdate = null;
state._loadingLabel = '';
state._abort = null;
/** Monotonic load-ownership token; every load() start claims a new one. */
state._loadGeneration = 0;
/**
* The layer's draw sets, made at init: cable and landing lines (draped),
* pins (landing points), fills (polygons), stems and reference points.
*/
state._sets = null;
/** Set ids this layer made, for matching picks. */
state._setIds = new Set();
/** What each drawn item is, by set id then item id (picks fly to it). */
state._picks = new Map();
/** Drawn surface items, culled by their feature's reference each sweep. */
state._surfaceItems = [];
/**
* Fetched cable/landing JSON kept across disable/enable. A disable CLEARS
* the draw sets (see releaseDrawing) instead of hiding them, so a
* re-enable has to rebuild the items; the network/parse half of that
* rebuild is the expensive part users would notice, so it is cached.
*/
state._cachedCableJson = null;
state._cachedLandingJson = null;
state._referenceRecords = [];
state._clickSubscription = null;
state._preRenderRemover = null;
state._moveEndRemover = null;
state._mapStackListener = null;
/** What ground lines drape on; refined from live scene state at init. */
state._clampTo = 'both';
state._referenceLabelCount = 0;
state._referenceSweepGate = createCableReferenceSweepGate({
now: sweepClock,
});
state._overlayPublisher = createCableOverlayPublisher({ host: overlayHost });
/** Reused winner→entry scratch so a 2 Hz sweep allocates no arrays. */
state._publishScratch = [];
/**
* Last published cohort signature (ids + quantized priorities). A parked
* camera reproduces the same winners every sweep; skipping the identical
* republish keeps the host from requesting a render per publish, so the
* layer stays render-governor idle exactly like its native predecessor.
* Tip positions need no republish either: the host reprojects the same
* mutable Cartesians on every painted frame.
*/
state._lastPublishedIds = [];
state._lastPublishedPriorities = [];
state._lastPublishedCount = -1;
state.cableColor = BASE_CABLE_COLOR;
state.landingColor = BASE_LANDING_COLOR;
return state;
}