@ruckc/truss-ol 1.37.2 → 1.39.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
@@ -47,7 +47,7 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
47
47
  | --- | --- |
48
48
  | `center` (bindable), `zoom` (bindable), `minZoom`, `maxZoom` | The view. `center` is `[lon, lat]`; zoom limits default to 1 and 19. |
49
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. |
50
+ | `markers` | `{ id, lon, lat, label?, description?, kind?, colors?, radius?, stroke? }[]`. Invalid coordinates are skipped. |
51
51
  | `geojson` | A GeoJSON Feature or FeatureCollection. |
52
52
  | `points` | A large point set: `{ lon, lat, ...properties }[]` or a GeoJSON FeatureCollection of points. |
53
53
  | `pointsMode` | `'auto'` (points up to 2,000, clusters beyond), `'points'`, `'cluster'`, `'heatmap'`. |
@@ -56,7 +56,8 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
56
56
  | `declutter`, `labelMinZoom` | Labels on their own decluttered layer (the points always show); labels only from a zoom level. |
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
- | `featureStyle` | Per-feature GeoJSON styling by function. Features may also carry `style` / simplestyle properties. |
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. |
60
61
  | `selected` (bindable), `onselect` | Selection of a marker, GeoJSON feature or point, by click or keyboard. `onselect` and `featurePopup` receive the `geometryType` (`Point`, `Polygon`, ...). |
61
62
  | `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. |
62
63
  | `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,6 +65,20 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
64
65
 
65
66
  Methods (via `bind:this`): `fit(target?, { padding, duration, maxZoom })`, `setView({ center, zoom, duration })`, `getView()`, `updateSize()`.
66
67
 
68
+ ### Pie markers
69
+
70
+ `featureStyle` may return `{ colors, radius?, stroke?: { color, width } }` for a point. One colour is a filled circle; two to six are equal slices from 12 o'clock, clockwise (more than six are ignored); colours are any CSS colours, so hex strings from your data work. The outline defaults to black, 1px. Icons are drawn once to a canvas and cached by colours, radius and outline. A selected pie keeps its slices and gains a ring. `markers` accept `colors`, `radius` and `stroke` directly.
71
+
72
+ Supported: `geojson` points, `markers`, `points` in `'points'` mode, and the single points in `'cluster'` mode (OpenLayers clustering and the viewport grid above 20,000 points). Not applicable: clusters, which keep their count styling (`clusterStyle`), and the heatmap. Pies are bitmap icons, so favour clusters for very large sets.
73
+
74
+ ```svelte
75
+ <Map {points} pointsMode="points" idBy="code" featureStyle={(p) => ({ colors: p.status.map((s) => COLORS[s]), radius: 9 })} />
76
+ ```
77
+
78
+ ### Basemap and selection
79
+
80
+ `basemap={{ url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' }}` creates an XYZ source with that template. Changing `basemap` at runtime swaps only the tile layer: the map instance and the view are kept. A click on empty map clears the selection and calls `onselect(null)`.
81
+
67
82
  ### Large point sets
68
83
 
69
84
  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.
package/dist/Map.svelte CHANGED
@@ -3,9 +3,9 @@
3
3
  import { Button } from '@ruckc/truss-ui';
4
4
  import 'ol/ol.css';
5
5
  import type OLMap from 'ol/Map.js';
6
- import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewState } from './types.js';
6
+ import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
7
7
  import {
8
- DEFAULT_PALETTES, EMPTY_STORE, NATIVE_CLUSTER_MAX, aggregate, addStat, autoMode, clusterProps, clusterRadius, compactCount, compileCluster, compileStyle, cssGradient, featureTitle,
8
+ DEFAULT_PALETTES, EMPTY_STORE, NATIVE_CLUSTER_MAX, aggregate, drawPie, pieKey, pieStroke, addStat, autoMode, clusterProps, clusterRadius, compactCount, compileCluster, compileStyle, cssGradient, featureTitle,
9
9
  isLight, lonLatExtent, newStat, numbersOf, popupEntries, propertyStyle, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
10
10
  type ClusterInfo, type ClusterStyle, type Compiled, type CompiledCluster, type FeatureStyle, type HeatmapOptions, type LegendInfo, type MapStyle, type Palettes, type PointStore, type PointsInput, type PointsMode, type Props
11
11
  } from './util.js';
@@ -35,11 +35,13 @@
35
35
  featureTooltip,
36
36
  legend = false,
37
37
  selected = $bindable(),
38
+ extent = $bindable(),
38
39
  height = 420,
39
40
  fitOnLoad = true,
40
41
  popup,
41
42
  toolbar,
42
43
  onselect,
44
+ onviewchange,
43
45
  onready
44
46
  }: {
45
47
  /** [lon, lat] */
@@ -106,6 +108,8 @@
106
108
  featureStyle?: (properties: Props, feature: { id: string | number | undefined; type: string }) => FeatureStyle | undefined;
107
109
  /** Id of the selected marker, GeoJSON feature (its `id`, `properties.id`, or `geo:<n>`) or point. Bindable; set it to select, `undefined` to clear. */
108
110
  selected?: string;
111
+ /** The visible lon/lat extent `[west, south, east, north]`, updated whenever the map moves. Bindable, read-only output: setting it does nothing. */
112
+ extent?: [number, number, number, number];
109
113
  /** Map height: px, or any CSS length. Default 420. */
110
114
  height?: number | string;
111
115
  /** Fit the view to markers/features/points on first load (once the container has a size). */
@@ -125,6 +129,8 @@
125
129
  /** Extra controls appended to the toolbar. */
126
130
  toolbar?: Snippet;
127
131
  onselect?: (s: MapSelection | null) => void;
132
+ /** Fired when the map has moved (`moveend`) and once after the initial load and fit: the centre `[lon, lat]`, zoom and visible extent `[west, south, east, north]`. Not fired for a move that changed nothing. */
133
+ onviewchange?: (v: MapViewChange) => void;
128
134
  /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
129
135
  onready?: (api: MapApi) => void;
130
136
  } = $props();
@@ -166,7 +172,7 @@
166
172
  const [
167
173
  { default: OLMap }, { default: View }, { default: TileLayer }, { default: VectorLayer }, { default: VectorSource },
168
174
  { default: OSM }, { default: XYZ }, { default: Overlay }, { default: Feature }, { default: Point }, { default: GeoJSON },
169
- { Style, Circle: CircleStyle, Fill, Stroke, Text }, { fromLonLat, toLonLat, transformExtent }, { default: Attribution }, { default: ScaleLine },
175
+ { Style, Circle: CircleStyle, Fill, Stroke, Text, Icon }, { fromLonLat, toLonLat, transformExtent }, { default: Attribution }, { default: ScaleLine },
170
176
  { default: Graticule }, { createEmpty, extend, isEmpty, boundingExtent, getCenter, intersects }, { default: Cluster }, { default: Heatmap }
171
177
  ] = await Promise.all([
172
178
  import('ol/Map.js'), import('ol/View.js'), import('ol/layer/Tile.js'), import('ol/layer/Vector.js'), import('ol/source/Vector.js'),
@@ -238,9 +244,35 @@
238
244
  return v === undefined || v === null || v === '' ? undefined : String(v);
239
245
  };
240
246
 
247
+ /** Pie icons by colours, radius and outline: one canvas per distinct look, however many features share it. */
248
+ const pies = new Map<string, any>();
249
+ const pieIcon = (colors: string[], radius: number, stroke: ReturnType<typeof pieStroke>) => {
250
+ const key = pieKey(colors, radius, stroke);
251
+ let ic = pies.get(key);
252
+ if (!ic) {
253
+ const ratio = Math.ceil(window.devicePixelRatio);
254
+ const cv = drawPie(colors, radius, stroke, ratio);
255
+ pies.set(key, ic = new Icon({ img: cv, scale: 1 / ratio }));
256
+ }
257
+ return ic;
258
+ };
259
+ /** The selected pie: a primary ring and halo around it, beneath the pie. */
260
+ 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 }) }) });
261
+
241
262
  const markerStyle = (f: any) => {
242
263
  const on = f.getId() === selected;
243
264
  const c = tone(f.get('kind'));
265
+ const colors: string[] | undefined = f.get('colors');
266
+ if (colors?.length) {
267
+ const r = f.get('radius') ?? 7;
268
+ return [
269
+ ...(on ? [pieRing(r)] : []),
270
+ new Style({
271
+ image: pieIcon(colors, r, pieStroke(f.get('stroke'))),
272
+ text: f.get('label') ? new Text({ text: f.get('label'), offsetY: r + 11, font: '600 12px Inter Variable, system-ui, sans-serif', fill: new Fill({ color: T['on-surface'] }), stroke: new Stroke({ color: T.surface, width: 3 }) }) : undefined
273
+ })
274
+ ];
275
+ }
244
276
  return [
245
277
  ...(on ? [new Style({ image: new CircleStyle({ radius: 14, fill: new Fill({ color: rgba(c, 0.25) }) }) })] : []),
246
278
  new Style({
@@ -265,16 +297,21 @@
265
297
  const o: FeatureStyle = { ...propertyStyle(p), ...featureStyle?.(p, { id: f.getId(), type: t }) };
266
298
  const base = compiled.color?.(p) ?? tone(f.get('kind'));
267
299
  const fillC = o.fill ?? base, op = o.opacity ?? compiled.opacity, on = isSel(f);
300
+ const strokeC = typeof o.stroke === 'object' ? o.stroke.color : o.stroke, strokeW = typeof o.stroke === 'object' ? o.stroke.width : undefined;
268
301
  if (t === 'Point' || t === 'MultiPoint') {
269
302
  const r = o.radius ?? compiled.size?.(p) ?? 5;
303
+ if (o.colors?.length) {
304
+ const pie = new Style({ image: pieIcon(o.colors, r, pieStroke(o.stroke, o.strokeWidth)), text: labelText(o.label, r + 12) });
305
+ return on ? [pieRing(r), pie] : pie;
306
+ }
270
307
  const dot = new Style({
271
- image: new CircleStyle({ radius: on ? r + 2 : r, fill: new Fill({ color: op === undefined ? fillC : rgba(fillC, op) }), stroke: new Stroke({ color: o.stroke ?? T.surface, width: o.strokeWidth ?? 1.5 }) }),
308
+ image: new CircleStyle({ radius: on ? r + 2 : r, fill: new Fill({ color: op === undefined ? fillC : rgba(fillC, op) }), stroke: new Stroke({ color: strokeC ?? T.surface, width: o.strokeWidth ?? strokeW ?? 1.5 }) }),
272
309
  text: labelText(o.label, r + 12)
273
310
  });
274
311
  return on ? [new Style({ image: new CircleStyle({ radius: r + 8, fill: new Fill({ color: rgba(fillC, 0.25) }) }) }), dot] : dot;
275
312
  }
276
313
  return new Style({
277
- stroke: new Stroke({ color: o.stroke ?? base, width: (o.strokeWidth ?? 2.5) + (on ? 1.5 : 0), lineCap: 'round', lineJoin: 'round' }),
314
+ stroke: new Stroke({ color: strokeC ?? base, width: (o.strokeWidth ?? strokeW ?? 2.5) + (on ? 1.5 : 0), lineCap: 'round', lineJoin: 'round' }),
278
315
  fill: new Fill({ color: rgba(fillC, Math.min(1, (op ?? 0.14) + (on ? 0.14 : 0))) }),
279
316
  text: labelText(o.label, 0)
280
317
  });
@@ -357,6 +394,16 @@
357
394
  heatSrc.clear(true);
358
395
  heatSrc.addFeatures(cells.map((c) => new Feature({ geometry: new Point([c.x, c.y]), w: c.weight / peak })));
359
396
  };
397
+ let lastView = '';
398
+ /** Tell the consumer where the map is now, unless it is where we last said. */
399
+ const emitView = () => {
400
+ const v = ctl!.getView() as MapViewChange;
401
+ const key = `${v.center}|${v.zoom}|${v.extent}`;
402
+ if (key === lastView) return;
403
+ lastView = key;
404
+ extent = v.extent;
405
+ onviewchange?.(v);
406
+ };
360
407
  const refreshView = () => { if (mode === 'heatmap') refreshHeat(); else if (mode === 'cluster' && store.n > NATIVE_CLUSTER_MAX) refreshAgg(); };
361
408
  const heatGradient = () => {
362
409
  const s = heatmap?.gradient ?? P.sequential.slice(1);
@@ -382,7 +429,7 @@
382
429
  markers() {
383
430
  markerSrc.clear();
384
431
  markerSrc.addFeatures(markers.filter((m) => validLonLat(m.lon, m.lat)).map((m) => {
385
- const f = new Feature({ geometry: new Point(fromLonLat([m.lon, m.lat])), label: m.label, kind: m.kind });
432
+ const f = new Feature({ geometry: new Point(fromLonLat([m.lon, m.lat])), label: m.label, kind: m.kind, colors: m.colors, radius: m.radius, stroke: m.stroke });
386
433
  f.setId(m.id);
387
434
  return f;
388
435
  }));
@@ -485,6 +532,7 @@
485
532
  zoom = Number((view.getZoom() ?? 0).toFixed(2));
486
533
  seenC = [center[0], center[1]]; seenZ = zoom;
487
534
  refreshView();
535
+ emitView();
488
536
  });
489
537
  /** Select a feature (marker, GeoJSON feature or point) as a click or the keyboard would; `at` anchors the popup for shapes. */
490
538
  const choose = (f: any, at?: number[]) => {
@@ -562,6 +610,7 @@
562
610
  sync.base(); sync.markers(); sync.geo(); sync.points();
563
611
  if (fitPending && el.clientWidth && el.clientHeight) { fitPending = false; ctl.fit(undefined, { duration: 0 }); }
564
612
  ready = true;
613
+ emitView();
565
614
  onready?.({ map, fit: ctl.fit, setView: ctl.setView, getView: ctl.getView, updateSize: ctl.updateSize });
566
615
 
567
616
  dispose = () => {
@@ -1,6 +1,6 @@
1
1
  import { type Snippet } from 'svelte';
2
2
  import 'ol/ol.css';
3
- import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewState } from './types.js';
3
+ import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
4
4
  import { type ClusterStyle, type FeatureStyle, type HeatmapOptions, type MapStyle, type PointsInput, type PointsMode, type Props } from './util.js';
5
5
  type $$ComponentProps = {
6
6
  /** [lon, lat] */
@@ -70,6 +70,8 @@ type $$ComponentProps = {
70
70
  }) => FeatureStyle | undefined;
71
71
  /** Id of the selected marker, GeoJSON feature (its `id`, `properties.id`, or `geo:<n>`) or point. Bindable; set it to select, `undefined` to clear. */
72
72
  selected?: string;
73
+ /** The visible lon/lat extent `[west, south, east, north]`, updated whenever the map moves. Bindable, read-only output: setting it does nothing. */
74
+ extent?: [number, number, number, number];
73
75
  /** Map height: px, or any CSS length. Default 420. */
74
76
  height?: number | string;
75
77
  /** Fit the view to markers/features/points on first load (once the container has a size). */
@@ -89,6 +91,8 @@ type $$ComponentProps = {
89
91
  /** Extra controls appended to the toolbar. */
90
92
  toolbar?: Snippet;
91
93
  onselect?: (s: MapSelection | null) => void;
94
+ /** Fired when the map has moved (`moveend`) and once after the initial load and fit: the centre `[lon, lat]`, zoom and visible extent `[west, south, east, north]`. Not fired for a move that changed nothing. */
95
+ onviewchange?: (v: MapViewChange) => void;
92
96
  /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
93
97
  onready?: (api: MapApi) => void;
94
98
  };
@@ -99,6 +103,6 @@ declare const Map: import("svelte").Component<$$ComponentProps, {
99
103
  }) => void;
100
104
  getView: () => MapViewState | undefined;
101
105
  updateSize: () => void;
102
- }, "selected" | "center" | "zoom">;
106
+ }, "selected" | "center" | "zoom" | "extent">;
103
107
  type Map = ReturnType<typeof Map>;
104
108
  export default Map;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ 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 type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, FitOptions, FitTarget, MapApi } from './types.js';
7
- export type { MapStyle, SizeSpec, ColorSpec, FeatureStyle, LegendInfo, ClusterStyle, ClusterSizeSpec, ClusterColorSpec, ClusterBy, ClusterAgg, ClusterInfo } from './style.js';
6
+ export type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, MapViewChange, FitOptions, FitTarget, MapApi } from './types.js';
7
+ export type { MapStyle, SizeSpec, ColorSpec, FeatureStyle, PieStroke, LegendInfo, ClusterStyle, ClusterSizeSpec, ClusterColorSpec, ClusterBy, ClusterAgg, ClusterInfo } from './style.js';
8
8
  export type { PointsInput, PointInput, PointsMode, HeatmapOptions } from './points.js';
9
9
  export type { ControlPosition, ScaleUnit, HeadingStatus } from './util.js';
package/dist/style.d.ts CHANGED
@@ -158,18 +158,38 @@ export type Compiled = {
158
158
  * spec's domain or categories (not when given, nor for function and constant forms).
159
159
  */
160
160
  export declare function compileStyle(style: MapStyle | undefined, rows: Iterable<Props>, palettes?: Palettes): Compiled;
161
+ /** The outline of a pie marker. Default: black, 1px. */
162
+ export type PieStroke = {
163
+ color: string;
164
+ width: number;
165
+ };
166
+ export declare const PIE_MAX = 6;
167
+ /** The pie outline `stroke` describes (a colour string, an object, or nothing for the default), width falling back to `width` then 1. */
168
+ export declare function pieStroke(stroke: string | Partial<PieStroke> | undefined, width?: number): PieStroke;
169
+ /** The cache key of a pie icon: its (at most six) colours, radius and outline. */
170
+ export declare function pieKey(colors: string[], radius: number, stroke: PieStroke): string;
171
+ /**
172
+ * Draw a pie marker to a canvas: `colors` (1 to 6) as equal slices from 12 o'clock, clockwise, outlined by `stroke`.
173
+ * The canvas is `ratio` times larger than the marker's CSS size (`2 * radius + stroke width + 2` px square); the marker is centred.
174
+ */
175
+ export declare function drawPie(colors: string[], radius: number, stroke: PieStroke, ratio?: number, doc?: Document): HTMLCanvasElement;
161
176
  /** Per-feature drawing overrides. Any field left out keeps the feature's default (or data-driven) look. */
162
177
  export type FeatureStyle = {
163
178
  /** Fill colour of polygons and points. */
164
179
  fill?: string;
165
180
  /** Fill opacity 0 to 1. */
166
181
  opacity?: number;
167
- /** Outline / line colour. */
168
- stroke?: string;
182
+ /** Outline / line colour. For a pie (`colors`) the outline as `{ color, width }`; a plain colour string works there too. */
183
+ stroke?: string | PieStroke;
169
184
  /** Outline / line width in px. */
170
185
  strokeWidth?: number;
171
186
  /** Point radius in px. */
172
187
  radius?: number;
188
+ /**
189
+ * Points only: draw a pie marker instead of a dot. One colour is a filled circle; two to six (extra ones are ignored) are equal slices
190
+ * starting at 12 o'clock and running clockwise. Any CSS colour, e.g. hex strings straight from your data. Wins over `fill`.
191
+ */
192
+ colors?: string[];
173
193
  /** Text drawn next to the feature. */
174
194
  label?: string;
175
195
  };
package/dist/style.js CHANGED
@@ -131,6 +131,55 @@ export function compileStyle(style, rows, palettes = DEFAULT_PALETTES) {
131
131
  }
132
132
  return out;
133
133
  }
134
+ export const PIE_MAX = 6;
135
+ /** The pie outline `stroke` describes (a colour string, an object, or nothing for the default), width falling back to `width` then 1. */
136
+ export function pieStroke(stroke, width) {
137
+ if (stroke && typeof stroke === 'object')
138
+ return { color: stroke.color ?? '#000000', width: stroke.width ?? width ?? 1 };
139
+ return { color: stroke || '#000000', width: width ?? 1 };
140
+ }
141
+ /** The cache key of a pie icon: its (at most six) colours, radius and outline. */
142
+ export function pieKey(colors, radius, stroke) {
143
+ return `${colors.slice(0, PIE_MAX).join(',')}|${radius}|${stroke.color}|${stroke.width}`;
144
+ }
145
+ /**
146
+ * Draw a pie marker to a canvas: `colors` (1 to 6) as equal slices from 12 o'clock, clockwise, outlined by `stroke`.
147
+ * The canvas is `ratio` times larger than the marker's CSS size (`2 * radius + stroke width + 2` px square); the marker is centred.
148
+ */
149
+ export function drawPie(colors, radius, stroke, ratio = 1, doc = document) {
150
+ const cols = colors.slice(0, PIE_MAX);
151
+ const size = Math.ceil(2 * radius + stroke.width + 2);
152
+ const cv = doc.createElement('canvas');
153
+ cv.width = cv.height = Math.ceil(size * ratio);
154
+ const g = cv.getContext('2d');
155
+ g.scale(ratio, ratio);
156
+ const c = size / 2;
157
+ g.lineJoin = 'round';
158
+ g.strokeStyle = stroke.color;
159
+ g.lineWidth = stroke.width;
160
+ if (cols.length === 1) {
161
+ g.beginPath();
162
+ g.arc(c, c, radius, 0, Math.PI * 2);
163
+ g.fillStyle = cols[0];
164
+ g.fill();
165
+ if (stroke.width > 0)
166
+ g.stroke();
167
+ return cv;
168
+ }
169
+ const step = (Math.PI * 2) / cols.length;
170
+ cols.forEach((col, i) => {
171
+ const a0 = -Math.PI / 2 + i * step;
172
+ g.beginPath();
173
+ g.moveTo(c, c);
174
+ g.arc(c, c, radius, a0, a0 + step);
175
+ g.closePath();
176
+ g.fillStyle = col;
177
+ g.fill();
178
+ if (stroke.width > 0)
179
+ g.stroke();
180
+ });
181
+ return cv;
182
+ }
134
183
  const SIMPLE = { fill: 'fill', 'fill-opacity': 'opacity', stroke: 'stroke', 'stroke-width': 'strokeWidth', 'marker-size': 'radius', title: 'label' };
135
184
  /**
136
185
  * The style a GeoJSON feature carries in its own properties: a `style` object (`{ fill, opacity, stroke, strokeWidth, radius, label }`)
package/dist/types.d.ts CHANGED
@@ -7,6 +7,15 @@ export type MapMarker = {
7
7
  label?: string;
8
8
  description?: string;
9
9
  kind?: MarkerKind;
10
+ /** Draw a pie instead of the dot: one colour is a filled circle, two to six are equal slices from 12 o'clock, clockwise. Any CSS colour. */
11
+ colors?: string[];
12
+ /** Pie radius in px. Default 7. */
13
+ radius?: number;
14
+ /** Pie outline. Default black, 1px. */
15
+ stroke?: {
16
+ color: string;
17
+ width: number;
18
+ };
10
19
  };
11
20
  /**
12
21
  * Basemap: OpenStreetMap tiles (`'osm'`), none (themed graticule, works offline), any XYZ tile source, or
@@ -21,6 +30,12 @@ export type Basemap = 'osm' | 'none' | {
21
30
  attribution?: string;
22
31
  maxZoom?: number;
23
32
  };
33
+ /** What `onviewchange` receives, and what `bind:extent` holds: the view after the map moved. */
34
+ export type MapViewChange = {
35
+ center: [number, number];
36
+ zoom: number;
37
+ extent: [number, number, number, number];
38
+ };
24
39
  export type MapSelection = {
25
40
  type: 'marker';
26
41
  marker: MapMarker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.37.2",
3
+ "version": "1.39.0",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",