mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
DATA LAYERS keeps its curated core layers; regional and niche sources live in the Data Library, opened from Browse data library at the foot of the panel. Each entry is a JSON manifest in src/library/entries/ pointing at a live upstream (query API, provider-hosted file or tile endpoint), so nothing is bundled and a self-hosted instance hosts no data. Sources without CORS go through one allowlisted /api/library route. Kinds: dataset (GeoJSON, CSV, JSON records, ArcGIS, partitioned GeoParquet), tiles (XYZ, WMS/ArcGIS bbox export, terrarium relief) and pack. Selections persist and travel in share links as lib=, separate from the core layer tokens. Library rows get Zoom and Remove icon chips that work while the layer is off, rendered through RailChips. Strings are translated in every locale.
96 lines
3.2 KiB
JavaScript
96 lines
3.2 KiB
JavaScript
import { LayerPanel } from '../ui/layers.js';
|
|
import { governorRequestRender } from '../renderGovernor.js';
|
|
import { markDetectionSourcesChanged } from '../data/detection.js';
|
|
|
|
/** Own the layer panel and application reactions to lifecycle activity. */
|
|
export class LayerPresentation {
|
|
constructor(
|
|
manager,
|
|
{
|
|
weatherClock,
|
|
requestRender = governorRequestRender,
|
|
invalidateDetection = markDetectionSourcesChanged,
|
|
} = {},
|
|
) {
|
|
this.manager = manager;
|
|
this.weatherClock = weatherClock;
|
|
this._panel = null;
|
|
this.pendingVisible = false;
|
|
this._unsubscribe = manager.subscribeActivity((change) => {
|
|
if (change.type === 'status') this.refresh();
|
|
else if (change.type === 'registrations') this._panel?.rerender();
|
|
else if (change.type === 'destroy-all') this.destroy();
|
|
else {
|
|
const reason =
|
|
change.type === 'data-updated'
|
|
? `layer-tick:${change.layerId}`
|
|
: change.type === 'visibility-settled'
|
|
? 'layer-visibility'
|
|
: change.type === 'params-settled'
|
|
? `layer-params:${change.layerId}`
|
|
: null;
|
|
if (!reason) return;
|
|
requestRender(reason);
|
|
if (change.type !== 'params-settled') invalidateDetection(reason);
|
|
}
|
|
});
|
|
}
|
|
get panel() {
|
|
if (!this._panel)
|
|
this._panel = new LayerPanel({
|
|
weatherClock: this.weatherClock,
|
|
getLayers: () => this.manager.getAll(),
|
|
isEnabled: (id) => this.manager.isEnabled(id),
|
|
setEnabled: (id, enabled, options) =>
|
|
this.manager.setEnabled(id, enabled, options),
|
|
setLayerParams: (id, params, options) =>
|
|
this.manager.setLayerParams(id, params, options),
|
|
getRowControls: (id) => {
|
|
const module = this.manager.layers.get(id)?.module;
|
|
try {
|
|
return module?.getRowControls?.() || null;
|
|
} catch (error) {
|
|
console.warn(`[Data] ${id} getRowControls error:`, error);
|
|
return null;
|
|
}
|
|
},
|
|
hasRowControls: (id) =>
|
|
typeof this.manager.layers.get(id)?.module?.getRowControls ===
|
|
'function',
|
|
subscribeRowControls: (id, listener) => {
|
|
const module = this.manager.layers.get(id)?.module;
|
|
module?.setRowControlsListener?.(listener);
|
|
return () => module?.setRowControlsListener?.(null);
|
|
},
|
|
onHiddenRefresh: () => {
|
|
this.pendingVisible = true;
|
|
},
|
|
});
|
|
return this._panel;
|
|
}
|
|
mount(container) {
|
|
this.panel.mount(container);
|
|
}
|
|
/** Hand the Recent Imagery readout factory to the panel (see LayerPanel). */
|
|
attachRecentImagery(factory) {
|
|
// Detaching never builds a panel that teardown already released.
|
|
if (factory) this.panel.attachRecentImagery(factory);
|
|
else this._panel?.attachRecentImagery(null);
|
|
}
|
|
refresh() {
|
|
this._panel?._refreshTogglePanel();
|
|
}
|
|
flushVisible() {
|
|
if (!this.pendingVisible) return;
|
|
this.pendingVisible = false;
|
|
this.refresh();
|
|
}
|
|
destroy() {
|
|
this._panel?.destroy();
|
|
this._panel = null;
|
|
this.pendingVisible = false;
|
|
this._unsubscribe?.();
|
|
this._unsubscribe = null;
|
|
}
|
|
}
|