@ruckc/truss-ol 1.28.0 → 1.29.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,63 @@
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
+ <!-- density heatmap weighted by magnitude -->
32
+ <Map points={quakes} pointsMode="heatmap" heatmap={{ weightBy: 'mag', radius: 8, blur: 12 }} />
33
+ ```
34
+
35
+ ## Props
36
+
37
+ | Prop | Purpose |
38
+ | --- | --- |
39
+ | `center` (bindable), `zoom` (bindable), `minZoom`, `maxZoom` | The view. `center` is `[lon, lat]`; zoom limits default to 1 and 19. |
40
+ | `basemap` | `'osm'`, `'none'` (themed graticule, works offline), `{ url, attribution?, maxZoom? }` or `{ osm: true, attribution?, maxZoom? }`. |
41
+ | `markers` | `{ id, lon, lat, label?, description?, kind? }[]`. Invalid coordinates are skipped. |
42
+ | `geojson` | A GeoJSON Feature or FeatureCollection. |
43
+ | `points` | A large point set: `{ lon, lat, ...properties }[]` or a GeoJSON FeatureCollection of points. |
44
+ | `pointsMode` | `'auto'` (points up to 2,000, clusters beyond), `'points'`, `'cluster'`, `'heatmap'`. |
45
+ | `clusterDistance`, `heatmap` | Cluster cell size in px; heatmap `radius`, `blur`, `weightBy`, `gradient`. |
46
+ | `style`, `legend` | Data-driven size and colour from feature properties (spec or function); `legend` draws the key. |
47
+ | `featureStyle` | Per-feature GeoJSON styling by function. Features may also carry `style` / simplestyle properties. |
48
+ | `selected` (bindable), `onselect` | Selection of a marker, GeoJSON feature or point, by click or keyboard. |
49
+ | `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. |
50
+ | `fitOnLoad`, `fitOnDataChange`, `refitOnResize` | When the view fits the data. |
51
+ | `height`, `onready` | Map height; `onready(api)` receives `{ map, fit, setView, getView, updateSize }`. |
52
+
53
+ Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`.
54
+
55
+ ### Large point sets
56
+
57
+ 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.
58
+
59
+ Standalone `ZoomControl`, `Compass`, `ScaleBar` and `Attribution` components are also exported for an `ol/Map` you own.
60
+
61
+ ## License
62
+
63
+ MIT