Add the Data Library: live regional datasets, tiles and packs

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.
This commit is contained in:
Said Turksever committed 2026-11-12 12:26:45 +00:00
1 parent 10a788db78
commit db80d82b8d
182 files changed
+15805 -44

No files matched your search

+26 -10
View File
@@ -120,6 +120,17 @@ const PANEL_ORDER = PANEL_GROUPS.flatMap(({ label, ids, containerId }) =>
const PANEL_POSITIONS = new Map(
PANEL_ORDER.map(({ id }, index) => [id, index]),
);
// Data Library layers follow every core group, in the order they were added.
const LIBRARY_GROUP = msg('Library');
const panelPosition = (layer) =>
layer.libraryEntryId
? PANEL_ORDER.length + 1
: (PANEL_POSITIONS.get(layer.id) ?? PANEL_ORDER.length);
const panelGroup = (layer) =>
layer.libraryEntryId
? LIBRARY_GROUP
: (PANEL_ORDER[PANEL_POSITIONS.get(layer.id)]?.label ??
msg('Other layers'));
function englishPanelLabel(layer) {
return PANEL_LABELS[layer.id] || LAYER_NAME_KEYS[layer.id] || layer.name;
@@ -372,6 +383,10 @@ export class LayerPanel {
this._groupContainers = new Map();
this._toggleContainer = null;
}
/** Rebuild the rows after the layer set changed (a Data Library add/remove). */
rerender() {
this._renderToggles();
}
_renderToggles() {
if (this._destroyed || !this._toggleContainer) return;
this._releaseBindings();
@@ -380,19 +395,13 @@ export class LayerPanel {
// its toggle and metadata.
const layers = this.getAll()
.slice()
.sort(
(a, b) =>
(PANEL_POSITIONS.get(a.id) ?? PANEL_ORDER.length) -
(PANEL_POSITIONS.get(b.id) ?? PANEL_ORDER.length),
);
.sort((a, b) => panelPosition(a) - panelPosition(b));
this._rows = [];
this._rowViews = new Map();
let previousGroup = '';
for (const layer of layers) {
if (!layer.showInTogglePanel) continue;
const group =
PANEL_ORDER[PANEL_POSITIONS.get(layer.id)]?.label ??
msg('Other layers');
const group = panelGroup(layer);
const containerId =
PANEL_ORDER[PANEL_POSITIONS.get(layer.id)]?.containerId;
const container = this._groupContainers.has(containerId)
@@ -485,6 +494,7 @@ export class LayerPanel {
id: layer.id,
// English name for voice tools, which must not receive translated text.
englishName: englishPanelLabel(layer),
libraryEntry: layer.libraryEntryId || null,
icon: layer.icon,
name: panelLabel(layer),
count: row.count ? presentLayerCount(layer.stats) : null,
@@ -504,7 +514,12 @@ export class LayerPanel {
* controls for good, and a shown info line stays.
*/
_presentControls(row, layer) {
const controls = layer.enabled ? this._rowControlsFor(layer.id) : null;
// A quiet row stays quiet while off, except Data Library rows, whose
// actions (zoom, remove) work on a layer that is off.
const controls =
layer.enabled || layer.libraryEntryId
? this._rowControlsFor(layer.id)
: null;
if (controls?.readout) {
// The row became a rail readout: its controls go for good.
row.controls = false;
@@ -580,7 +595,8 @@ export class LayerPanel {
...(live?.chips || []),
...(live?.segmented?.options || []),
].find((entry) => entry.id === chipId);
if (!chip || chip.disabled || !this.isEnabled(id)) return;
if (!chip || chip.disabled || (!this.isEnabled(id) && !chip.whileOff))
return;
if (typeof chip.onClick === 'function') chip.onClick();
else if (chip.params)
this.setLayerParams(id, chip.params, { origin: 'user' });