@ruckc/truss-ol 1.55.1 → 1.57.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
@@ -57,13 +57,73 @@ 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` and once after the initial load and fit; `extent` is `[west, south, east, north]`. `bind:extent` is a read-only output. Neither fires when the view did not change, so applying `center`/`zoom` does not loop. |
61
- | `selected` (bindable), `onselect` | Selection of a marker, GeoJSON feature or point, by click or keyboard. `onselect` and `featurePopup` receive the `geometryType` (`Point`, `Polygon`, ...). |
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); `{{ 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. |
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. |
67
+ | `drawMode`, `editLayer`, `snap`, `ondrawend`, `onmodifyend`, `onmoveend` | Draw a point, line or polygon, drag vertices (`'modify'`) or whole features (`'move'`) on an app layer (by its `id` property) or the map's GeoJSON. See below. |
68
+ | `onlocate`, `onlocateerror` | The `controls.locate` button's positions and errors. |
69
+ | `oncontextmenu` | Right-click, touch long-press, ContextMenu key / Shift+F10: `{ lonLat, pixel, x, y, feature?, source }`. |
63
70
  | `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 }`. |
71
+ | `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 }`. |
65
72
 
66
- Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`.
73
+ 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()`.
74
+
75
+ ### Your own layers
76
+
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
78
+ 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
+ property names it in `onselect`, in `featurePopup`'s `feature.layer`, and in `select()`. Its features need ids (`feature.setId`).
80
+
81
+ ```ts
82
+ const roads = new VectorLayer({ source, properties: { id: 'roads', trussInteractive: true } });
83
+ api.map.addLayer(roads);
84
+ // onselect: { type: 'feature', id: 'r1', properties, geometryType: 'LineString', layer: 'roads' }
85
+ api.select('roads', 'r1'); // select from code (any vector layer with that id); no onselect, like setting `selected`
86
+ api.select(null, 'm1'); // one of the map's own features
87
+ api.select(null, null); // clear
88
+ ```
89
+
90
+ ### An app map, edge to edge
91
+
92
+ ```svelte
93
+ <Map variant="bare" basemap={{ url, attribution }} fitOnLoad={false}
94
+ initialView={savedView() ?? { extent: [-125, 24, -66, 50] }}
95
+ controls={{ fit: true }} onfit={fitVisibleLayers}
96
+ attribution={{ collapsed: 'auto' }}
97
+ onviewchange={(v) => localStorage.setItem('view', JSON.stringify(v))} {onready} />
98
+ ```
99
+
100
+ `onviewchange` only reports moves, so saving every change never overwrites the saved view with the default one.
101
+
102
+ ### Your own popup, drawing, my location and a context menu (#303)
103
+
104
+ ```svelte
105
+ <script lang="ts">
106
+ import { Map, type MapApi, type MapDrawMode } from '@ruckc/truss-ol';
107
+ let api: MapApi;
108
+ let mode = $state<MapDrawMode | null>(null);
109
+ </script>
110
+
111
+ {#snippet place()}<PlaceCard feature={hit} />{/snippet}
112
+
113
+ <Map onready={(a) => (api = a)}
114
+ drawMode={mode} editLayer="places" ondrawend={saveNew} onmodifyend={saveEdits} onmoveend={saveEdits}
115
+ controls={{ locate: { follow: true } }} onlocateerror={(e) => console.warn(e.code)}
116
+ oncontextmenu={(e) => menu.open(e.x, e.y)} />
117
+
118
+ <!-- anywhere: api.openPopup(lonLat, { content: place, label: hit.name, onclose }) / api.closePopup() -->
119
+ ```
120
+
121
+ - **Popup:** `openPopup(lonLat, { content: Snippet | HTMLElement, autoPan?, closeButton?, label?, onclose? })` and `closePopup()` (on the api and the component) use the selection popup's card and arrow. One popup at a time: it replaces the selection popup until the selection changes. A `role="dialog"`; focus moves in (first control, else the card) and back on close; `Escape`, the × button, a click on the map, a new selection or another `openPopup` close it.
122
+ - **Draw and edit:** `drawMode` `'Point' | 'LineString' | 'Polygon' | 'modify' | 'move' | null` on `editLayer` (the `id` property of a vector layer you added; drawn features go into its source) or the map's own `geojson` (drawn features are only reported). `ondrawend({ feature, olFeature, layer })`, `onmodifyend` / `onmoveend({ features: [{ id, feature, olFeature }], layer })`, with GeoJSON in lon/lat. `snap` (default true), a sketch in the primary colour, clicks do not select while drawing. Keyboard on the focused map: Space adds a vertex at the centre, Enter finishes (or places a point), Backspace undoes, Escape cancels; `finishDrawing()`, `abortDrawing()`, `undoLastPoint()` on the api. The interactions load on first use.
123
+ - **Locate:** `controls={{ locate: true }}` or `{ follow, zoom, enableHighAccuracy, timeout, maximumAge }` adds a "Show my location" button: an accuracy circle and a dot in the primary colour, `onlocate({ lonLat, accuracy, heading, speed, timestamp })` on every update, an `onlocateerror({ code: 'denied' | 'unavailable' | 'timeout' | 'unsupported', message })` plus a `role="alert"` notice. `follow` keeps the view on the position until the reader pans; the next press re-centres, a press while centred stops.
124
+ - **Context menu:** `oncontextmenu({ lonLat, pixel, x, y, feature?, source })` on right-click, touch long-press, and the ContextMenu key or Shift+F10 on the focused map (at the selected feature, else the centre). It only reports where; open truss-ui's `ContextMenu` with `open(x, y)` (#304).
125
+
126
+ All new texts are `MapLabels` keys: `details`, `locate`, `located`, `locateDenied`, `locateUnavailable`, `locateUnsupported`, `drawing`.
67
127
 
68
128
  ### Pie markers
69
129