@ruckc/truss-ol 1.28.0 → 1.30.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 ADDED
@@ -0,0 +1,75 @@
1
+ # @ruckc/truss-ol
2
+
3
+ An [OpenLayers](https://openlayers.org) map for Svelte 5, styled by the [Truss UI](https://truss.ruck.io) design tokens: markers, GeoJSON, data-driven styling, clusters and heatmaps for large point sets, popups, selection and imperative view control. Colours follow the light/dark theme.
4
+
5
+ Docs: <https://truss.ruck.io/docs/packages>
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @ruckc/truss-ol @ruckc/truss-ui ol
11
+ ```
12
+
13
+ `svelte` (^5.20), `@ruckc/truss-ui` and `ol` (^10) are peer dependencies. OpenLayers is loaded lazily in the browser. For the exact chart palettes used by `style` colour scales, import the charts stylesheet once (`import '@ruckc/truss-chart/charts.css'`); without it built-in light values are used.
14
+
15
+ ## Usage
16
+
17
+ ```svelte
18
+ <script lang="ts">
19
+ import { Map } from '@ruckc/truss-ol';
20
+ let selected = $state<string>();
21
+ const quakes = $state.raw([{ lon: -122.4, lat: 37.8, mag: 4.1, depth: 8 } /* , ... */]);
22
+ </script>
23
+
24
+ <!-- a few markers and GeoJSON -->
25
+ <Map {markers} {geojson} basemap="osm" bind:selected height={420} />
26
+
27
+ <!-- a million points: clusters, size by magnitude, colour by depth -->
28
+ <Map points={quakes} pointsMode="cluster" legend
29
+ style={{ size: { by: 'mag', range: [2, 18] }, color: { by: 'depth', scale: 'sequential' } }} />
30
+
31
+ <!-- clusters sized by count and coloured by their strongest quake, with a legend -->
32
+ <Map points={quakes} pointsMode="cluster" legend
33
+ clusterStyle={{ size: { by: 'count' }, color: { by: { agg: 'max', prop: 'mag' }, title: 'Peak magnitude', format: (v) => `M${v.toFixed(1)}` } }} />
34
+
35
+ <!-- labels that never overlap, a hover tooltip and stable ids -->
36
+ <Map points={quakes} declutter labelMinZoom={4} idBy="code"
37
+ featureStyle={(p) => (p.mag >= 6 ? { label: `M${p.mag}` } : undefined)}
38
+ tooltip={(f) => `${f.properties.place} · M${f.properties.mag}`} />
39
+
40
+ <!-- density heatmap weighted by magnitude, with a legend -->
41
+ <Map points={quakes} pointsMode="heatmap" legend heatmap={{ weightBy: 'mag', radius: 8, blur: 12, title: 'Energy' }} />
42
+ ```
43
+
44
+ ## Props
45
+
46
+ | Prop | Purpose |
47
+ | --- | --- |
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? }`. |
50
+ | `markers` | `{ id, lon, lat, label?, description?, kind? }[]`. Invalid coordinates are skipped. |
51
+ | `geojson` | A GeoJSON Feature or FeatureCollection. |
52
+ | `points` | A large point set: `{ lon, lat, ...properties }[]` or a GeoJSON FeatureCollection of points. |
53
+ | `pointsMode` | `'auto'` (points up to 2,000, clusters beyond), `'points'`, `'cluster'`, `'heatmap'`. |
54
+ | `clusterDistance`, `heatmap` | Cluster cell size in px; heatmap `radius`, `blur`, `weightBy`, `gradient`, `title`. |
55
+ | `style`, `clusterStyle`, `legend` | Data-driven size and colour from feature properties (spec or function); clusters size and colour from aggregates (`by: 'count'` or `{ agg: 'sum' \| 'mean' \| 'min' \| 'max', prop }`). Every spec takes `title` and `format` for the legend; `legend` draws the key, including a heatmap ramp. |
56
+ | `declutter`, `labelMinZoom` | Labels on their own decluttered layer (the points always show); labels only from a zoom level. |
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
+ | `idBy` | Stable ids for points and GeoJSON features: a property name or `(properties, index) => id`, instead of `pt:n` / `geo:n`. |
59
+ | `featureStyle` | Per-feature GeoJSON styling by function. Features may also carry `style` / simplestyle properties. |
60
+ | `selected` (bindable), `onselect` | Selection of a marker, GeoJSON feature or point, by click or keyboard. `onselect` and `featurePopup` receive the `geometryType` (`Point`, `Polygon`, ...). |
61
+ | `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. |
62
+ | `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. |
63
+ | `height`, `onready` | Map height; `onready(api)` receives `{ map, fit, setView, getView, updateSize }`. |
64
+
65
+ Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`.
66
+
67
+ ### Large point sets
68
+
69
+ Points are held in typed arrays rather than OpenLayers features, so 10^6 points mount in about a second and re-cluster in tens of milliseconds while panning. Up to 20,000 points are clustered by OpenLayers' `Cluster` source; larger sets use an equivalent grid pass. `'points'` mode draws at most 100,000 points individually. Pass a plain array or `$state.raw`, not a deep `$state` proxy.
70
+
71
+ Standalone `ZoomControl`, `Compass`, `ScaleBar` and `Attribution` components are also exported for an `ol/Map` you own.
72
+
73
+ ## License
74
+
75
+ MIT