mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Above the height stations draw at, the layer only said "Fly below 48 km to a covered city" without showing which cities those are. Every system in the registry now has a marker there: a green, white-ringed dot over its city, 5 km up so terrain never hides it, shown only while the layer is on and stations are not drawn. Clicking a marker flies straight down into its city from 20 km, as an explicit camera action through the shell's runNavigation, like News and the weather layers. The markers belong to the layer for picking.
134 lines
4.1 KiB
JavaScript
134 lines
4.1 KiB
JavaScript
export function createState({ services }) {
|
|
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
|
|
services.overlays;
|
|
const layerState = {};
|
|
|
|
layerState.DEFAULT_OVERLAY_HOST = Object.freeze({
|
|
setEntries: setOverlayEntries,
|
|
setVisible: setOverlaySourceVisible,
|
|
clearSource: clearOverlaySource,
|
|
});
|
|
|
|
layerState._overlayHost = layerState.DEFAULT_OVERLAY_HOST;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Module-level mutable state
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** @type {object|null} The viewer the layer draws on. */
|
|
|
|
layerState._viewer = null;
|
|
|
|
/** @type {{ refreshLayerStats?: (layerId?: string) => void }|null} Manager that repaints the layer's row. */
|
|
|
|
layerState._dataManager = null;
|
|
|
|
/** Draw set of the station dots (`drawOf(viewer).points`), or null. */
|
|
|
|
layerState._stationSet = null;
|
|
|
|
/**
|
|
* Draw set of the covered cities' markers, shown above the activation
|
|
* height so the globe says where bike share is, or null.
|
|
*/
|
|
|
|
layerState._coverageSet = null;
|
|
|
|
/** The shell's camera action for a marker's flight (`attachShellServices`), or null. */
|
|
|
|
layerState._runNavigation = null;
|
|
|
|
/** Draw set of the selected station's highlight dot, or null. */
|
|
|
|
layerState._selectedSet = null;
|
|
|
|
/** Whether the bikeshare layer is currently enabled. */
|
|
|
|
layerState._enabled = false;
|
|
|
|
/** Timer handle for camera-move debounce. */
|
|
|
|
layerState._cameraDebounceTimer = null;
|
|
|
|
/** @type {(() => void)|null} Stops the camera `changed` listener, while attached. */
|
|
|
|
layerState._cameraChangedOff = null;
|
|
|
|
/** Hysteresis flag for altitude-based activation. */
|
|
|
|
layerState._altitudeGateEnabled = false;
|
|
|
|
/** Monotonic generation counter; incremented on each proximity check to cancel stale work. */
|
|
|
|
layerState._proximityGeneration = 0;
|
|
|
|
/** @type {Set<string>} City ids currently considered in-range. */
|
|
|
|
layerState._activeCityIds = new Set();
|
|
|
|
/** @type {Map<string, { stationKeys: Set<string> }>} Per-city runtime tracking of rendered station keys. */
|
|
|
|
layerState._cityRuntime = new Map();
|
|
|
|
/** @type {Map<string, Map<string, Object>>} Cached station information per city (cityId -> stationId -> StationInfo). */
|
|
|
|
layerState._stationInfoCache = new Map();
|
|
|
|
/** @type {Map<string, { timestamp: number, statusMap: Map<string, Object> }>} Cached station status per city. */
|
|
|
|
layerState._statusCache = new Map();
|
|
|
|
/** @type {Map<string, { promise: Promise, controller: AbortController, generation: number }>} In-flight station info requests. */
|
|
|
|
layerState._inFlightInfo = new Map();
|
|
|
|
/** @type {Map<string, { promise: Promise, controller: AbortController, generation: number }>} In-flight station status requests. */
|
|
|
|
layerState._inFlightStatus = new Map();
|
|
|
|
/** @type {Map<string, Object>} Render records keyed by "cityId:stationId". */
|
|
|
|
layerState._stationRenderMap = new Map();
|
|
|
|
/** @type {(() => void)|null} Unsubscribes the station-selection click. */
|
|
|
|
layerState._clickSubscription = null;
|
|
|
|
/** @type {string|null} Key of the currently selected station, or null. */
|
|
|
|
layerState._selectedKey = null;
|
|
|
|
/** Total number of currently rendered station points. */
|
|
|
|
layerState._count = 0;
|
|
|
|
/** Timestamp (ms) of the last successful status update. */
|
|
|
|
layerState._lastUpdate = null;
|
|
|
|
/** Whether any GBFS fetch is currently in progress. */
|
|
|
|
layerState._loading = false;
|
|
|
|
/** Reference count of concurrent loading operations. */
|
|
|
|
layerState._loadingOps = 0;
|
|
|
|
/**
|
|
* @type {Set<string>} City ids whose most recent fetch failed.
|
|
*
|
|
* Per city rather than one layer-wide flag: feeds are fetched independently,
|
|
* so a retired operator must not mark a layer that other cities are still
|
|
* populating as failed. Entries are dropped when their city leaves range.
|
|
* The layer reports failure only when these cost it everything it had to
|
|
* draw, and degraded otherwise — see `getStats()` in controls.js.
|
|
*/
|
|
|
|
layerState._failedCityIds = new Set();
|
|
|
|
/** Whether the MAX_TOTAL_POINTS cap warning has already been logged. */
|
|
|
|
layerState._limitWarned = false;
|
|
return layerState;
|
|
}
|