@ruckc/truss-ol 1.56.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.
@@ -31,15 +31,39 @@ export type MapLabels = {
31
31
  loadFailed: (reason: string) => string;
32
32
  /** Tooltip of the attribution's show/hide button. The provider credits themselves come from the tile sources and are not translated here. */
33
33
  attributions: string;
34
+ /** Accessible name of a popup opened with `openPopup` when it passes no `label`. */
35
+ details: string;
36
+ /** Accessible name of the locate button (`controls={{ locate: true }}`). */
37
+ locate: string;
38
+ /** Announced when the locate control first finds the reader; `accuracy` in metres. */
39
+ located: (accuracy: number) => string;
40
+ /** Shown when the reader refused location access. */
41
+ locateDenied: string;
42
+ /** Shown when the position could not be found (no fix, or it took too long). */
43
+ locateUnavailable: string;
44
+ /** Shown when the browser has no Geolocation API. */
45
+ locateUnsupported: string;
46
+ /** Announced when `drawMode` changes: how to draw or edit with the pointer and the keyboard. */
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;
34
52
  };
35
53
  import { type Snippet } from 'svelte';
36
54
  import 'ol/ol.css';
55
+ import type { MapLayer, BasemapOption } from './types.js';
37
56
  import type { Basemap, FitOptions, FitTarget, MapApi, MapAttribution, MapControls, MapFeatureInfo, MapInitialView, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
57
+ import type { MapContextMenuEvent, MapDrawEnd, MapDrawMode, MapEditEnd, MapLocateError, MapLocation, MapPopupOptions } from './types.js';
38
58
  import { type ClusterStyle, type FeatureStyle, type HeatmapOptions, type MapStyle, type PointsInput, type PointsMode, type Props } from './util.js';
39
59
  type $$ComponentProps = {
40
60
  /** [lon, lat] */
41
61
  center?: [number, number];
42
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
+ */
43
67
  basemap?: Basemap;
44
68
  markers?: MapMarker[];
45
69
  /** GeoJSON FeatureCollection/Feature. Optional `properties.kind` picks the intent color. */
@@ -152,10 +176,51 @@ type $$ComponentProps = {
152
176
  * visible extent `[west, south, east, north]`. Not fired for the starting view (`center`/`zoom` or `initialView`) nor for a move that changed nothing.
153
177
  */
154
178
  onviewchange?: (v: MapViewChange) => void;
155
- /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`, `select`). */
179
+ /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`, `select`, `openPopup`, `closePopup`, `finishDrawing`, `abortDrawing`, `undoLastPoint`). */
156
180
  onready?: (api: MapApi) => void;
181
+ /**
182
+ * Draw or edit (`null`, the default, does neither): `'Point'`, `'LineString'` or `'Polygon'` draws a new feature (`ondrawend`), `'modify'` drags
183
+ * vertices of existing ones (`onmodifyend`), `'move'` drags whole features (`onmoveend`). The target is `editLayer`, else the map's own `geojson`.
184
+ * While drawing, clicks do not select, and the focused map takes Space (add a vertex at the centre), Enter (finish), Backspace and Escape.
185
+ */
186
+ drawMode?: MapDrawMode | null;
187
+ /**
188
+ * The vector layer `drawMode` works on, by its `id` property: a layer your app added to `api.map` (`properties: { id: 'places' }`).
189
+ * Drawn features are added to its source. Without it, `modify` and `move` edit the map's own GeoJSON features and a drawn feature is only
190
+ * reported (add it to `geojson`). A layer that is not on the map yet is waited for.
191
+ */
192
+ editLayer?: string;
193
+ /** Snap the pointer to the vertices and edges of the features being edited. Default true. */
194
+ snap?: boolean;
195
+ /** A point, line or polygon was drawn: its GeoJSON (lon/lat) and the OpenLayers feature. */
196
+ ondrawend?: (e: MapDrawEnd) => void;
197
+ /** Vertices were dragged (`drawMode: 'modify'`): the changed features with their new geometry. */
198
+ onmodifyend?: (e: MapEditEnd) => void;
199
+ /** Features were dragged (`drawMode: 'move'`). */
200
+ onmoveend?: (e: MapEditEnd) => void;
201
+ /** The locate control (`controls.locate`) has a position: on the first fix and every update while it is on. */
202
+ onlocate?: (l: MapLocation) => void;
203
+ /** The locate control failed: permission denied, no position, a timeout, or no Geolocation API. The map shows `message` too. */
204
+ onlocateerror?: (e: MapLocateError) => void;
205
+ /**
206
+ * A right-click, a touch long-press, or the ContextMenu key / Shift+F10 on the focused map (at the selected feature, else the centre): where
207
+ * (`lonLat`, map `pixel`, viewport `x`/`y`) and the feature there. Setting it suppresses the browser's own menu on the map.
208
+ */
209
+ oncontextmenu?: (e: MapContextMenuEvent) => void;
157
210
  /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
158
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;
159
224
  };
160
225
  declare const Map: import("svelte").Component<$$ComponentProps, {
161
226
  fit: (target?: FitTarget, options?: FitOptions) => void;
@@ -165,6 +230,17 @@ declare const Map: import("svelte").Component<$$ComponentProps, {
165
230
  getView: () => MapViewState | undefined;
166
231
  updateSize: () => void;
167
232
  select: (layer: string | null, id: string | number | null | undefined) => boolean;
168
- }, "center" | "selected" | "zoom" | "extent">;
233
+ openPopup: (lonLat: [number, number], options: MapPopupOptions) => void;
234
+ closePopup: () => void;
235
+ finishDrawing: () => void;
236
+ abortDrawing: () => void;
237
+ undoLastPoint: () => void;
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">;
169
245
  type Map = ReturnType<typeof Map>;
170
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
+ };
@@ -0,0 +1,50 @@
1
+ /** Basemap descriptions (pure data, no OpenLayers): the `basemap` and `basemaps` props, their normalisation, and the Esri presets. */
2
+ const tile = (l, themed) => {
3
+ const osm = 'osm' in l && l.osm === true;
4
+ const t = l;
5
+ return { osm, url: osm ? undefined : t.url, attribution: l.attribution, maxZoom: l.maxZoom ?? 19, minZoom: osm ? undefined : t.minZoom, opacity: l.opacity, themed: l.themed ?? themed ?? osm };
6
+ };
7
+ /** The tile layers a basemap (or a `basemaps` entry) draws, bottom to top, or `'none'` for the graticule. Anything unrecognised draws nothing. */
8
+ export function basemapTiles(b) {
9
+ if (b === 'none' || (typeof b === 'object' && 'none' in b && b.none))
10
+ return 'none';
11
+ if (b === 'osm')
12
+ return [tile({ osm: true })];
13
+ if (!b || typeof b !== 'object')
14
+ return [];
15
+ if ('layers' in b)
16
+ return b.layers.map((l) => tile(l, b.themed));
17
+ if ('url' in b || 'osm' in b)
18
+ return [tile(b)];
19
+ return [];
20
+ }
21
+ /** The `basemaps` entry `id` names, else the first; `undefined` for an empty list. */
22
+ export function pickBasemap(list, id) {
23
+ return list?.find((b) => b.id === id) ?? list?.[0];
24
+ }
25
+ const ARC = 'https://server.arcgisonline.com/ArcGIS/rest/services';
26
+ const tiles = (service) => `${ARC}/${service}/MapServer/tile/{z}/{y}/{x}`;
27
+ const POWERED = 'Powered by <a href="https://www.esri.com" target="_blank" rel="noopener">Esri</a>';
28
+ // The credits are each service's own `copyrightText` (its REST endpoint, `?f=json`), as Esri asks them to be shown.
29
+ const IMAGERY = `${POWERED} | Source: Esri, Vantor, Earthstar Geographics, and the GIS User Community`;
30
+ const STREETS = `${POWERED} | Sources: Esri, HERE, Garmin, USGS, Intermap, INCREMENT P, NRCan, Esri Japan, METI, Esri China (Hong Kong), Esri Korea, Esri (Thailand), NGCC, © OpenStreetMap contributors, and the GIS User Community`;
31
+ const TOPO = `${POWERED} | Sources: Esri, HERE, Garmin, Intermap, increment P Corp., GEBCO, USGS, FAO, NPS, NRCAN, GeoBase, IGN, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), © OpenStreetMap contributors, and the GIS User Community`;
32
+ const PLACES = `${POWERED} | Esri, HERE, Garmin, © OpenStreetMap contributors, and the GIS user community`;
33
+ /** Esri's place-name and boundary overlay (Reference/World_Boundaries_and_Places), to stack over imagery. */
34
+ export const esriLabels = { url: tiles('Reference/World_Boundaries_and_Places'), attribution: PLACES, maxZoom: 19 };
35
+ /**
36
+ * Esri ArcGIS Online basemaps as `basemaps` entries (each also works as `basemap`): World_Imagery, World_Street_Map, World_Topo_Map, and
37
+ * World_Imagery with the World_Boundaries_and_Places labels on top. Each carries the attribution Esri's service publishes. None is themed,
38
+ * so dark mode never inverts them.
39
+ *
40
+ * 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
41
+ * package's licence: the tiles load without an API key, but whether your use is allowed (commercial use, traffic, an ArcGIS account) is
42
+ * between you and Esri. Esri asks for the attribution to stay visible and does not allow bulk tile download or offline caching from these
43
+ * services. See https://goto.arcgisonline.com/maps/World_Imagery and the other services' pages.
44
+ */
45
+ export const esriBasemaps = {
46
+ imagery: { id: 'esri-imagery', layers: [{ url: tiles('World_Imagery'), attribution: IMAGERY, maxZoom: 19 }] },
47
+ streets: { id: 'esri-streets', layers: [{ url: tiles('World_Street_Map'), attribution: STREETS, maxZoom: 19 }] },
48
+ topo: { id: 'esri-topo', layers: [{ url: tiles('World_Topo_Map'), attribution: TOPO, maxZoom: 19 }] },
49
+ hybrid: { id: 'esri-hybrid', layers: [{ url: tiles('World_Imagery'), attribution: IMAGERY, maxZoom: 19 }, esriLabels] }
50
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @internal The Map's context-menu gestures (#303): a right-click (`contextmenu`) and a touch long-press (the core's `longPress`, the gesture
3
+ * the tooltips use). The keyboard (ContextMenu key, Shift+F10) is handled by the Map's own key handler, which calls `keyboard()` so the
4
+ * native `contextmenu` event some platforms send after the key is not reported twice.
5
+ */
6
+ export declare function wireContextMenu(el: HTMLElement, fire: (x: number, y: number, source: 'mouse' | 'touch') => void, touchOk: () => boolean): {
7
+ keyboard(): void;
8
+ dispose(): void;
9
+ };
@@ -0,0 +1,23 @@
1
+ import { longPress } from '@ruckc/truss-ui';
2
+ /**
3
+ * @internal The Map's context-menu gestures (#303): a right-click (`contextmenu`) and a touch long-press (the core's `longPress`, the gesture
4
+ * the tooltips use). The keyboard (ContextMenu key, Shift+F10) is handled by the Map's own key handler, which calls `keyboard()` so the
5
+ * native `contextmenu` event some platforms send after the key is not reported twice.
6
+ */
7
+ export function wireContextMenu(el, fire, touchOk) {
8
+ let kb = -Infinity;
9
+ const menu = (e) => {
10
+ e.preventDefault();
11
+ // a long-press in progress reports itself; a key press just did
12
+ if (el.hasAttribute('data-tr-pressing') || performance.now() - kb < 800)
13
+ return;
14
+ fire(e.clientX, e.clientY, 'mouse');
15
+ };
16
+ el.addEventListener('contextmenu', menu);
17
+ const press = longPress(el, ({ x, y }) => { if (touchOk())
18
+ fire(x, y, 'touch'); }, () => { });
19
+ return {
20
+ keyboard() { kb = performance.now(); },
21
+ dispose() { el.removeEventListener('contextmenu', menu); press.dispose(); }
22
+ };
23
+ }
package/dist/edit.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type OLMap from 'ol/Map.js';
2
+ import type { GeoJSONFeature, MapDrawEnd, MapDrawMode, MapEditEnd } from './types.js';
3
+ /**
4
+ * @internal Drawing and editing for the Map (#303): OpenLayers' Draw, Modify, Translate and Snap, loaded on first use.
5
+ * The target is a vector layer found by its `id` property (`editLayer`, an app layer or, later, a `layers` entry of #302), or the
6
+ * Map's own GeoJSON layer. Kept out of Map.svelte so the component only wires props to it.
7
+ */
8
+ export type EditDeps = {
9
+ map: OLMap;
10
+ /** The Map's own GeoJSON layer: the target without `editLayer`. */
11
+ own: any;
12
+ /** A vector layer by its `id` property. */
13
+ find(id: string): any;
14
+ /** The sketch style (themed; read at each call). */
15
+ style: () => any;
16
+ toGeoJSON(f: any): GeoJSONFeature;
17
+ /** The current callbacks (props can change after the editor was created). */
18
+ events(): {
19
+ drawend?: (e: MapDrawEnd) => void;
20
+ modifyend?: (e: MapEditEnd) => void;
21
+ moveend?: (e: MapEditEnd) => void;
22
+ };
23
+ };
24
+ export declare const isDrawMode: (m: MapDrawMode | null | undefined) => m is "Point" | "LineString" | "Polygon";
25
+ /** Real vertices of a sketch (the last coordinate follows the pointer; a polygon's ring is closed back to its first vertex as well). */
26
+ export declare function sketchVertices(type: string, coords: any): number;
27
+ export declare function createEditor(d: EditDeps): {
28
+ set: (m: MapDrawMode | null, layer: string | undefined, snap: boolean) => Promise<void>;
29
+ finish: () => void;
30
+ abort: () => void;
31
+ undo: () => void;
32
+ /** Whether a draw mode (point, line, polygon) is active. */
33
+ readonly drawing: boolean;
34
+ /**
35
+ * The keyboard on the focused map while drawing: Space adds a vertex at the map centre (`center`), Enter finishes (or places a point),
36
+ * Backspace removes the last vertex, Escape drops the sketch. Returns whether the key was used.
37
+ */
38
+ key(e: KeyboardEvent, center: number[]): boolean;
39
+ /** The theme changed: redraw the sketch and the vertex handles (their style reads the tokens when drawn). */
40
+ restyle(): void;
41
+ dispose(): void;
42
+ };
package/dist/edit.js ADDED
@@ -0,0 +1,116 @@
1
+ export const isDrawMode = (m) => m === 'Point' || m === 'LineString' || m === 'Polygon';
2
+ /** Real vertices of a sketch (the last coordinate follows the pointer; a polygon's ring is closed back to its first vertex as well). */
3
+ export function sketchVertices(type, coords) {
4
+ return type === 'Polygon' ? Math.max(0, coords[0].length - 2) : coords.length - 1;
5
+ }
6
+ export function createEditor(d) {
7
+ let mode = null;
8
+ let ints = [];
9
+ let draw;
10
+ let sketch;
11
+ let token = 0;
12
+ let unwait;
13
+ const teardown = () => {
14
+ for (const i of ints)
15
+ d.map.removeInteraction(i);
16
+ ints = [];
17
+ draw = undefined;
18
+ sketch = undefined;
19
+ unwait?.();
20
+ unwait = undefined;
21
+ };
22
+ /** Switch to `m` on the layer `layer` (`undefined`: the Map's own GeoJSON); `null` stops. A layer that is not on the map yet is waited for. */
23
+ async function set(m, layer, snap) {
24
+ const t = ++token;
25
+ teardown();
26
+ mode = m;
27
+ if (!m)
28
+ return;
29
+ const l = layer === undefined ? d.own : d.find(layer);
30
+ if (!l) {
31
+ // a layer the app adds a moment later (created, then added in its own effect): start once it is there
32
+ const coll = d.map.getLayers();
33
+ const on = () => { if (d.find(layer))
34
+ void set(m, layer, snap); };
35
+ coll.on('add', on);
36
+ unwait = () => coll.un('add', on);
37
+ return;
38
+ }
39
+ const [{ default: Draw }, { default: Modify }, { default: Translate }, { default: Snap }] = await Promise.all([
40
+ import('ol/interaction/Draw.js'), import('ol/interaction/Modify.js'), import('ol/interaction/Translate.js'), import('ol/interaction/Snap.js')
41
+ ]);
42
+ if (t !== token)
43
+ return;
44
+ const source = l.getSource();
45
+ const tag = layer === undefined ? {} : { layer };
46
+ const report = (fs) => fs.map((f) => ({ ...(f.getId() !== undefined && { id: f.getId() }), feature: d.toGeoJSON(f), olFeature: f }));
47
+ if (isDrawMode(m)) {
48
+ // with an editLayer the drawn feature goes into its source; without one it is only reported (the app adds it to `geojson`)
49
+ draw = new Draw({ ...(layer !== undefined && { source }), type: m, style: d.style });
50
+ draw.on('drawstart', (e) => { sketch = e.feature; });
51
+ draw.on('drawabort', () => { sketch = undefined; });
52
+ draw.on('drawend', (e) => { sketch = undefined; d.events().drawend?.({ feature: d.toGeoJSON(e.feature), olFeature: e.feature, ...tag }); });
53
+ ints.push(draw);
54
+ }
55
+ else if (m === 'modify') {
56
+ const mod = new Modify({ source, style: d.style });
57
+ mod.on('modifyend', (e) => d.events().modifyend?.({ features: report(e.features.getArray()), ...tag }));
58
+ ints.push(mod);
59
+ }
60
+ else {
61
+ const tr = new Translate({ layers: [l], hitTolerance: 6 });
62
+ tr.on('translateend', (e) => d.events().moveend?.({ features: report(e.features.getArray()), ...tag }));
63
+ ints.push(tr);
64
+ }
65
+ // Snap goes last, so it sees the pointer before the interactions above
66
+ if (snap)
67
+ ints.push(new Snap({ source }));
68
+ for (const i of ints)
69
+ d.map.addInteraction(i);
70
+ }
71
+ const enough = () => {
72
+ const g = sketch?.getGeometry();
73
+ return !!g && sketchVertices(g.getType(), g.getCoordinates()) >= (mode === 'Polygon' ? 3 : 2);
74
+ };
75
+ const finish = () => { if (draw && sketch && enough())
76
+ draw.finishDrawing(); };
77
+ const abort = () => { draw?.abortDrawing(); };
78
+ const undo = () => { if (sketch)
79
+ draw.removeLastPoint(); };
80
+ /** Add a vertex at `at` (map coordinates), from the keyboard: a point is placed at once, a line or polygon grows. */
81
+ const add = (at) => {
82
+ draw.appendCoordinates([at]);
83
+ if (mode === 'Point')
84
+ draw.finishDrawing();
85
+ };
86
+ return {
87
+ set,
88
+ finish, abort, undo,
89
+ /** Whether a draw mode (point, line, polygon) is active. */
90
+ get drawing() { return !!draw; },
91
+ /**
92
+ * The keyboard on the focused map while drawing: Space adds a vertex at the map centre (`center`), Enter finishes (or places a point),
93
+ * Backspace removes the last vertex, Escape drops the sketch. Returns whether the key was used.
94
+ */
95
+ key(e, center) {
96
+ if (!draw)
97
+ return false;
98
+ if (e.key === ' ' || (e.key === 'Enter' && mode === 'Point'))
99
+ add(center);
100
+ else if (e.key === 'Enter')
101
+ finish();
102
+ else if (e.key === 'Backspace' && sketch)
103
+ undo();
104
+ else if (e.key === 'Escape' && sketch)
105
+ abort();
106
+ else
107
+ return false;
108
+ e.preventDefault();
109
+ return true;
110
+ },
111
+ /** The theme changed: redraw the sketch and the vertex handles (their style reads the tokens when drawn). */
112
+ restyle() { for (const i of ints)
113
+ i.getOverlay?.().changed(); },
114
+ dispose() { token++; teardown(); mode = null; }
115
+ };
116
+ }
package/dist/index.d.ts CHANGED
@@ -8,7 +8,10 @@ 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, MapInitialView, MapControls, MapAttribution } from './types.js';
11
+ export type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, MapViewChange, FitOptions, FitTarget, MapApi, MapInitialView, MapControls, MapAttribution, MapPopupOptions, MapDrawMode, GeoJSONFeature, MapDrawEnd, MapEditEnd, MapLocateOptions, MapLocation, MapLocateError, MapContextMenuEvent } 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';
15
+ export type { MapLayer, MapLayerRequest, MapLayerData, MapLayerLoadState, BasemapTiles, BasemapOsm, BasemapLayer, BasemapStack, BasemapOption } from './types.js';
16
+ export { esriBasemaps, esriLabels, basemapTiles } from './basemaps.js';
17
+ export { propertyStyle, drawableSymbol, MARKER_SIZES, SIMPLESTYLE_KEYS } from './style.js';
package/dist/index.js CHANGED
@@ -3,3 +3,5 @@ export { default as ZoomControl } from './ZoomControl.svelte';
3
3
  export { default as Compass } from './Compass.svelte';
4
4
  export { default as ScaleBar } from './ScaleBar.svelte';
5
5
  export { default as Attribution } from './Attribution.svelte';
6
+ export { esriBasemaps, esriLabels, basemapTiles } from './basemaps.js';
7
+ export { propertyStyle, drawableSymbol, MARKER_SIZES, SIMPLESTYLE_KEYS } from './style.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * #302: the `layers` prop. Keeps one OpenLayers vector layer per `MapLayer` in step with the list: adds, removes and updates only what
3
+ * changed, loads bbox `loader` layers as the view moves, and styles every feature with `createFeatureStyle`. Loaded lazily by the Map.
4
+ */
5
+ import type OLMap from 'ol/Map.js';
6
+ import VectorLayer from 'ol/layer/Vector.js';
7
+ import VectorSource from 'ol/source/Vector.js';
8
+ import type { FeatureLike } from 'ol/Feature.js';
9
+ import { type MapTokens } from './ol-style.js';
10
+ import type { MapLayer } from './types.js';
11
+ export type LayerHost = {
12
+ map: OLMap;
13
+ tokens: () => Partial<MapTokens>;
14
+ /** Whether a feature of this layer is the selected one. */
15
+ selected: (layer: VectorLayer<VectorSource>, f: FeatureLike) => boolean;
16
+ /** Labels drawn at this resolution (`labelMinZoom`). */
17
+ labels: (resolution: number) => boolean;
18
+ /** A layer (or the selected feature in it) went away: the Map rechecks its selection. */
19
+ changed: () => void;
20
+ };
21
+ /** GeoJSON (lon/lat) to features with ids: the GeoJSON `id`, else `properties.id`, else the index. */
22
+ export declare function readGeo(data: object): import("ol/Feature.js").default<import("ol/geom.js").Geometry, {
23
+ [x: string]: any;
24
+ }>[];
25
+ /** A lon/lat box `pad` larger on each side, clamped to the world. */
26
+ export declare function padBox(ext: number[], pad: number): [number, number, number, number];
27
+ export declare class LayerManager {
28
+ #private;
29
+ constructor(host: LayerHost);
30
+ /** The OpenLayers layer of an entry. */
31
+ layer(id: string): VectorLayer<VectorSource<import("ol/Feature.js").default<import("ol/geom.js").Geometry, {
32
+ [x: string]: any;
33
+ }>>, import("ol/Feature.js").default<import("ol/geom.js").Geometry, {
34
+ [x: string]: any;
35
+ }>> | undefined;
36
+ /** Whether an OpenLayers layer is one of ours. */
37
+ owns(l: unknown): boolean;
38
+ /** Apply the list: remove what left, create what is new, update only what changed. */
39
+ sync(list: MapLayer[]): void;
40
+ /** New theme tokens or label zoom: drop the cached styles and redraw. */
41
+ restyle(): void;
42
+ /** The selection moved: redraw (cached styles carry the selection in their key). */
43
+ redraw(): void;
44
+ /** Load a loader layer again now. */
45
+ reload(id: string): void;
46
+ destroy(): void;
47
+ }