@ruckc/truss-ol 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,7 +46,9 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
46
46
  | Prop | Purpose |
47
47
  | --- | --- |
48
48
  | `center` (bindable), `zoom` (bindable), `minZoom`, `maxZoom` | The view. `center` is `[lon, lat]`; zoom limits default to 1 and 19. |
49
- | `basemap` | `'osm'`, `'none'` (themed graticule, works offline), `{ url, attribution?, maxZoom? }` or `{ osm: true, attribution?, maxZoom? }`. |
49
+ | `basemap` | `'osm'`, `'none'` (themed graticule, works offline), `{ url, attribution?, maxZoom?, minZoom?, opacity?, themed? }`, `{ osm: true, attribution?, maxZoom?, opacity?, themed? }`, or a stack `{ layers: [...], themed? }` drawn bottom to top. See [Basemaps](#basemaps). |
50
+ | `basemaps`, `basemapId` (bindable), `onbasemapchange` | A list of `{ id, label?, ...basemap }` (`{ none: true }` for the graticule) with a switcher in the toolbar; wins over `basemap`. |
51
+ | `layers` | Data layers, each a managed vector layer: `{ id, geojson \| source \| loader, style?, simplestyle?, visible?, zIndex?, interactive?, label?, opacity?, declutter?, onload? }[]`. See [Layers](#layers). |
50
52
  | `markers` | `{ id, lon, lat, label?, description?, kind?, colors?, radius?, stroke? }[]`. Invalid coordinates are skipped. |
51
53
  | `geojson` | A GeoJSON Feature or FeatureCollection. |
52
54
  | `points` | A large point set: `{ lon, lat, ...properties }[]` or a GeoJSON FeatureCollection of points. |
@@ -60,6 +62,7 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
60
62
  | `onviewchange`, `extent` (bindable) | `onviewchange({ center, zoom, extent })` fires on `moveend`, including a load-time fit that moved the view, but never for the starting view (`center`/`zoom`, `initialView`); `extent` is `[west, south, east, north]`. `bind:extent` is a read-only output that holds the starting view too. Neither fires when the view did not change, so applying `center`/`zoom` does not loop. |
61
63
  | `initialView` | Where the map starts, applied before anything is reported: `{ center: [lon, lat], zoom }` or `{ extent: [west, south, east, north], padding?, maxZoom? }` (fitted once the container has a size). Wins over `center`/`zoom`; `fitOnLoad` wins over it when there is data. Read once, on mount. |
62
64
  | `controls`, `fitTarget`, `onfit` | `controls={{ zoom: false }}` / `{{ fit: false }}` hide built-in buttons (both show by default; the `toolbar` snippet always shows); `{{ locate: true }}` adds "Show my location". `fitTarget` (anything `fit()` takes, or a function returning it) is "the data" for the fit button, `fitOnLoad`, `fitOnDataChange`, `refitOnResize` and `fit()`; by default the markers, GeoJSON, points and `trussInteractive` layers. `onfit` replaces what the fit button does. |
65
+ | `controls`, `fitTarget`, `onfit` | `controls={{ zoom: false }}` / `{{ fit: false }}` / `{{ basemap: false }}` hide built-in buttons (all show by default, the basemap switcher once `basemaps` lists two or more; the `toolbar` snippet always shows). `fitTarget` (anything `fit()` takes, or a function returning it) is "the data" for the fit button, `fitOnLoad`, `fitOnDataChange`, `refitOnResize` and `fit()`; by default the markers, GeoJSON, points and `trussInteractive` layers. `onfit` replaces what the fit button does. |
63
66
  | `attribution` | `{ collapsed: false }` (default, expanded), `true`, or `'auto'`: collapsed while the map is narrower than 640px (the map's width, not the viewport's; a reader's own open/close stands until the map crosses 640px). The scale line always stacks above the attribution's measured height. |
64
67
  | `variant` | `'bare'`: no border, no radius, and the full height of its container unless `height` is set (an edge-to-edge map). |
65
68
  | `selected` (bindable), `onselect` | Selection of a marker, GeoJSON feature or point (or a feature of a `trussInteractive` layer, see below), by click or keyboard. `onselect` and `featurePopup` receive the `geometryType` (`Point`, `Polygon`, ...). |
@@ -71,10 +74,72 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
71
74
  | `height`, `onready` | Map height: px or any CSS length (`'100%'`, `'calc(100dvh - 56px)'`), server-rendered as a nonced rule (no `style` attribute); `onready(api)` receives `{ map, fit, setView, getView, updateSize, select, openPopup, closePopup, finishDrawing, abortDrawing, undoLastPoint }`. |
72
75
 
73
76
  Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`, `select(layer, id)`, `openPopup(lonLat, options)`, `closePopup()`, `finishDrawing()`, `abortDrawing()`, `undoLastPoint()`.
77
+ | `height`, `onready` | Map height: px or any CSS length (`'100%'`, `'calc(100dvh - 56px)'`), server-rendered as a nonced rule (no `style` attribute); `onready(api)` receives `{ map, fit, setView, getView, updateSize, select, layer, reloadLayer }`. |
78
+
79
+ Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`, `select(layer, id)`, `layer(id)` (the OpenLayers layer of a `layers` entry), `reloadLayer(id)`.
80
+
81
+ ### Layers
82
+
83
+ Each `layers` entry is an OpenLayers vector layer the Map creates and keeps in step with the list, matched by `id`: only what changed is applied, so an unchanged layer (and its features) is never rebuilt. Features come from `geojson` (lon/lat, replaced when you pass a new object), your own `source` (EPSG:3857; never cleared), or a bbox `loader`. Feature ids are the GeoJSON `id`, else `properties.id`, else the index.
84
+
85
+ - **Style:** `style` is a `FeatureStyle` for every feature or `(properties, { id, type }) => FeatureStyle`. A feature's own `style` object and simplestyle properties win over it (`simplestyle: false` turns that off); whatever neither sets takes the theme tokens.
86
+ - **Order and visibility:** `zIndex` defaults to `30 + index` (above the built-in GeoJSON, points and markers; later entries on top); `visible`, `opacity`, `declutter` (read when the layer is created) and `label` (kept as the OpenLayers layer's `label` property, for your layer list).
87
+ - **Selection:** layers are `interactive` by default: click, hover, Enter/Shift+Enter, `onselect` (`layer: id`), `select(id, featureId)`, the popup and the default fit all include them. `interactive: false` leaves a layer out of hit testing (the fit still covers it while visible).
88
+ - **Loader:** `loader({ bbox, zoom, signal })` is called after the map moves (debounced 250ms) with the view padded by a quarter, unless the last answer covered the view. Resolve to GeoJSON, or `{ geojson, truncated: true }` when the box held more than you sent (the next move loads again). A request the view outran is aborted (`signal`) and its answer ignored. `onload({ loading, count, truncated, error? })` reports progress; `reloadLayer(id)` loads again now.
89
+ - Pass a plain array (or `$state.raw`), as for `geojson`; each entry's own fields are still watched, so a change inside a `$state` list applies too.
90
+
91
+ ```svelte
92
+ <Map {layers} onselect={(s) => s?.type === 'feature' && openFeature(s.layer, s.id)} />
93
+ <script>
94
+ const layers = $derived(appLayers.map((l, i) => ({
95
+ id: l.id, label: l.name, visible: l.visible, zIndex: 100 - i,
96
+ style: (p) => ({ markerColor: l.color, stroke: l.color, fill: l.color, opacity: 0.25, label: l.labelProperty && p[l.labelProperty] }),
97
+ ...(l.count > 5000
98
+ ? { loader: ({ bbox, signal }) => fetchFeatures(l.id, { bbox, signal }).then((r) => ({ geojson: r.collection, truncated: r.hasMore })), onload: (s) => (loadState[l.id] = s) }
99
+ : { geojson: l.features })
100
+ })));
101
+ </script>
102
+ ```
103
+
104
+ ### Styles and simplestyle
105
+
106
+ `propertyStyle(properties)` reads [simplestyle-spec 1.1](https://github.com/mapbox/simplestyle-spec): `marker-color`, `marker-size` (`small` 5px, `medium` 7px, `large` 10px radius, or a radius in px), `marker-symbol`, `stroke`, `stroke-width`, `stroke-opacity`, `fill`, `fill-opacity`, and `title` as the label. Points use `marker-color` (then `fill`). The spec's grey defaults are not applied: what a feature leaves out takes the layer style, then the theme.
107
+
108
+ `marker-symbol` is drawn as text inside the marker when it is one or two characters (a letter, a digit, an emoji) or a number up to 999, in black or white for contrast (the `on-primary` token on the default marker); the marker grows to a 9px radius to hold it. Maki icon names (`rail`, `cafe`) are not drawn, because no icon set is bundled: draw those with your own `ol/style` icon in a style of your own.
109
+
110
+ For layers you build yourself, the same builder is exported from `@ruckc/truss-ol/ol-style` (it imports `ol`, so load it from client-only code; the Map loads it lazily):
111
+
112
+ ```ts
113
+ import { createFeatureStyle, createOlStyle, readMapTokens } from '@ruckc/truss-ol/ol-style';
114
+ import { onThemeChange } from '@ruckc/truss-ui';
115
+
116
+ const style = createFeatureStyle({ style: { markerColor: '#d33' }, tokens: () => readMapTokens(el), selected: (f) => f.getId() === sel });
117
+ layer.setStyle(style); // the Map's look: tokens, selection halo, labels, simplestyle, cached per look
118
+ onThemeChange(el, () => { style.reset(); layer.changed(); });
119
+ createOlStyle({ markerColor: '#d33', symbol: 'A', label: 'Depot' }, { geometryType: 'Point', selected: true, tokens }); // Style[]
120
+ ```
121
+
122
+ ### Basemaps
123
+
124
+ ```svelte
125
+ <script>
126
+ import { Map, esriBasemaps } from '@ruckc/truss-ol';
127
+ let basemapId = $state(localStorage.getItem('basemap') ?? 'esri-streets');
128
+ </script>
129
+ <Map basemaps={[esriBasemaps.streets, esriBasemaps.imagery, esriBasemaps.hybrid, esriBasemaps.topo]} bind:basemapId
130
+ onbasemapchange={(id) => localStorage.setItem('basemap', id)} />
131
+ ```
132
+
133
+ - **Stacks:** `{ layers: [{ url, attribution?, maxZoom?, minZoom?, opacity?, themed? }, ...] }` draws its layers bottom to top: imagery first, then label or boundary overlays. Changing `basemap` swaps only the tile layers (identical tiles are kept); the map and the view stay.
134
+ - **Switcher:** with two or more `basemaps`, a layers button in the toolbar opens a menu of them (checkable items, arrow keys, Enter, Escape returns focus). Names come from `label`, else `MapLabels.basemapName(id)` (which names the presets, `osm` and `none`); its accessible name is `MapLabels.basemap`. Hide it with `controls={{ basemap: false }}`. `basemapId` unset or unknown shows the first entry.
135
+ - **Dark mode (`themed`):** in dark mode a themed tile layer is inverted and hue-rotated to match the theme. Only OpenStreetMap tiles (`'osm'`, `{ osm: true }`) are themed by default; tile URLs, stacks and the Esri presets are not, so aerial imagery and hillshades keep their real colours. Set `themed: true` on a basemap, a stack, or one layer of a stack (a layer's own value wins). Unthemed layers carry the `tr-basemap-plain` class.
136
+ - **Esri presets:** `esriBasemaps.imagery` (World_Imagery), `.streets` (World_Street_Map), `.topo` (World_Topo_Map) and `.hybrid` (World_Imagery under Reference/World_Boundaries_and_Places, also exported alone as `esriLabels`), each with the credits Esri's service publishes ("Powered by Esri" and the data sources). They are `basemaps` entries, and each also works as `basemap`. Override `id`, `label` or the layers by spreading: `{ ...esriBasemaps.imagery, id: 'imagery', label: t('Imagery') }`.
137
+
138
+ **Esri's terms.** These tiles are Esri's, under Esri's terms (the Esri Master License Agreement and the ArcGIS Online terms of use linked from each service, e.g. https://goto.arcgisonline.com/maps/World_Imagery), not under this package's MIT licence. They load without an API key, but whether your use is allowed (commercial use, volume, whether you need an ArcGIS account) is for you to check with Esri. Keep the attribution visible, and do not bulk-download or cache the tiles for offline use (Esri publishes separate export services for that).
74
139
 
75
140
  ### Your own layers
76
141
 
77
- Layers your app adds through `onready(api) → api.map` are left alone: clicks, the pointer cursor, the tooltip and keyboard selection only see the
142
+ Prefer `layers` (below), which the Map creates, styles and hit-tests for you. Layers your app adds through `onready(api) → api.map` are left alone: clicks, the pointer cursor, the tooltip and keyboard selection only see the
78
143
  map's own markers, GeoJSON features and points. A vector layer takes part when it opts in with the `trussInteractive: true` property; its `id`
79
144
  property names it in `onselect`, in `featurePopup`'s `feature.layer`, and in `select()`. Its features need ids (`feature.setId`).
80
145
 
@@ -135,9 +200,9 @@ Supported: `geojson` points, `markers`, `points` in `'points'` mode, and the sin
135
200
  <Map {points} pointsMode="points" idBy="code" featureStyle={(p) => ({ colors: p.status.map((s) => COLORS[s]), radius: 9 })} />
136
201
  ```
137
202
 
138
- ### Basemap and selection
203
+ ### Selection
139
204
 
140
- `basemap={{ url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' }}` creates an XYZ source with that template. Changing `basemap` at runtime swaps only the tile layer: the map instance and the view are kept. A click on empty map clears the selection and calls `onselect(null)`.
205
+ A click on empty map clears the selection and calls `onselect(null)`; so does removing the `layers` entry that holds the selected feature.
141
206
 
142
207
  ### Large point sets
143
208
 
package/dist/Map.svelte CHANGED
@@ -47,6 +47,11 @@
47
47
  locateUnsupported: string;
48
48
  /** Announced when `drawMode` changes: how to draw or edit with the pointer and the keyboard. */
49
49
  drawing: (mode: 'Point' | 'LineString' | 'Polygon' | 'modify' | 'move') => string;
50
+ // #302
51
+ /** Accessible name and tooltip of the basemap switcher. */
52
+ basemap: string;
53
+ /** The switcher's name for a `basemaps` entry without a `label`, by its `id` (the `esriBasemaps` presets, `osm`, `none`; any other id as itself). */
54
+ basemapName: (id: string) => string;
50
55
  };
51
56
  const DEFAULTS: MapLabels = {
52
57
  map: 'Map. Arrow keys pan, plus and minus zoom.',
@@ -77,7 +82,9 @@
77
82
  Polygon: 'Drawing an area: click to add corners and double-click to finish. Keyboard: Space adds a corner at the centre, Enter finishes, Backspace removes the last corner, Escape cancels.',
78
83
  modify: 'Editing shapes: drag a vertex to move it, or drag an edge to add one.',
79
84
  move: 'Moving features: drag a feature to move it.'
80
- })[mode]
85
+ })[mode],
86
+ basemap: 'Basemap',
87
+ basemapName: (id) => ({ 'esri-imagery': 'Imagery', 'esri-streets': 'Streets', 'esri-topo': 'Topographic', 'esri-hybrid': 'Imagery with labels', osm: 'OpenStreetMap', none: 'None' })[id] ?? id
81
88
  };
82
89
  </script>
83
90
 
@@ -86,9 +93,13 @@
86
93
  import { cssvars } from './cssvars.js';
87
94
  import SsrStyle from './SsrStyle.svelte';
88
95
  import { onMount, tick, untrack, type Snippet } from 'svelte';
89
- import { Button, readColorTokens, onThemeChange } from '@ruckc/truss-ui';
96
+ import { Button, MenuButton, readColorTokens, onThemeChange } from '@ruckc/truss-ui';
90
97
  import 'ol/ol.css';
91
98
  import type OLMap from 'ol/Map.js';
99
+ // #302: layers, basemap stacks and the switcher
100
+ import type { LayerManager } from './layers-ol.js';
101
+ import type { MapLayer, BasemapOption } from './types.js';
102
+ import { basemapTiles, pickBasemap } from './basemaps.js';
92
103
  import type { Basemap, FitOptions, FitTarget, MapApi, MapAttribution, MapControls, MapFeatureInfo, MapInitialView, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
93
104
  import type { MapContextMenuEvent, MapDrawEnd, MapDrawMode, MapEditEnd, MapLocateError, MapLocation, MapPopupOptions } from './types.js';
94
105
  import { createEditor, isDrawMode } from './edit.js';
@@ -96,7 +107,7 @@
96
107
  import { wireContextMenu } from './contextmenu.js';
97
108
  import {
98
109
  DEFAULT_PALETTES, EMPTY_STORE, NATIVE_CLUSTER_MAX, aggregate, drawPie, pieKey, pieStroke, addStat, autoMode, clusterProps, clusterRadius, compactCount, compileCluster, compileStyle, cssGradient, featureTitle,
99
- isLight, lonLatExtent, moveMs, newStat, numbersOf, popupEntries, propertyStyle, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
110
+ isLight, lonLatExtent, moveMs, newStat, numbersOf, popupEntries, propertyStyle, drawableSymbol, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
100
111
  type ClusterInfo, type ClusterStyle, type Compiled, type CompiledCluster, type FeatureStyle, type HeatmapOptions, type LegendInfo, type MapStyle, type Palettes, type PointStore, type PointsInput, type PointsMode, type Props
101
112
  } from './util.js';
102
113
 
@@ -149,11 +160,20 @@
149
160
  onlocate,
150
161
  onlocateerror,
151
162
  oncontextmenu,
152
- labels
163
+ labels,
164
+ // #302
165
+ layers,
166
+ basemaps,
167
+ basemapId = $bindable(),
168
+ onbasemapchange
153
169
  }: {
154
170
  /** [lon, lat] */
155
171
  center?: [number, number];
156
172
  zoom?: number;
173
+ /**
174
+ * `'osm'` (default), `'none'` (a themed graticule), `{ url, attribution?, maxZoom?, opacity?, themed? }` (XYZ tiles), `{ osm: true, ... }`, or a stack
175
+ * `{ layers: [...], themed? }` drawn bottom to top (imagery, then label overlays). Only OSM tiles are `themed` (inverted in dark mode) by default.
176
+ */
157
177
  basemap?: Basemap;
158
178
  markers?: MapMarker[];
159
179
  /** GeoJSON FeatureCollection/Feature. Optional `properties.kind` picks the intent color. */
@@ -297,6 +317,18 @@
297
317
  oncontextmenu?: (e: MapContextMenuEvent) => void;
298
318
  /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
299
319
  labels?: Partial<MapLabels>;
320
+ /**
321
+ * Data layers, each an OpenLayers vector layer the Map manages: `{ id, geojson | source | loader, style?, visible?, zIndex?, interactive?, label?, opacity? }`.
322
+ * Matched by `id`; only what changed is applied. Interactive layers (the default) take part in selection, which reports their `id` as `layer`.
323
+ * Pass a plain array (or `$state.raw`), as for `geojson`.
324
+ */
325
+ layers?: MapLayer[];
326
+ /** Basemaps to choose from (`{ id, label?, ...basemap }`, e.g. `Object.values(esriBasemaps)`). With two or more, the toolbar shows a switcher (`controls.basemap`). Wins over `basemap`. */
327
+ basemaps?: BasemapOption[];
328
+ /** The `id` of the `basemaps` entry shown; bindable. Unset or unknown, the first entry shows. */
329
+ basemapId?: string;
330
+ /** The switcher picked a basemap (to remember it, say). */
331
+ onbasemapchange?: (id: string) => void;
300
332
  } = $props();
301
333
 
302
334
  const L = useLabels('Map', DEFAULTS, () => labels);
@@ -359,7 +391,11 @@
359
391
  const sketchMode = $derived(isDrawMode(drawMode));
360
392
  /** Moves an element the app rendered into the popup, and detaches it again when the popup closes. */
361
393
  const adopt = (content: HTMLElement) => (node: HTMLElement) => { node.append(content); return () => content.remove(); };
362
- let sync: { limits(): void; markers(): void; geo(): void; points(): void; base(): void; style(): void; select(): void; view(): void; attribution(): void } | undefined;
394
+ let sync: { limits(): void; markers(): void; geo(): void; points(): void; base(): void; layers(): void; style(): void; select(): void; view(): void; attribution(): void } | undefined;
395
+ /** The OpenLayers vector layer of the `layers` entry `id`. */
396
+ export function layer(id: string) { return layerMgr?.layer(id); }
397
+ /** Load a `loader` layer again now. */
398
+ export function reloadLayer(id: string) { layerMgr?.reload(id); }
363
399
  let failed = $state<string>();
364
400
  let legendInfo = $state.raw<LegendInfo>({});
365
401
 
@@ -367,6 +403,11 @@
367
403
  const cssHeight = $derived.by(() => { const v = height ?? (variant === 'bare' ? '100%' : 420); return typeof v === 'number' ? `${v}px` : v; });
368
404
  const showZoom = $derived(controls?.zoom !== false);
369
405
  const showFit = $derived(controls?.fit !== false);
406
+ // #302: the basemap shown (a `basemaps` entry wins over `basemap`) and the switcher
407
+ const activeBasemap = $derived(pickBasemap(basemaps, basemapId));
408
+ const showBasemap = $derived(controls?.basemap !== false && (basemaps?.length ?? 0) > 1);
409
+ const basemapItems = $derived((basemaps ?? []).map((b) => ({ label: b.label ?? L.basemapName(b.id), checked: b.id === activeBasemap?.id, onselect: () => { basemapId = b.id; onbasemapchange?.(b.id); } })));
410
+ let layerMgr: LayerManager | undefined;
370
411
  /** Narrower than this (map width, px), `attribution={{ collapsed: 'auto' }}` collapses the credits. */
371
412
  const NARROW = 640;
372
413
  let root: HTMLDivElement;
@@ -380,12 +421,14 @@
380
421
  { default: OLMap }, { default: View }, { default: TileLayer }, { default: VectorLayer }, { default: VectorSource },
381
422
  { default: OSM }, { default: XYZ }, { default: Overlay }, { default: Feature }, { default: Point }, { default: GeoJSON },
382
423
  { Style, Circle: CircleStyle, Fill, Stroke, Text, Icon }, { fromLonLat, toLonLat, transformExtent }, { default: Attribution }, { default: ScaleLine },
383
- { default: Graticule }, { createEmpty, extend, isEmpty, boundingExtent, getCenter, intersects }, { default: Cluster }, { default: Heatmap }
424
+ { default: Graticule }, { createEmpty, extend, isEmpty, boundingExtent, getCenter, intersects }, { default: Cluster }, { default: Heatmap },
425
+ { createOlStyle }, { LayerManager }
384
426
  ] = await Promise.all([
385
427
  import('ol/Map.js'), import('ol/View.js'), import('ol/layer/Tile.js'), import('ol/layer/Vector.js'), import('ol/source/Vector.js'),
386
428
  import('ol/source/OSM.js'), import('ol/source/XYZ.js'), import('ol/Overlay.js'), import('ol/Feature.js'), import('ol/geom/Point.js'), import('ol/format/GeoJSON.js'),
387
429
  import('ol/style.js'), import('ol/proj.js'), import('ol/control/Attribution.js'), import('ol/control/ScaleLine.js'),
388
- import('ol/layer/Graticule.js'), import('ol/extent.js'), import('ol/source/Cluster.js'), import('ol/layer/Heatmap.js')
430
+ import('ol/layer/Graticule.js'), import('ol/extent.js'), import('ol/source/Cluster.js'), import('ol/layer/Heatmap.js'),
431
+ import('./ol-style.js'), import('./layers-ol.js')
389
432
  ]);
390
433
  if (dead) return;
391
434
 
@@ -500,8 +543,6 @@
500
543
  };
501
544
  const isSel = (f: any) => !selLayer && selected !== undefined && String(f.getId()) === selected;
502
545
  const zoomOk = () => labelMinZoom === undefined || (view.getZoom() ?? 0) >= labelMinZoom;
503
- const labelText = (text: string | undefined, offsetY: number) => text === undefined || declutter || !zoomOk() ? undefined
504
- : new Text({ text: String(text), offsetY, font: '600 12px Inter Variable, system-ui, sans-serif', fill: new Fill({ color: T['on-surface'] }), stroke: new Stroke({ color: T.surface, width: 3 }) });
505
546
  /**
506
547
  * GeoJSON features and individual points. Precedence: `featureStyle` function, the feature's own `style`/simplestyle
507
548
  * properties, the data-driven `style`, then the `kind` tone. A selected feature gets a heavier outline (shapes) or a halo (points).
@@ -510,26 +551,11 @@
510
551
  const p: Props = f.getProperties();
511
552
  const t = f.getGeometry()?.getType();
512
553
  const o: FeatureStyle = { ...propertyStyle(p), ...featureStyle?.(p, { id: f.getId(), type: t }) };
513
- const base = compiled.color?.(p) ?? tone(f.get('kind'));
514
- const fillC = o.fill ?? base, op = o.opacity ?? compiled.opacity, on = isSel(f);
515
- const strokeC = typeof o.stroke === 'object' ? o.stroke.color : o.stroke, strokeW = typeof o.stroke === 'object' ? o.stroke.width : undefined;
516
- if (t === 'Point' || t === 'MultiPoint') {
517
- const r = o.radius ?? compiled.size?.(p) ?? 5;
518
- if (o.colors?.length) {
519
- const pie = new Style({ image: pieIcon(o.colors, r, pieStroke(o.stroke, o.strokeWidth)), text: labelText(o.label, r + 12) });
520
- return on ? [pieRing(r), pie] : pie;
521
- }
522
- const dot = new Style({
523
- image: new CircleStyle({ radius: on ? r + 2 : r, fill: new Fill({ color: op === undefined ? fillC : rgba(fillC, op) }), stroke: new Stroke({ color: strokeC ?? T.surface, width: o.strokeWidth ?? strokeW ?? 1.5 }) }),
524
- text: labelText(o.label, r + 12)
525
- });
526
- return on ? [new Style({ image: new CircleStyle({ radius: r + 8, fill: new Fill({ color: rgba(fillC, 0.25) }) }) }), dot] : dot;
527
- }
528
- return new Style({
529
- stroke: new Stroke({ color: strokeC ?? base, width: (o.strokeWidth ?? strokeW ?? 2.5) + (on ? 1.5 : 0), lineCap: 'round', lineJoin: 'round' }),
530
- fill: new Fill({ color: rgba(fillC, Math.min(1, (op ?? 0.14) + (on ? 0.14 : 0))) }),
531
- text: labelText(o.label, 0)
532
- });
554
+ const pt = t === 'Point' || t === 'MultiPoint';
555
+ // the shared builder (createOlStyle, exported for app layers) draws it; data-driven size and opacity fill what the feature leaves out
556
+ const look: FeatureStyle = { ...o, opacity: o.opacity ?? compiled.opacity, ...(pt && { radius: o.radius ?? compiled.size?.(p) ?? 5 }) };
557
+ const out = createOlStyle(look, { selected: isSel(f), geometryType: t, tokens: T as any, color: compiled.color?.(p) ?? tone(f.get('kind')), labels: !declutter && zoomOk() });
558
+ return out.length === 1 ? out[0] : out;
533
559
  };
534
560
  const pointStyle = (f: any) => {
535
561
  const cl = f.get('_cluster');
@@ -543,7 +569,7 @@
543
569
  const o: FeatureStyle = { ...propertyStyle(p), ...featureStyle?.(p, { id: f.getId(), type: t }) };
544
570
  if (o.label === undefined) return undefined;
545
571
  const pt = t === 'Point' || t === 'MultiPoint';
546
- const r = o.radius ?? compiled.size?.(p) ?? 5;
572
+ const r0 = o.radius ?? compiled.size?.(p) ?? 5, r = drawableSymbol(o.symbol) ? Math.max(r0, 9) : r0;
547
573
  return new Style({ text: new Text({ text: String(o.label), offsetY: pt ? r + 12 : 0, font: '600 12px Inter Variable, system-ui, sans-serif', fill: new Fill({ color: T['on-surface'] }), stroke: new Stroke({ color: T.surface, width: 3 }) }) });
548
574
  };
549
575
 
@@ -564,6 +590,7 @@
564
590
  const labelPtLayer = new VectorLayer({ source: ptSrc, style: labelStyle, declutter: true, visible: false, zIndex: 26 });
565
591
 
566
592
  let baseLayers: any[] = [];
593
+ let baseKey = '';
567
594
  /** `attribution.collapsed`, with `'auto'` resolved against the map's own width (unknown while it has none). */
568
595
  const narrow = () => el.clientWidth > 0 && el.clientWidth < NARROW;
569
596
  const wantCollapsed = () => { const c = attribution?.collapsed ?? false; return c === 'auto' ? narrow() : c; };
@@ -584,6 +611,13 @@
584
611
  controls: [attrCtl, new ScaleLine({ units: 'metric', minWidth: 64 })],
585
612
  keyboardEventTarget: el
586
613
  });
614
+ // #302: the `layers` prop's vector layers (styled by the same builder; selection, tokens and label zoom come from the Map)
615
+ layerMgr = new LayerManager({
616
+ map, tokens: () => T as any, labels: () => zoomOk(),
617
+ selected: (l, f) => selLayer === l && selected !== undefined && String(f.getId()) === selected,
618
+ // a layer went (or its features were replaced): a selection in a layer that left is cleared, anything else rechecked
619
+ changed: () => { if (selLayer && !map.getAllLayers().includes(selLayer)) clear(); else sync!.select(); }
620
+ });
587
621
 
588
622
  const overlay = new Overlay({ element: popupEl, positioning: 'bottom-center', offset: [0, -16], stopEvent: true });
589
623
  map.addOverlay(overlay);
@@ -648,18 +682,27 @@
648
682
 
649
683
  // ---- sync functions (called from effects)
650
684
  sync = {
685
+ // #302: a basemap is a stack of tile layers (a `basemaps` entry wins over `basemap`); only `themed` layers carry the dark-mode filter.
686
+ // Unchanged tiles are kept (a theme change only redraws the graticule).
651
687
  base() {
688
+ const tiles = basemapTiles(activeBasemap ?? basemap);
689
+ const key = JSON.stringify(tiles);
690
+ if (key === baseKey && tiles !== 'none') return;
691
+ baseKey = key;
652
692
  for (const l of baseLayers) map.removeLayer(l);
653
693
  baseLayers = [];
654
- const osm = basemap === 'osm' ? ({} as { attribution?: string; maxZoom?: number }) : typeof basemap === 'object' && 'osm' in basemap ? basemap : undefined;
655
- if (osm) baseLayers = [new TileLayer({ source: new OSM({ attributions: osm.attribution, maxZoom: osm.maxZoom ?? 19 }), className: 'tr-basemap', zIndex: 0 })];
656
- else if (basemap === 'none') {
694
+ if (tiles === 'none') {
657
695
  baseLayers = [new Graticule({ strokeStyle: new Stroke({ color: rgba(T.outline, 0.45), width: 1 }), showLabels: true, wrapX: true, zIndex: 0,
658
696
  latLabelStyle: new Text({ font: '11px Inter Variable, system-ui', fill: new Fill({ color: T.outline }) }),
659
697
  lonLabelStyle: new Text({ font: '11px Inter Variable, system-ui', fill: new Fill({ color: T.outline }) }) })];
660
- } else if (typeof basemap === 'object' && 'url' in basemap) baseLayers = [new TileLayer({ source: new XYZ({ url: basemap.url, attributions: basemap.attribution, maxZoom: basemap.maxZoom ?? 19 }), className: 'tr-basemap', zIndex: 0 })];
698
+ } else baseLayers = tiles.map((t) => new TileLayer({
699
+ source: t.osm ? new OSM({ attributions: t.attribution, maxZoom: t.maxZoom }) : new XYZ({ url: t.url, attributions: t.attribution, maxZoom: t.maxZoom, ...(t.minZoom !== undefined && { minZoom: t.minZoom }) }),
700
+ className: t.themed ? 'tr-basemap' : 'tr-basemap tr-basemap-plain', zIndex: 0, ...(t.opacity !== undefined && { opacity: t.opacity })
701
+ }));
661
702
  for (const l of baseLayers) map.addLayer(l);
662
703
  },
704
+ // #302: the `layers` prop
705
+ layers() { layerMgr!.sync(layers ?? []); },
663
706
  markers() {
664
707
  markerSrc.clear();
665
708
  markerSrc.addFeatures(markers.filter((m) => validLonLat(m.lon, m.lat)).map((m) => {
@@ -700,7 +743,7 @@
700
743
  style() {
701
744
  read(); clusterStyles.clear(); recompile(); heatLayer.setGradient(heatGradient());
702
745
  labelGeoLayer.setVisible(declutter); labelPtLayer.setVisible(declutter);
703
- markerLayer.changed(); geoLayer.changed(); ptLayer.changed(); labelGeoLayer.changed(); labelPtLayer.changed(); this.base();
746
+ markerLayer.changed(); geoLayer.changed(); ptLayer.changed(); labelGeoLayer.changed(); labelPtLayer.changed(); this.base(); layerMgr?.restyle();
704
747
  },
705
748
  limits() { view.setMinZoom(minZoom); view.setMaxZoom(maxZoom); },
706
749
  attribution() {
@@ -708,7 +751,7 @@
708
751
  (attrEl.querySelector('button') as HTMLButtonElement).title = L.attributions;
709
752
  },
710
753
  select() {
711
- markerLayer.changed(); geoLayer.changed(); ptLayer.changed();
754
+ markerLayer.changed(); geoLayer.changed(); ptLayer.changed(); layerMgr?.redraw();
712
755
  const m = selLayer ? undefined : markers.find((x) => x.id === selected);
713
756
  const f: any = m || selected === undefined ? undefined : selLayer ? selLayer.getSource()?.getFeatureById(selected) : geoSrc.getFeatureById(selected) ?? ptSrc.getFeatureById(selected) ?? aggSrc.getFeatureById(selected);
714
757
  const g = f?.getGeometry();
@@ -742,7 +785,7 @@
742
785
  if (target === undefined) return;
743
786
  }
744
787
  if (target === undefined) {
745
- for (const src of [markerSrc, geoSrc, ...map.getAllLayers().filter((l: any) => !own(l) && interactive(l)).map((l: any) => l.getSource())]) extend(ext, src.getExtent()!);
788
+ for (const src of [markerSrc, geoSrc, ...map.getAllLayers().filter((l: any) => !own(l) && (interactive(l) || (layerMgr!.owns(l) && l.getVisible()))).map((l: any) => l.getSource())]) extend(ext, src.getExtent()!);
746
789
  const pe = storeExtent(store);
747
790
  if (pe) extend(ext, pe);
748
791
  } else {
@@ -1059,7 +1102,7 @@
1059
1102
  const attrRo = new ResizeObserver(() => root.style.setProperty('--trm-attribution-h', `${attrEl.offsetHeight}px`));
1060
1103
  attrRo.observe(attrEl);
1061
1104
 
1062
- sync.base(); sync.markers(); sync.geo(); sync.points();
1105
+ sync.base(); sync.markers(); sync.geo(); sync.points(); sync.layers();
1063
1106
  applyStart();
1064
1107
  emitView(true); // the starting view: `bind:extent` gets it, `onviewchange` only hears of a move
1065
1108
  if (fitPending && el.clientWidth && el.clientHeight) { fitPending = false; ctl.fit(undefined, { duration: 0 }); }
@@ -1067,13 +1110,14 @@
1067
1110
  emitView();
1068
1111
  // set before onready runs: an app callback that throws must not leave the observers behind
1069
1112
  dispose = () => {
1070
- unwatch(); el.removeEventListener('keydown', onkey); ro.disconnect(); attrRo.disconnect(); dispose303();
1113
+ unwatch(); layerMgr?.destroy(); el.removeEventListener('keydown', onkey); ro.disconnect(); attrRo.disconnect(); dispose303();
1071
1114
  map.setTarget(undefined);
1072
1115
  };
1073
1116
  x303.edit(); x303.ctx();
1074
1117
  onready?.({
1075
1118
  map, fit: ctl.fit, setView: ctl.setView, getView: ctl.getView, updateSize: ctl.updateSize, select: ctl.select,
1076
- openPopup, closePopup, finishDrawing, abortDrawing, undoLastPoint
1119
+ openPopup, closePopup, finishDrawing, abortDrawing, undoLastPoint,
1120
+ layer: (id) => layerMgr?.layer(id), reloadLayer: (id) => layerMgr?.reload(id)
1077
1121
  });
1078
1122
  })().catch((e) => (failed = e instanceof Error ? e.message : String(e)));
1079
1123
 
@@ -1093,7 +1137,12 @@
1093
1137
  $effect(() => { featureStyle; declutter; labelMinZoom; if (ready) sync?.style(); });
1094
1138
  $effect(() => { minZoom; maxZoom; if (ready) sync?.limits(); });
1095
1139
  $effect(() => { style; if (ready) sync?.style(); });
1096
- $effect(() => { basemap; if (ready) sync?.base(); });
1140
+ $effect(() => { basemap; activeBasemap; if (ready) sync?.base(); });
1141
+ // #302: each layer's own fields are read here, so a change to one (even inside a `$state` list) resyncs; the sync itself is untracked
1142
+ $effect(() => {
1143
+ for (const l of layers ?? []) { l.id; l.geojson; l.source; l.loader; l.onload; l.style; l.simplestyle; l.visible; l.zIndex; l.interactive; l.label; l.opacity; l.declutter; }
1144
+ if (ready) untrack(() => { sync?.layers(); refit(); });
1145
+ });
1097
1146
  // a `selected` the consumer set (not one a click, the keyboard or `select()` set) names one of the map's own features
1098
1147
  $effect(() => { if (selected !== mine) selLayer = undefined; if (ready) sync?.select(); });
1099
1148
  $effect(() => { center; zoom; if (ready) sync?.view(); });
@@ -1150,7 +1199,7 @@
1150
1199
  </div>
1151
1200
  <div class="sr" aria-live="polite">{announce}</div>
1152
1201
 
1153
- {#if showZoom || showFit || locOpts || toolbar}
1202
+ {#if showZoom || showFit || showBasemap || locOpts || toolbar}
1154
1203
  <div class="controls" role="toolbar" aria-label={L.controls}>
1155
1204
  {#if showZoom}
1156
1205
  <Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label={L.zoomIn} onclick={() => ctl?.zoomBy(1)} />
@@ -1158,6 +1207,8 @@
1158
1207
  {/if}
1159
1208
  {#if showFit}<Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label={L.fitToData} onclick={() => (onfit ? onfit() : ctl?.fit())} />{/if}
1160
1209
  {#if locOpts}<Button variant="minimal" intent="neutral" size="sm" icon="locate" aria-label={L.locate} pressed={tracking} onclick={() => x303?.pressLocate()} data-testid="trm-locate" />{/if}
1210
+ <!-- #302: the basemap switcher (a menu of checkable entries: Menu's keyboard, focus return and Escape) -->
1211
+ {#if showBasemap}<MenuButton label={L.basemap} icon="layers" iconOnly variant="minimal" intent="neutral" size="sm" items={basemapItems} />{/if}
1161
1212
  {#if toolbar}{@render toolbar()}{/if}
1162
1213
  </div>
1163
1214
  {/if}
@@ -1232,10 +1283,10 @@
1232
1283
  .notice { position: absolute; z-index: 4; top: 8px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 112px); padding: 8px 32px 8px 12px; background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); box-shadow: var(--tr-elevation-2); color: var(--tr-on-surface); font: var(--tr-text-sm) var(--tr-font-sans); }
1233
1284
  .err { position: absolute; inset: auto 8px 8px; padding: 8px 12px; border-radius: var(--tr-radius-md); background: var(--tr-danger-container); color: var(--tr-on-danger-container); }
1234
1285
 
1235
- /* Dark mode: tint raster tiles to the theme */
1236
- :global(:root[data-theme='dark'] .tr-basemap) { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7); }
1286
+ /* Dark mode: tint themed raster tiles to the theme (OSM by default); `themed: false` layers (`tr-basemap-plain`: imagery, topo, overlays) keep their colours (#302) */
1287
+ :global(:root[data-theme='dark'] .tr-basemap:not(.tr-basemap-plain)) { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7); }
1237
1288
  @media (prefers-color-scheme: dark) {
1238
- :global(:root:not([data-theme='light']) .tr-basemap) { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7); }
1289
+ :global(:root:not([data-theme='light']) .tr-basemap:not(.tr-basemap-plain)) { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7); }
1239
1290
  }
1240
1291
  /*
1241
1292
  * Restyle OpenLayers' built-in controls with design tokens. ol.css loads after these rules, and some of its selectors weigh as much as
@@ -45,9 +45,14 @@ export type MapLabels = {
45
45
  locateUnsupported: string;
46
46
  /** Announced when `drawMode` changes: how to draw or edit with the pointer and the keyboard. */
47
47
  drawing: (mode: 'Point' | 'LineString' | 'Polygon' | 'modify' | 'move') => string;
48
+ /** Accessible name and tooltip of the basemap switcher. */
49
+ basemap: string;
50
+ /** The switcher's name for a `basemaps` entry without a `label`, by its `id` (the `esriBasemaps` presets, `osm`, `none`; any other id as itself). */
51
+ basemapName: (id: string) => string;
48
52
  };
49
53
  import { type Snippet } from 'svelte';
50
54
  import 'ol/ol.css';
55
+ import type { MapLayer, BasemapOption } from './types.js';
51
56
  import type { Basemap, FitOptions, FitTarget, MapApi, MapAttribution, MapControls, MapFeatureInfo, MapInitialView, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
52
57
  import type { MapContextMenuEvent, MapDrawEnd, MapDrawMode, MapEditEnd, MapLocateError, MapLocation, MapPopupOptions } from './types.js';
53
58
  import { type ClusterStyle, type FeatureStyle, type HeatmapOptions, type MapStyle, type PointsInput, type PointsMode, type Props } from './util.js';
@@ -55,6 +60,10 @@ type $$ComponentProps = {
55
60
  /** [lon, lat] */
56
61
  center?: [number, number];
57
62
  zoom?: number;
63
+ /**
64
+ * `'osm'` (default), `'none'` (a themed graticule), `{ url, attribution?, maxZoom?, opacity?, themed? }` (XYZ tiles), `{ osm: true, ... }`, or a stack
65
+ * `{ layers: [...], themed? }` drawn bottom to top (imagery, then label overlays). Only OSM tiles are `themed` (inverted in dark mode) by default.
66
+ */
58
67
  basemap?: Basemap;
59
68
  markers?: MapMarker[];
60
69
  /** GeoJSON FeatureCollection/Feature. Optional `properties.kind` picks the intent color. */
@@ -200,6 +209,18 @@ type $$ComponentProps = {
200
209
  oncontextmenu?: (e: MapContextMenuEvent) => void;
201
210
  /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
202
211
  labels?: Partial<MapLabels>;
212
+ /**
213
+ * Data layers, each an OpenLayers vector layer the Map manages: `{ id, geojson | source | loader, style?, visible?, zIndex?, interactive?, label?, opacity? }`.
214
+ * Matched by `id`; only what changed is applied. Interactive layers (the default) take part in selection, which reports their `id` as `layer`.
215
+ * Pass a plain array (or `$state.raw`), as for `geojson`.
216
+ */
217
+ layers?: MapLayer[];
218
+ /** Basemaps to choose from (`{ id, label?, ...basemap }`, e.g. `Object.values(esriBasemaps)`). With two or more, the toolbar shows a switcher (`controls.basemap`). Wins over `basemap`. */
219
+ basemaps?: BasemapOption[];
220
+ /** The `id` of the `basemaps` entry shown; bindable. Unset or unknown, the first entry shows. */
221
+ basemapId?: string;
222
+ /** The switcher picked a basemap (to remember it, say). */
223
+ onbasemapchange?: (id: string) => void;
203
224
  };
204
225
  declare const Map: import("svelte").Component<$$ComponentProps, {
205
226
  fit: (target?: FitTarget, options?: FitOptions) => void;
@@ -214,6 +235,12 @@ declare const Map: import("svelte").Component<$$ComponentProps, {
214
235
  finishDrawing: () => void;
215
236
  abortDrawing: () => void;
216
237
  undoLastPoint: () => void;
217
- }, "center" | "selected" | "zoom" | "extent">;
238
+ layer: (id: string) => import("ol/layer/Vector.js").default<import("ol/source.js").Vector<import("ol/Feature.js").default<import("ol/geom.js").Geometry, {
239
+ [x: string]: any;
240
+ }>>, import("ol/Feature.js").default<import("ol/geom.js").Geometry, {
241
+ [x: string]: any;
242
+ }>> | undefined;
243
+ reloadLayer: (id: string) => void;
244
+ }, "center" | "selected" | "zoom" | "extent" | "basemapId">;
218
245
  type Map = ReturnType<typeof Map>;
219
246
  export default Map;
@@ -0,0 +1,106 @@
1
+ /** Basemap descriptions (pure data, no OpenLayers): the `basemap` and `basemaps` props, their normalisation, and the Esri presets. */
2
+ /** An XYZ tile layer: `url` with `{z}`, `{x}`, `{y}` (or `{-y}`) placeholders. */
3
+ export type BasemapTiles = {
4
+ url: string;
5
+ /** Credits shown in the attribution control (HTML is allowed, as OpenLayers renders it). */
6
+ attribution?: string;
7
+ /** The deepest zoom the source serves; the map upsamples beyond it. Default 19. */
8
+ maxZoom?: number;
9
+ /** The shallowest zoom the source serves. Default 0. */
10
+ minZoom?: number;
11
+ /** 0 to 1. Default 1. */
12
+ opacity?: number;
13
+ /**
14
+ * Tint this layer to the dark theme (a CSS invert and hue-rotate filter on `.tr-basemap`). Default `false` for tile URLs, so imagery,
15
+ * hillshades and label overlays keep their real colours. In a stack, a layer's own `themed` wins over the stack's.
16
+ */
17
+ themed?: boolean;
18
+ };
19
+ /** OpenStreetMap's own tiles with your `attribution` and/or `maxZoom`. Themed (inverted in dark mode) unless `themed: false`. */
20
+ export type BasemapOsm = {
21
+ osm: true;
22
+ attribution?: string;
23
+ maxZoom?: number;
24
+ opacity?: number;
25
+ themed?: boolean;
26
+ };
27
+ /** One layer of a basemap stack. */
28
+ export type BasemapLayer = BasemapTiles | BasemapOsm;
29
+ /** Several tile layers drawn bottom to top: imagery first, then label or boundary overlays. `themed` is the default for its layers. */
30
+ export type BasemapStack = {
31
+ layers: BasemapLayer[];
32
+ themed?: boolean;
33
+ };
34
+ /**
35
+ * Basemap: OpenStreetMap tiles (`'osm'`), none (themed graticule, works offline), any XYZ tile source (`{ url }`), OSM tiles with your own
36
+ * `attribution`/`maxZoom` (`{ osm: true }`), or a stack of tile layers (`{ layers: [...] }`). Only OSM tiles are themed (inverted in dark mode)
37
+ * by default; set `themed` to choose.
38
+ */
39
+ export type Basemap = 'osm' | 'none' | BasemapTiles | BasemapOsm | BasemapStack;
40
+ /**
41
+ * One entry of the `basemaps` list the built-in switcher offers: an `id` (what `bind:basemapId` holds) and a `label`, plus the basemap itself
42
+ * (`{ url }`, `{ osm: true }`, `{ layers }`, or `{ none: true }` for the plain graticule). Without a `label` the switcher shows the
43
+ * `basemapName` text of `MapLabels` for the `id` (it names the `esriBasemaps` presets, `osm` and `none`).
44
+ */
45
+ export type BasemapOption = {
46
+ id: string;
47
+ label?: string;
48
+ } & (BasemapTiles | BasemapOsm | BasemapStack | {
49
+ none: true;
50
+ });
51
+ /** A basemap layer as the map builds it. */
52
+ export type TileSpec = {
53
+ osm: boolean;
54
+ url?: string;
55
+ attribution?: string;
56
+ maxZoom: number;
57
+ minZoom?: number;
58
+ opacity?: number;
59
+ themed: boolean;
60
+ };
61
+ /** The tile layers a basemap (or a `basemaps` entry) draws, bottom to top, or `'none'` for the graticule. Anything unrecognised draws nothing. */
62
+ export declare function basemapTiles(b: Basemap | BasemapOption | undefined): TileSpec[] | 'none';
63
+ /** The `basemaps` entry `id` names, else the first; `undefined` for an empty list. */
64
+ export declare function pickBasemap(list: BasemapOption[] | undefined, id: string | undefined): BasemapOption | undefined;
65
+ /** Esri's place-name and boundary overlay (Reference/World_Boundaries_and_Places), to stack over imagery. */
66
+ export declare const esriLabels: BasemapTiles;
67
+ /**
68
+ * Esri ArcGIS Online basemaps as `basemaps` entries (each also works as `basemap`): World_Imagery, World_Street_Map, World_Topo_Map, and
69
+ * World_Imagery with the World_Boundaries_and_Places labels on top. Each carries the attribution Esri's service publishes. None is themed,
70
+ * so dark mode never inverts them.
71
+ *
72
+ * These are Esri's services, used under Esri's terms (the Esri Master License Agreement and the ArcGIS Online terms of use), not under this
73
+ * package's licence: the tiles load without an API key, but whether your use is allowed (commercial use, traffic, an ArcGIS account) is
74
+ * between you and Esri. Esri asks for the attribution to stay visible and does not allow bulk tile download or offline caching from these
75
+ * services. See https://goto.arcgisonline.com/maps/World_Imagery and the other services' pages.
76
+ */
77
+ export declare const esriBasemaps: {
78
+ imagery: {
79
+ id: string;
80
+ layers: {
81
+ url: string;
82
+ attribution: string;
83
+ maxZoom: number;
84
+ }[];
85
+ };
86
+ streets: {
87
+ id: string;
88
+ layers: {
89
+ url: string;
90
+ attribution: string;
91
+ maxZoom: number;
92
+ }[];
93
+ };
94
+ topo: {
95
+ id: string;
96
+ layers: {
97
+ url: string;
98
+ attribution: string;
99
+ maxZoom: number;
100
+ }[];
101
+ };
102
+ hybrid: {
103
+ id: string;
104
+ layers: BasemapTiles[];
105
+ };
106
+ };