@ruckc/truss-ol 1.55.1 → 1.56.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 +35 -4
- package/dist/Map.svelte +179 -55
- package/dist/Map.svelte.d.ts +33 -5
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +36 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,13 +57,44 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
|
|
|
57
57
|
| `tooltip`, `featureTooltip` | Hover tooltip for points and features: `true` (the name), a `(feature) => string` formatter, or a snippet. A `role="tooltip"` the map points `aria-describedby` at; `Escape` hides it. |
|
|
58
58
|
| `idBy` | Stable ids for points and GeoJSON features: a property name or `(properties, index) => id`, instead of `pt:n` / `geo:n`. |
|
|
59
59
|
| `featureStyle` | Per-feature styling by function (`fill`, `opacity`, `stroke`, `strokeWidth`, `radius`, `label`, `colors`). Features may also carry `style` / simplestyle properties. `colors: string[]` draws a pie marker, see below. |
|
|
60
|
-
| `onviewchange`, `extent` (bindable) | `onviewchange({ center, zoom, extent })` fires on `moveend
|
|
61
|
-
| `
|
|
60
|
+
| `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
|
+
| `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
|
+
| `controls`, `fitTarget`, `onfit` | `controls={{ zoom: false }}` / `{{ fit: false }}` hide built-in buttons (both show by default; 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
|
+
| `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
|
+
| `variant` | `'bare'`: no border, no radius, and the full height of its container unless `height` is set (an edge-to-edge map). |
|
|
65
|
+
| `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`, ...). |
|
|
62
66
|
| `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. |
|
|
63
67
|
| `fitOnLoad`, `fitOnDataChange`, `refitOnResize` | When the view fits the data. `center` and `zoom` are applied only when you change them, so their defaults never undo a fit. |
|
|
64
|
-
| `height`, `onready` | Map height; `onready(api)` receives `{ map, fit, setView, getView, updateSize }`. |
|
|
68
|
+
| `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 }`. |
|
|
65
69
|
|
|
66
|
-
Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`.
|
|
70
|
+
Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`, `select(layer, id)`.
|
|
71
|
+
|
|
72
|
+
### Your own layers
|
|
73
|
+
|
|
74
|
+
Layers your app adds through `onready(api) → api.map` are left alone: clicks, the pointer cursor, the tooltip and keyboard selection only see the
|
|
75
|
+
map's own markers, GeoJSON features and points. A vector layer takes part when it opts in with the `trussInteractive: true` property; its `id`
|
|
76
|
+
property names it in `onselect`, in `featurePopup`'s `feature.layer`, and in `select()`. Its features need ids (`feature.setId`).
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const roads = new VectorLayer({ source, properties: { id: 'roads', trussInteractive: true } });
|
|
80
|
+
api.map.addLayer(roads);
|
|
81
|
+
// onselect: { type: 'feature', id: 'r1', properties, geometryType: 'LineString', layer: 'roads' }
|
|
82
|
+
api.select('roads', 'r1'); // select from code (any vector layer with that id); no onselect, like setting `selected`
|
|
83
|
+
api.select(null, 'm1'); // one of the map's own features
|
|
84
|
+
api.select(null, null); // clear
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### An app map, edge to edge
|
|
88
|
+
|
|
89
|
+
```svelte
|
|
90
|
+
<Map variant="bare" basemap={{ url, attribution }} fitOnLoad={false}
|
|
91
|
+
initialView={savedView() ?? { extent: [-125, 24, -66, 50] }}
|
|
92
|
+
controls={{ fit: true }} onfit={fitVisibleLayers}
|
|
93
|
+
attribution={{ collapsed: 'auto' }}
|
|
94
|
+
onviewchange={(v) => localStorage.setItem('view', JSON.stringify(v))} {onready} />
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`onviewchange` only reports moves, so saving every change never overwrites the saved view with the default one.
|
|
67
98
|
|
|
68
99
|
### Pie markers
|
|
69
100
|
|
package/dist/Map.svelte
CHANGED
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
legendRange: (title: string, from: string, to: string) => string;
|
|
31
31
|
/** Shown when the map could not be created; `reason` is the error message. */
|
|
32
32
|
loadFailed: (reason: string) => string;
|
|
33
|
+
/** Tooltip of the attribution's show/hide button. The provider credits themselves come from the tile sources and are not translated here. */
|
|
34
|
+
attributions: string;
|
|
33
35
|
};
|
|
34
36
|
const DEFAULTS: MapLabels = {
|
|
35
37
|
map: 'Map. Arrow keys pan, plus and minus zoom.',
|
|
@@ -46,7 +48,8 @@
|
|
|
46
48
|
low: 'Low',
|
|
47
49
|
high: 'High',
|
|
48
50
|
legendRange: (title, from, to) => `${title}: ${from} to ${to}`,
|
|
49
|
-
loadFailed: (reason) => `Map failed to load: ${reason}
|
|
51
|
+
loadFailed: (reason) => `Map failed to load: ${reason}`,
|
|
52
|
+
attributions: 'Attributions'
|
|
50
53
|
};
|
|
51
54
|
</script>
|
|
52
55
|
|
|
@@ -58,7 +61,7 @@
|
|
|
58
61
|
import { Button, readColorTokens, onThemeChange } from '@ruckc/truss-ui';
|
|
59
62
|
import 'ol/ol.css';
|
|
60
63
|
import type OLMap from 'ol/Map.js';
|
|
61
|
-
import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
|
|
64
|
+
import type { Basemap, FitOptions, FitTarget, MapApi, MapAttribution, MapControls, MapFeatureInfo, MapInitialView, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
|
|
62
65
|
import {
|
|
63
66
|
DEFAULT_PALETTES, EMPTY_STORE, NATIVE_CLUSTER_MAX, aggregate, drawPie, pieKey, pieStroke, addStat, autoMode, clusterProps, clusterRadius, compactCount, compileCluster, compileStyle, cssGradient, featureTitle,
|
|
64
67
|
isLight, lonLatExtent, moveMs, newStat, numbersOf, popupEntries, propertyStyle, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
|
|
@@ -91,8 +94,14 @@
|
|
|
91
94
|
legend = false,
|
|
92
95
|
selected = $bindable(),
|
|
93
96
|
extent = $bindable(),
|
|
94
|
-
height
|
|
97
|
+
height,
|
|
98
|
+
variant = 'default',
|
|
95
99
|
fitOnLoad = true,
|
|
100
|
+
initialView,
|
|
101
|
+
controls,
|
|
102
|
+
fitTarget,
|
|
103
|
+
onfit,
|
|
104
|
+
attribution,
|
|
96
105
|
popup,
|
|
97
106
|
toolbar,
|
|
98
107
|
onselect,
|
|
@@ -166,10 +175,28 @@
|
|
|
166
175
|
selected?: string;
|
|
167
176
|
/** The visible lon/lat extent `[west, south, east, north]`, updated whenever the map moves. Bindable, read-only output: setting it does nothing. */
|
|
168
177
|
extent?: [number, number, number, number];
|
|
169
|
-
/** Map height: px, or any CSS length. Default 420
|
|
178
|
+
/** Map height: px, or any CSS length (`'100%'`, `'60vh'`, `'calc(100dvh - 56px)'`). Default 420, or `'100%'` with `variant="bare"`. */
|
|
170
179
|
height?: number | string;
|
|
171
|
-
/**
|
|
180
|
+
/** `bare`: no border and no corner radius, and (unless `height` says otherwise) the full height of its container, for an edge-to-edge map. */
|
|
181
|
+
variant?: 'default' | 'bare';
|
|
182
|
+
/** Fit the view to the data (`fitTarget`, else markers/features/points) on first load, once the container has a size. It wins over `initialView` when there is data. */
|
|
172
183
|
fitOnLoad?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Where the map starts, applied before anything is reported: `{ center: [lon, lat], zoom }`, or `{ extent: [west, south, east, north], padding?, maxZoom? }`
|
|
186
|
+
* (fitted as soon as the container has a size). Wins over `center` and `zoom`; read once, on mount. A saved view restored here never makes `onviewchange` fire.
|
|
187
|
+
*/
|
|
188
|
+
initialView?: MapInitialView;
|
|
189
|
+
/** Which built-in toolbar buttons show: `{ zoom: false }` hides zoom in/out, `{ fit: false }` the fit button. Both show by default; the `toolbar` snippet always does. */
|
|
190
|
+
controls?: MapControls;
|
|
191
|
+
/**
|
|
192
|
+
* What "the data" is for the fit button, `fitOnLoad`, `fitOnDataChange`, `refitOnResize` and `fit()` without an argument: anything `fit()` accepts,
|
|
193
|
+
* or a function returning it (called at each fit; `undefined` means nothing to fit). Default: the markers, GeoJSON, points and `trussInteractive` layers.
|
|
194
|
+
*/
|
|
195
|
+
fitTarget?: FitTarget | (() => FitTarget | undefined);
|
|
196
|
+
/** Replaces what the fit button does (for example a fit with your own options). `fitOnLoad` and `fit()` are unaffected. */
|
|
197
|
+
onfit?: () => void;
|
|
198
|
+
/** OpenLayers' attribution: `collapsed` `false` (default: expanded), `true`, or `'auto'` (collapsed while the map is narrower than 640px, measured on the map, not the viewport). */
|
|
199
|
+
attribution?: MapAttribution;
|
|
173
200
|
/** Fit the view again whenever `markers`, `geojson` or `points` change. Default false. */
|
|
174
201
|
fitOnDataChange?: boolean;
|
|
175
202
|
/** Re-measure the map when its container resizes (always), and also refit to the data. Default false. */
|
|
@@ -184,10 +211,17 @@
|
|
|
184
211
|
featurePopup?: Snippet<[feature: MapFeatureInfo]>;
|
|
185
212
|
/** Extra controls appended to the toolbar. */
|
|
186
213
|
toolbar?: Snippet;
|
|
214
|
+
/**
|
|
215
|
+
* A click or the keyboard selected a marker, GeoJSON feature or point (or cleared the selection: `null`). Layers your app adds to `api.map`
|
|
216
|
+
* take no part unless they carry the `trussInteractive: true` property; their features then report the layer's `id` property as `layer`.
|
|
217
|
+
*/
|
|
187
218
|
onselect?: (s: MapSelection | null) => void;
|
|
188
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Fired when the map has moved (`moveend`), including the load-time fit of `fitOnLoad` when it moved the view: the centre `[lon, lat]`, zoom and
|
|
221
|
+
* visible extent `[west, south, east, north]`. Not fired for the starting view (`center`/`zoom` or `initialView`) nor for a move that changed nothing.
|
|
222
|
+
*/
|
|
189
223
|
onviewchange?: (v: MapViewChange) => void;
|
|
190
|
-
/** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
|
|
224
|
+
/** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`, `select`). */
|
|
191
225
|
onready?: (api: MapApi) => void;
|
|
192
226
|
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
193
227
|
labels?: Partial<MapLabels>;
|
|
@@ -198,7 +232,9 @@
|
|
|
198
232
|
let el: HTMLDivElement;
|
|
199
233
|
let popupEl: HTMLDivElement;
|
|
200
234
|
let ready = $state(false);
|
|
201
|
-
let ctl: { zoomBy(d: number): void; fit(target?: FitTarget, o?: FitOptions): void; setView(v: Partial<Pick<MapViewState, 'center' | 'zoom'>> & { duration?: number }): void; getView(): MapViewState; updateSize(): void } | undefined;
|
|
235
|
+
let ctl: { zoomBy(d: number): void; fit(target?: FitTarget, o?: FitOptions): void; setView(v: Partial<Pick<MapViewState, 'center' | 'zoom'>> & { duration?: number }): void; getView(): MapViewState; updateSize(): void; select: MapApi['select'] } | undefined;
|
|
236
|
+
// the app layer (`trussInteractive`, or picked by `select(layerId, …)`) the selected feature belongs to; undefined for the map's own features
|
|
237
|
+
let selLayer = $state.raw<any>(undefined);
|
|
202
238
|
let fsel = $state.raw<MapFeatureInfo | null>(null);
|
|
203
239
|
let tip = $state.raw<MapFeatureInfo | null>(null);
|
|
204
240
|
let tipEl: HTMLDivElement;
|
|
@@ -209,6 +245,8 @@
|
|
|
209
245
|
let seenC: [number, number] | undefined;
|
|
210
246
|
let seenZ: number | undefined;
|
|
211
247
|
let announce = $state('');
|
|
248
|
+
/** The `selected` value the map itself set last (click, keyboard, `select()`), to tell it from one the consumer set. */
|
|
249
|
+
let mine: string | undefined;
|
|
212
250
|
|
|
213
251
|
/** Fit the view to a lon/lat extent, `{ lon, lat }` points, GeoJSON, or (no argument) everything on the map. */
|
|
214
252
|
export function fit(target?: FitTarget, options?: FitOptions) { ctl?.fit(target, options); }
|
|
@@ -218,11 +256,19 @@
|
|
|
218
256
|
export function getView(): MapViewState | undefined { return ctl?.getView(); }
|
|
219
257
|
/** Re-measure the container (the map does this by itself when its container resizes). */
|
|
220
258
|
export function updateSize() { ctl?.updateSize(); }
|
|
221
|
-
|
|
259
|
+
/** Select a feature without firing `onselect`: `layer` `null` for the map's own features, else the `id` property of an app layer; `id` `null` clears. False when not found. */
|
|
260
|
+
export function select(layer: string | null, id: string | number | null | undefined): boolean { return ctl?.select(layer, id) ?? false; }
|
|
261
|
+
let sync: { limits(): void; markers(): void; geo(): void; points(): void; base(): void; style(): void; select(): void; view(): void; attribution(): void } | undefined;
|
|
222
262
|
let failed = $state<string>();
|
|
223
263
|
let legendInfo = $state.raw<LegendInfo>({});
|
|
224
264
|
|
|
225
|
-
const sel = $derived(markers.find((m) => m.id === selected));
|
|
265
|
+
const sel = $derived(selLayer ? undefined : markers.find((m) => m.id === selected));
|
|
266
|
+
const cssHeight = $derived.by(() => { const v = height ?? (variant === 'bare' ? '100%' : 420); return typeof v === 'number' ? `${v}px` : v; });
|
|
267
|
+
const showZoom = $derived(controls?.zoom !== false);
|
|
268
|
+
const showFit = $derived(controls?.fit !== false);
|
|
269
|
+
/** Narrower than this (map width, px), `attribution={{ collapsed: 'auto' }}` collapses the credits. */
|
|
270
|
+
const NARROW = 640;
|
|
271
|
+
let root: HTMLDivElement;
|
|
226
272
|
|
|
227
273
|
onMount(() => {
|
|
228
274
|
let dispose = () => {};
|
|
@@ -305,6 +351,8 @@
|
|
|
305
351
|
for (const k of cprops) { const st = out[k] = newStat(); for (const m of members) { const v = m.get(k); addStat(st, typeof v === 'number' || (typeof v === 'string' && v.trim() !== '') ? Number(v) : NaN); } }
|
|
306
352
|
return out;
|
|
307
353
|
};
|
|
354
|
+
/** An app layer's name for `onselect`, `select()` and `MapFeatureInfo.layer`: its `id` property. */
|
|
355
|
+
const layerIdOf = (l: any): string | undefined => { const v = l.get('id'); return v === undefined || v === null ? undefined : String(v); };
|
|
308
356
|
const idOf = (p: Props, i: number): string | undefined => {
|
|
309
357
|
const v = typeof idBy === 'function' ? idBy(p, i) : idBy ? p[idBy] : undefined;
|
|
310
358
|
return v === undefined || v === null || v === '' ? undefined : String(v);
|
|
@@ -326,7 +374,7 @@
|
|
|
326
374
|
const pieRing = (r: number) => new Style({ image: new CircleStyle({ radius: r + 6, fill: new Fill({ color: rgba(T.primary, 0.25) }), stroke: new Stroke({ color: T.primary, width: 2.5 }) }) });
|
|
327
375
|
|
|
328
376
|
const markerStyle = (f: any) => {
|
|
329
|
-
const on = f.getId() === selected;
|
|
377
|
+
const on = !selLayer && f.getId() === selected;
|
|
330
378
|
const c = tone(f.get('kind'));
|
|
331
379
|
const colors: string[] | undefined = f.get('colors');
|
|
332
380
|
if (colors?.length) {
|
|
@@ -349,7 +397,7 @@
|
|
|
349
397
|
})
|
|
350
398
|
];
|
|
351
399
|
};
|
|
352
|
-
const isSel = (f: any) => selected !== undefined && String(f.getId()) === selected;
|
|
400
|
+
const isSel = (f: any) => !selLayer && selected !== undefined && String(f.getId()) === selected;
|
|
353
401
|
const zoomOk = () => labelMinZoom === undefined || (view.getZoom() ?? 0) >= labelMinZoom;
|
|
354
402
|
const labelText = (text: string | undefined, offsetY: number) => text === undefined || declutter || !zoomOk() ? undefined
|
|
355
403
|
: 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 }) });
|
|
@@ -415,13 +463,24 @@
|
|
|
415
463
|
const labelPtLayer = new VectorLayer({ source: ptSrc, style: labelStyle, declutter: true, visible: false, zIndex: 26 });
|
|
416
464
|
|
|
417
465
|
let baseLayers: any[] = [];
|
|
466
|
+
/** `attribution.collapsed`, with `'auto'` resolved against the map's own width (unknown while it has none). */
|
|
467
|
+
const narrow = () => el.clientWidth > 0 && el.clientWidth < NARROW;
|
|
468
|
+
const wantCollapsed = () => { const c = attribution?.collapsed ?? false; return c === 'auto' ? narrow() : c; };
|
|
469
|
+
const attrCtl = new Attribution({ collapsible: true, collapsed: wantCollapsed(), tipLabel: L.attributions });
|
|
470
|
+
const attrEl: HTMLElement = (attrCtl as any).element; // protected in the typings, public in practice (every control has one)
|
|
471
|
+
let wasNarrow = narrow();
|
|
472
|
+
// the starting view: initialView over center/zoom; written back to the bindings so their defaults never move it
|
|
473
|
+
const iv = initialView;
|
|
474
|
+
if (iv?.center) center = [iv.center[0], iv.center[1]];
|
|
475
|
+
if (iv?.zoom !== undefined) zoom = iv.zoom;
|
|
418
476
|
seenC = [...center]; seenZ = zoom;
|
|
419
477
|
const view = new View({ center: fromLonLat(center), zoom, minZoom, maxZoom });
|
|
478
|
+
let startExtent = iv?.extent;
|
|
420
479
|
const map = new OLMap({
|
|
421
480
|
target: el,
|
|
422
481
|
view,
|
|
423
482
|
layers: [heatLayer, geoLayer, ptLayer, markerLayer, labelGeoLayer, labelPtLayer],
|
|
424
|
-
controls: [
|
|
483
|
+
controls: [attrCtl, new ScaleLine({ units: 'metric', minWidth: 64 })],
|
|
425
484
|
keyboardEventTarget: el
|
|
426
485
|
});
|
|
427
486
|
|
|
@@ -462,13 +521,21 @@
|
|
|
462
521
|
};
|
|
463
522
|
let lastView = '';
|
|
464
523
|
/** Tell the consumer where the map is now, unless it is where we last said. */
|
|
465
|
-
const emitView = () => {
|
|
524
|
+
const emitView = (quiet = false) => {
|
|
466
525
|
const v = ctl!.getView() as MapViewChange;
|
|
467
526
|
const key = `${v.center}|${v.zoom}|${v.extent}`;
|
|
468
527
|
if (key === lastView) return;
|
|
469
528
|
lastView = key;
|
|
470
529
|
extent = v.extent;
|
|
471
|
-
onviewchange?.(v);
|
|
530
|
+
if (!quiet) onviewchange?.(v);
|
|
531
|
+
};
|
|
532
|
+
/** The `initialView` extent, once the container has a size: the app's own starting view, so it is recorded without an `onviewchange`. */
|
|
533
|
+
const applyStart = () => {
|
|
534
|
+
if (!startExtent || !el.clientWidth || !el.clientHeight) return;
|
|
535
|
+
const pad = typeof iv!.padding === 'number' ? [iv!.padding, iv!.padding, iv!.padding, iv!.padding] : iv!.padding ?? [0, 0, 0, 0];
|
|
536
|
+
view.fit(transformExtent(startExtent, 'EPSG:4326', 'EPSG:3857'), { padding: pad, maxZoom: iv!.maxZoom ?? view.getMaxZoom(), duration: 0 });
|
|
537
|
+
startExtent = undefined;
|
|
538
|
+
emitView(true);
|
|
472
539
|
};
|
|
473
540
|
const refreshView = () => { if (mode === 'heatmap') refreshHeat(); else if (mode === 'cluster' && store.n > NATIVE_CLUSTER_MAX) refreshAgg(); };
|
|
474
541
|
const heatGradient = () => {
|
|
@@ -535,15 +602,20 @@
|
|
|
535
602
|
markerLayer.changed(); geoLayer.changed(); ptLayer.changed(); labelGeoLayer.changed(); labelPtLayer.changed(); this.base();
|
|
536
603
|
},
|
|
537
604
|
limits() { view.setMinZoom(minZoom); view.setMaxZoom(maxZoom); },
|
|
605
|
+
attribution() {
|
|
606
|
+
attrCtl.setCollapsed(wantCollapsed());
|
|
607
|
+
(attrEl.querySelector('button') as HTMLButtonElement).title = L.attributions;
|
|
608
|
+
},
|
|
538
609
|
select() {
|
|
539
610
|
markerLayer.changed(); geoLayer.changed(); ptLayer.changed();
|
|
540
|
-
const m = markers.find((x) => x.id === selected);
|
|
541
|
-
const f: any = m || selected === undefined ? undefined : geoSrc.getFeatureById(selected) ?? ptSrc.getFeatureById(selected) ?? aggSrc.getFeatureById(selected);
|
|
542
|
-
|
|
543
|
-
|
|
611
|
+
const m = selLayer ? undefined : markers.find((x) => x.id === selected);
|
|
612
|
+
const f: any = m || selected === undefined ? undefined : selLayer ? selLayer.getSource()?.getFeatureById(selected) : geoSrc.getFeatureById(selected) ?? ptSrc.getFeatureById(selected) ?? aggSrc.getFeatureById(selected);
|
|
613
|
+
const g = f?.getGeometry();
|
|
614
|
+
if (g) {
|
|
544
615
|
const pos = clicked && clicked.id === selected ? clicked.at : g.getType() === 'Point' ? g.getCoordinates() : getCenter(g.getExtent());
|
|
545
616
|
const { geometry, ...properties } = f.getProperties();
|
|
546
|
-
|
|
617
|
+
const layer = selLayer ? layerIdOf(selLayer) : undefined;
|
|
618
|
+
fsel = { id: selected!, properties, geometryType: g.getType(), lonLat: toLonLat(pos) as [number, number], ...(layer !== undefined && { layer }) };
|
|
547
619
|
announce = featureTitle(properties);
|
|
548
620
|
overlay.setPosition(pos);
|
|
549
621
|
} else {
|
|
@@ -564,8 +636,12 @@
|
|
|
564
636
|
zoomBy: (d) => view.animate({ zoom: Math.min(Math.max((view.getZoom() ?? 0) + d, view.getMinZoom()), view.getMaxZoom()), duration: moveMs(200) }),
|
|
565
637
|
fit: (target, o = {}) => {
|
|
566
638
|
let ext = createEmpty();
|
|
639
|
+
if (target === undefined && fitTarget !== undefined) {
|
|
640
|
+
target = typeof fitTarget === 'function' ? fitTarget() : fitTarget;
|
|
641
|
+
if (target === undefined) return;
|
|
642
|
+
}
|
|
567
643
|
if (target === undefined) {
|
|
568
|
-
for (const src of [markerSrc, geoSrc]) extend(ext, src.getExtent()!);
|
|
644
|
+
for (const src of [markerSrc, geoSrc, ...map.getAllLayers().filter((l: any) => !own(l) && interactive(l)).map((l: any) => l.getSource())]) extend(ext, src.getExtent()!);
|
|
569
645
|
const pe = storeExtent(store);
|
|
570
646
|
if (pe) extend(ext, pe);
|
|
571
647
|
} else {
|
|
@@ -586,12 +662,26 @@
|
|
|
586
662
|
zoom: view.getZoom() ?? 0,
|
|
587
663
|
extent: transformExtent(view.calculateExtent(map.getSize()), 'EPSG:3857', 'EPSG:4326') as [number, number, number, number]
|
|
588
664
|
}),
|
|
589
|
-
updateSize: () => map.updateSize()
|
|
665
|
+
updateSize: () => map.updateSize(),
|
|
666
|
+
select: (layer, id) => {
|
|
667
|
+
if (id === null || id === undefined) { clicked = undefined; selLayer = undefined; selected = mine = undefined; sync!.select(); return true; }
|
|
668
|
+
const l: any = layer === null ? undefined : map.getAllLayers().find((x: any) => layerIdOf(x) === layer && typeof x.getSource()?.getFeatureById === 'function');
|
|
669
|
+
if (layer !== null && !l) return false;
|
|
670
|
+
const k = String(id);
|
|
671
|
+
if (!(l ? l.getSource().getFeatureById(k) : markerSrc.getFeatureById(k) ?? geoSrc.getFeatureById(k) ?? ptSrc.getFeatureById(k) ?? aggSrc.getFeatureById(k))) return false;
|
|
672
|
+
clicked = undefined; selLayer = l; selected = mine = k; sync!.select();
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
590
675
|
};
|
|
591
676
|
|
|
592
677
|
// ---- user interaction
|
|
593
|
-
/**
|
|
594
|
-
|
|
678
|
+
/**
|
|
679
|
+
* Only the map's own data layers take part in hit tests (not the basemap, the heatmap nor the label layers), plus the layers your
|
|
680
|
+
* app added with the `trussInteractive: true` property: clicks, hover, the tooltip and keyboard selection never touch any other layer.
|
|
681
|
+
*/
|
|
682
|
+
const own = (l: any) => l === markerLayer || l === geoLayer || l === ptLayer;
|
|
683
|
+
const interactive = (l: any) => l.get('trussInteractive') === true && l.getVisible() && typeof l.getSource?.()?.getFeatures === 'function';
|
|
684
|
+
const hittable = (l: any) => own(l) || interactive(l);
|
|
595
685
|
map.on('moveend', () => {
|
|
596
686
|
const c = toLonLat(view.getCenter()!);
|
|
597
687
|
center = [Number(c[0].toFixed(5)), Number(c[1].toFixed(5))];
|
|
@@ -600,28 +690,37 @@
|
|
|
600
690
|
refreshView();
|
|
601
691
|
emitView();
|
|
602
692
|
});
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
693
|
+
const clear = () => { selLayer = undefined; selected = mine = undefined; sync!.select(); onselect?.(null); };
|
|
694
|
+
/**
|
|
695
|
+
* Select a feature (marker, GeoJSON feature, point, or a feature of a `trussInteractive` layer `l`) as a click or the keyboard would;
|
|
696
|
+
* `at` anchors the popup for shapes. A feature without an id, or one that cannot be found again, clears the selection instead.
|
|
697
|
+
*/
|
|
698
|
+
const choose = (f: any, l: any, at?: number[]) => {
|
|
699
|
+
const raw = f.getId();
|
|
700
|
+
if (raw === undefined) { clear(); return; }
|
|
701
|
+
selLayer = own(l) ? undefined : l;
|
|
702
|
+
const id = String(raw);
|
|
606
703
|
clicked = at ? { id, at } : undefined;
|
|
607
|
-
selected = id;
|
|
704
|
+
selected = mine = id;
|
|
608
705
|
sync!.select();
|
|
609
|
-
if (
|
|
610
|
-
else onselect?.({ type: 'feature', id:
|
|
706
|
+
if (l === markerLayer && sel) onselect?.({ type: 'marker', marker: sel });
|
|
707
|
+
else if (fsel) onselect?.({ type: 'feature', id: raw, properties: fsel.properties, geometryType: fsel.geometryType, ...(fsel.layer !== undefined && { layer: fsel.layer }) });
|
|
708
|
+
else clear();
|
|
611
709
|
};
|
|
612
|
-
|
|
613
|
-
/** Features shown inside the current view, in a stable order, for keyboard selection. */
|
|
710
|
+
/** Features shown inside the current view, in a stable order, for keyboard selection: the map's own, then the `trussInteractive` layers'. */
|
|
614
711
|
const visible = () => {
|
|
615
712
|
const ext = view.calculateExtent(map.getSize());
|
|
616
|
-
const out: any[] = [];
|
|
617
|
-
|
|
713
|
+
const out: { f: any; l: any }[] = [];
|
|
714
|
+
const layers = [[markerLayer, markerSrc], [geoLayer, geoSrc], [ptLayer, ptLayer.getSource()!], ...map.getAllLayers().filter((l: any) => !own(l) && interactive(l)).map((l: any) => [l, l.getSource()])];
|
|
715
|
+
for (const [l, src] of layers) for (const f of src.getFeatures() as any[]) if (!f.get('_cluster') && f.getId() !== undefined && f.getGeometry() && intersects(f.getGeometry().getExtent(), ext)) out.push({ f, l });
|
|
618
716
|
return out;
|
|
619
717
|
};
|
|
620
718
|
const cycle = (dir: number) => {
|
|
621
719
|
const list = visible();
|
|
622
720
|
if (!list.length) return;
|
|
623
|
-
const at = list.findIndex((
|
|
624
|
-
|
|
721
|
+
const at = list.findIndex((x) => String(x.f.getId()) === selected && (own(x.l) ? !selLayer : x.l === selLayer));
|
|
722
|
+
const next = list[at < 0 ? (dir > 0 ? 0 : list.length - 1) : (at + dir + list.length) % list.length];
|
|
723
|
+
choose(next.f, next.l);
|
|
625
724
|
};
|
|
626
725
|
const onkey = (e: KeyboardEvent) => {
|
|
627
726
|
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); cycle(e.shiftKey ? -1 : 1); }
|
|
@@ -636,7 +735,7 @@
|
|
|
636
735
|
const [x0, y0, x1, y1] = cl.bbox;
|
|
637
736
|
if (x1 - x0 < 1 && y1 - y0 < 1) view.animate({ center: [x0, y0], zoom: Math.min((view.getZoom() ?? 0) + 2, view.getMaxZoom()), duration: moveMs(300) });
|
|
638
737
|
else view.fit(cl.bbox, { padding: [60, 60, 60, 60], duration: moveMs(300), maxZoom: view.getMaxZoom() });
|
|
639
|
-
} else if (hit) choose(hit.f, e.coordinate);
|
|
738
|
+
} else if (hit) choose(hit.f, hit.l, e.coordinate);
|
|
640
739
|
else clear();
|
|
641
740
|
});
|
|
642
741
|
map.on('pointermove', (e) => {
|
|
@@ -666,18 +765,27 @@
|
|
|
666
765
|
const ro = new ResizeObserver(() => {
|
|
667
766
|
map.updateSize();
|
|
668
767
|
if (!el.clientWidth || !el.clientHeight) return;
|
|
768
|
+
// 'auto' follows the map's width, but only when it crosses the breakpoint: a reader who opened the credits keeps them open
|
|
769
|
+
const n = narrow();
|
|
770
|
+
if (n !== wasNarrow) { wasNarrow = n; if (attribution?.collapsed === 'auto') attrCtl.setCollapsed(n); }
|
|
771
|
+
applyStart();
|
|
669
772
|
if (fitPending || refitOnResize) { fitPending = false; ctl!.fit(undefined, { duration: 0 }); }
|
|
670
773
|
});
|
|
671
774
|
ro.observe(el);
|
|
775
|
+
// the scale line stacks above the attribution, however many lines the credits wrap to (or none, when the source has none)
|
|
776
|
+
const attrRo = new ResizeObserver(() => root.style.setProperty('--trm-attribution-h', `${attrEl.offsetHeight}px`));
|
|
777
|
+
attrRo.observe(attrEl);
|
|
672
778
|
|
|
673
779
|
sync.base(); sync.markers(); sync.geo(); sync.points();
|
|
780
|
+
applyStart();
|
|
781
|
+
emitView(true); // the starting view: `bind:extent` gets it, `onviewchange` only hears of a move
|
|
674
782
|
if (fitPending && el.clientWidth && el.clientHeight) { fitPending = false; ctl.fit(undefined, { duration: 0 }); }
|
|
675
783
|
ready = true;
|
|
676
784
|
emitView();
|
|
677
|
-
onready?.({ map, fit: ctl.fit, setView: ctl.setView, getView: ctl.getView, updateSize: ctl.updateSize });
|
|
785
|
+
onready?.({ map, fit: ctl.fit, setView: ctl.setView, getView: ctl.getView, updateSize: ctl.updateSize, select: ctl.select });
|
|
678
786
|
|
|
679
787
|
dispose = () => {
|
|
680
|
-
unwatch(); el.removeEventListener('keydown', onkey); ro.disconnect();
|
|
788
|
+
unwatch(); el.removeEventListener('keydown', onkey); ro.disconnect(); attrRo.disconnect();
|
|
681
789
|
map.setTarget(undefined);
|
|
682
790
|
};
|
|
683
791
|
})().catch((e) => (failed = e instanceof Error ? e.message : String(e)));
|
|
@@ -699,12 +807,14 @@
|
|
|
699
807
|
$effect(() => { minZoom; maxZoom; if (ready) sync?.limits(); });
|
|
700
808
|
$effect(() => { style; if (ready) sync?.style(); });
|
|
701
809
|
$effect(() => { basemap; if (ready) sync?.base(); });
|
|
702
|
-
|
|
810
|
+
// a `selected` the consumer set (not one a click, the keyboard or `select()` set) names one of the map's own features
|
|
811
|
+
$effect(() => { if (selected !== mine) selLayer = undefined; if (ready) sync?.select(); });
|
|
703
812
|
$effect(() => { center; zoom; if (ready) sync?.view(); });
|
|
813
|
+
$effect(() => { attribution; L.attributions; if (ready) sync?.attribution(); });
|
|
704
814
|
</script>
|
|
705
815
|
|
|
706
|
-
<SsrStyle {uid} rules={{ '': `height:${
|
|
707
|
-
<div class="trm" data-sv={uid} {@attach cssvars(() => ({ 'height':
|
|
816
|
+
<SsrStyle {uid} rules={{ '': `height:${cssHeight}` }} />
|
|
817
|
+
<div class="trm" class:bare={variant === 'bare'} data-sv={uid} bind:this={root} {@attach cssvars(() => ({ 'height': cssHeight }))}>
|
|
708
818
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
709
819
|
<div class="map" bind:this={el} tabindex="0" role="application" aria-label={L.map}></div>
|
|
710
820
|
|
|
@@ -735,12 +845,16 @@
|
|
|
735
845
|
</div>
|
|
736
846
|
<div class="sr" aria-live="polite">{announce}</div>
|
|
737
847
|
|
|
738
|
-
|
|
739
|
-
<
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
848
|
+
{#if showZoom || showFit || toolbar}
|
|
849
|
+
<div class="controls" role="toolbar" aria-label={L.controls}>
|
|
850
|
+
{#if showZoom}
|
|
851
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label={L.zoomIn} onclick={() => ctl?.zoomBy(1)} />
|
|
852
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="minus" aria-label={L.zoomOut} onclick={() => ctl?.zoomBy(-1)} />
|
|
853
|
+
{/if}
|
|
854
|
+
{#if showFit}<Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label={L.fitToData} onclick={() => (onfit ? onfit() : ctl?.fit())} />{/if}
|
|
855
|
+
{#if toolbar}{@render toolbar()}{/if}
|
|
856
|
+
</div>
|
|
857
|
+
{/if}
|
|
744
858
|
{#if legend && (legendInfo.size || legendInfo.color || legendInfo.clusterSize || legendInfo.clusterColor || legendInfo.heatmap)}
|
|
745
859
|
<div class="legend" role="group" aria-label={L.legend}>
|
|
746
860
|
{#each [legendInfo.size, legendInfo.clusterSize] as lg, i (i)}
|
|
@@ -771,6 +885,7 @@
|
|
|
771
885
|
|
|
772
886
|
<style>
|
|
773
887
|
.trm { position: relative; overflow: hidden; border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); background: var(--tr-surface-container); }
|
|
888
|
+
.trm.bare { border: 0; border-radius: 0; }
|
|
774
889
|
.map { position: absolute; inset: 0; outline: none; }
|
|
775
890
|
.map:focus-visible { box-shadow: inset 0 0 0 2px var(--tr-primary); }
|
|
776
891
|
/* the buttons sit at least 24px apart centre to centre (WCAG 2.5.8 spacing): 2px apart, 4px once compact makes them 20px (#292) */
|
|
@@ -807,12 +922,21 @@
|
|
|
807
922
|
@media (prefers-color-scheme: dark) {
|
|
808
923
|
:global(:root:not([data-theme='light']) .tr-basemap) { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7); }
|
|
809
924
|
}
|
|
810
|
-
/*
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
925
|
+
/*
|
|
926
|
+
* Restyle OpenLayers' built-in controls with design tokens. ol.css loads after these rules, and some of its selectors weigh as much as
|
|
927
|
+
* `.trm .ol-attribution` (0,2,0): `.ol-attribution:not(.ol-collapsed)` (a translucent white background, unreadable under the dark text
|
|
928
|
+
* tokens, #300), `.ol-attribution.ol-uncollapsible` (position, radius) and `.ol-control button:hover/:focus` (0,2,1: colour, outline).
|
|
929
|
+
* So every attribution rule names `.ol-control` too, (0,3,0) and up, and wins whatever the load order. The scale line's own rules
|
|
930
|
+
* (`.ol-scale-line`, `.ol-scale-line-inner`, 0,1,0) never tie with `.trm .ol-scale-line` (0,2,0).
|
|
931
|
+
*/
|
|
932
|
+
:global(.trm .ol-attribution.ol-control) { right: 8px; bottom: 8px; max-width: 70%; background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-pill); font: var(--tr-text-xs) var(--tr-font-sans); color: var(--tr-on-surface-variant); }
|
|
933
|
+
:global(.trm .ol-attribution.ol-control ul) { margin: 0; padding: 2px 10px; color: var(--tr-on-surface-variant); text-shadow: none; }
|
|
934
|
+
:global(.trm .ol-attribution.ol-control a) { color: var(--tr-primary-text, var(--tr-primary)); }
|
|
935
|
+
:global(.trm .ol-attribution.ol-control button) { background: none; color: var(--tr-on-surface-variant); }
|
|
936
|
+
:global(.trm .ol-attribution.ol-control button:hover) { background: var(--tr-surface-container-high); color: var(--tr-on-surface); outline: none; }
|
|
937
|
+
:global(.trm .ol-attribution.ol-control button:focus) { outline: none; }
|
|
938
|
+
:global(.trm .ol-attribution.ol-control button:focus-visible) { box-shadow: var(--tr-focus-ring); }
|
|
939
|
+
/* above the attribution's measured height (--trm-attribution-h, set from a ResizeObserver), never lower than the classic 36px */
|
|
940
|
+
:global(.trm .ol-scale-line) { left: auto; right: 8px; bottom: max(36px, calc(var(--trm-attribution-h, 0px) + 14px)); background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-pill); padding: 2px 8px; }
|
|
817
941
|
:global(.trm .ol-scale-line-inner) { border-color: var(--tr-on-surface-variant); color: var(--tr-on-surface-variant); font: var(--tr-text-xs) var(--tr-font-sans); }
|
|
818
942
|
</style>
|
package/dist/Map.svelte.d.ts
CHANGED
|
@@ -29,10 +29,12 @@ export type MapLabels = {
|
|
|
29
29
|
legendRange: (title: string, from: string, to: string) => string;
|
|
30
30
|
/** Shown when the map could not be created; `reason` is the error message. */
|
|
31
31
|
loadFailed: (reason: string) => string;
|
|
32
|
+
/** Tooltip of the attribution's show/hide button. The provider credits themselves come from the tile sources and are not translated here. */
|
|
33
|
+
attributions: string;
|
|
32
34
|
};
|
|
33
35
|
import { type Snippet } from 'svelte';
|
|
34
36
|
import 'ol/ol.css';
|
|
35
|
-
import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
|
|
37
|
+
import type { Basemap, FitOptions, FitTarget, MapApi, MapAttribution, MapControls, MapFeatureInfo, MapInitialView, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
|
|
36
38
|
import { type ClusterStyle, type FeatureStyle, type HeatmapOptions, type MapStyle, type PointsInput, type PointsMode, type Props } from './util.js';
|
|
37
39
|
type $$ComponentProps = {
|
|
38
40
|
/** [lon, lat] */
|
|
@@ -104,10 +106,28 @@ type $$ComponentProps = {
|
|
|
104
106
|
selected?: string;
|
|
105
107
|
/** The visible lon/lat extent `[west, south, east, north]`, updated whenever the map moves. Bindable, read-only output: setting it does nothing. */
|
|
106
108
|
extent?: [number, number, number, number];
|
|
107
|
-
/** Map height: px, or any CSS length. Default 420
|
|
109
|
+
/** Map height: px, or any CSS length (`'100%'`, `'60vh'`, `'calc(100dvh - 56px)'`). Default 420, or `'100%'` with `variant="bare"`. */
|
|
108
110
|
height?: number | string;
|
|
109
|
-
/**
|
|
111
|
+
/** `bare`: no border and no corner radius, and (unless `height` says otherwise) the full height of its container, for an edge-to-edge map. */
|
|
112
|
+
variant?: 'default' | 'bare';
|
|
113
|
+
/** Fit the view to the data (`fitTarget`, else markers/features/points) on first load, once the container has a size. It wins over `initialView` when there is data. */
|
|
110
114
|
fitOnLoad?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Where the map starts, applied before anything is reported: `{ center: [lon, lat], zoom }`, or `{ extent: [west, south, east, north], padding?, maxZoom? }`
|
|
117
|
+
* (fitted as soon as the container has a size). Wins over `center` and `zoom`; read once, on mount. A saved view restored here never makes `onviewchange` fire.
|
|
118
|
+
*/
|
|
119
|
+
initialView?: MapInitialView;
|
|
120
|
+
/** Which built-in toolbar buttons show: `{ zoom: false }` hides zoom in/out, `{ fit: false }` the fit button. Both show by default; the `toolbar` snippet always does. */
|
|
121
|
+
controls?: MapControls;
|
|
122
|
+
/**
|
|
123
|
+
* What "the data" is for the fit button, `fitOnLoad`, `fitOnDataChange`, `refitOnResize` and `fit()` without an argument: anything `fit()` accepts,
|
|
124
|
+
* or a function returning it (called at each fit; `undefined` means nothing to fit). Default: the markers, GeoJSON, points and `trussInteractive` layers.
|
|
125
|
+
*/
|
|
126
|
+
fitTarget?: FitTarget | (() => FitTarget | undefined);
|
|
127
|
+
/** Replaces what the fit button does (for example a fit with your own options). `fitOnLoad` and `fit()` are unaffected. */
|
|
128
|
+
onfit?: () => void;
|
|
129
|
+
/** OpenLayers' attribution: `collapsed` `false` (default: expanded), `true`, or `'auto'` (collapsed while the map is narrower than 640px, measured on the map, not the viewport). */
|
|
130
|
+
attribution?: MapAttribution;
|
|
111
131
|
/** Fit the view again whenever `markers`, `geojson` or `points` change. Default false. */
|
|
112
132
|
fitOnDataChange?: boolean;
|
|
113
133
|
/** Re-measure the map when its container resizes (always), and also refit to the data. Default false. */
|
|
@@ -122,10 +142,17 @@ type $$ComponentProps = {
|
|
|
122
142
|
featurePopup?: Snippet<[feature: MapFeatureInfo]>;
|
|
123
143
|
/** Extra controls appended to the toolbar. */
|
|
124
144
|
toolbar?: Snippet;
|
|
145
|
+
/**
|
|
146
|
+
* A click or the keyboard selected a marker, GeoJSON feature or point (or cleared the selection: `null`). Layers your app adds to `api.map`
|
|
147
|
+
* take no part unless they carry the `trussInteractive: true` property; their features then report the layer's `id` property as `layer`.
|
|
148
|
+
*/
|
|
125
149
|
onselect?: (s: MapSelection | null) => void;
|
|
126
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Fired when the map has moved (`moveend`), including the load-time fit of `fitOnLoad` when it moved the view: the centre `[lon, lat]`, zoom and
|
|
152
|
+
* visible extent `[west, south, east, north]`. Not fired for the starting view (`center`/`zoom` or `initialView`) nor for a move that changed nothing.
|
|
153
|
+
*/
|
|
127
154
|
onviewchange?: (v: MapViewChange) => void;
|
|
128
|
-
/** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
|
|
155
|
+
/** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`, `select`). */
|
|
129
156
|
onready?: (api: MapApi) => void;
|
|
130
157
|
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
131
158
|
labels?: Partial<MapLabels>;
|
|
@@ -137,6 +164,7 @@ declare const Map: import("svelte").Component<$$ComponentProps, {
|
|
|
137
164
|
}) => void;
|
|
138
165
|
getView: () => MapViewState | undefined;
|
|
139
166
|
updateSize: () => void;
|
|
167
|
+
select: (layer: string | null, id: string | number | null | undefined) => boolean;
|
|
140
168
|
}, "center" | "selected" | "zoom" | "extent">;
|
|
141
169
|
type Map = ReturnType<typeof Map>;
|
|
142
170
|
export default Map;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { default as ScaleBar } from './ScaleBar.svelte';
|
|
|
8
8
|
export type { ScaleBarLabels } from './ScaleBar.svelte';
|
|
9
9
|
export { default as Attribution } from './Attribution.svelte';
|
|
10
10
|
export type { AttributionLabels } from './Attribution.svelte';
|
|
11
|
-
export type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, MapViewChange, FitOptions, FitTarget, MapApi } from './types.js';
|
|
11
|
+
export type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, MapViewChange, FitOptions, FitTarget, MapApi, MapInitialView, MapControls, MapAttribution } from './types.js';
|
|
12
12
|
export type { MapStyle, SizeSpec, ColorSpec, FeatureStyle, PieStroke, LegendInfo, ClusterStyle, ClusterSizeSpec, ClusterColorSpec, ClusterBy, ClusterAgg, ClusterInfo } from './style.js';
|
|
13
13
|
export type { PointsInput, PointInput, PointsMode, HeatmapOptions } from './points.js';
|
|
14
14
|
export type { ControlPosition, ScaleUnit, HeadingStatus } from './util.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -42,8 +42,11 @@ export type MapSelection = {
|
|
|
42
42
|
} | {
|
|
43
43
|
type: 'feature';
|
|
44
44
|
id?: string | number;
|
|
45
|
-
properties: Record<string, unknown>;
|
|
45
|
+
properties: Record<string, unknown>;
|
|
46
|
+
/** `Point`, `LineString`, `Polygon`, `MultiPolygon`, ... */
|
|
46
47
|
geometryType: string;
|
|
48
|
+
/** The `id` property of the app layer the feature belongs to (a layer added with `trussInteractive: true`); absent for the map's own features. */
|
|
49
|
+
layer?: string;
|
|
47
50
|
};
|
|
48
51
|
/** A GeoJSON or point feature as the popup and selection report it. */
|
|
49
52
|
export type MapFeatureInfo = {
|
|
@@ -54,6 +57,8 @@ export type MapFeatureInfo = {
|
|
|
54
57
|
geometryType: string;
|
|
55
58
|
/** Where the popup is anchored. */
|
|
56
59
|
lonLat: [number, number];
|
|
60
|
+
/** The `id` property of the app layer the feature belongs to (see `trussInteractive`); absent for the map's own features. */
|
|
61
|
+
layer?: string;
|
|
57
62
|
};
|
|
58
63
|
/** The view as `getView()` reports it and `setView()` accepts. */
|
|
59
64
|
export type MapViewState = {
|
|
@@ -87,4 +92,34 @@ export type MapApi = {
|
|
|
87
92
|
getView(): MapViewState;
|
|
88
93
|
/** Re-measure the container (call after resizing it yourself; the map already does this when its container resizes). */
|
|
89
94
|
updateSize(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Select a feature as a click would, without firing `onselect` (like setting `selected`): `layer` is `null` for the map's own markers,
|
|
97
|
+
* GeoJSON features and points, or the `id` property of a vector layer your app added (`new VectorLayer({ properties: { id: 'roads' } })`).
|
|
98
|
+
* `id` `null`/`undefined` clears the selection. Returns false (and changes nothing) when the layer or the feature is not found.
|
|
99
|
+
*/
|
|
100
|
+
select(layer: string | null, id: string | number | null | undefined): boolean;
|
|
101
|
+
};
|
|
102
|
+
/** Where the Map starts (`initialView`): a centre and zoom, or a lon/lat extent fitted once the container has a size. */
|
|
103
|
+
export type MapInitialView = {
|
|
104
|
+
/** `[lon, lat]` */
|
|
105
|
+
center?: [number, number];
|
|
106
|
+
zoom?: number;
|
|
107
|
+
/** `[west, south, east, north]`: fitted instead of `center`/`zoom` once the map has a size. */
|
|
108
|
+
extent?: [number, number, number, number];
|
|
109
|
+
/** Pixels kept free around `extent` (a number for all four sides). Default 0. */
|
|
110
|
+
padding?: number | [number, number, number, number];
|
|
111
|
+
/** Do not zoom closer than this when fitting `extent`. Default: the map's `maxZoom`. */
|
|
112
|
+
maxZoom?: number;
|
|
113
|
+
};
|
|
114
|
+
/** The built-in toolbar buttons of the Map (`controls`): each shows unless set to `false`. */
|
|
115
|
+
export type MapControls = {
|
|
116
|
+
/** Zoom in and zoom out. */
|
|
117
|
+
zoom?: boolean;
|
|
118
|
+
/** Fit to data (see `fitTarget` and `onfit`). */
|
|
119
|
+
fit?: boolean;
|
|
120
|
+
};
|
|
121
|
+
/** OpenLayers' attribution control of the Map (`attribution`). */
|
|
122
|
+
export type MapAttribution = {
|
|
123
|
+
/** `false` (expanded, the default), `true` (collapsed behind its button), or `'auto'`: collapsed while the map is narrower than 640px. */
|
|
124
|
+
collapsed?: boolean | 'auto';
|
|
90
125
|
};
|