@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.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type OLMap from 'ol/Map.js';
2
+ import type { Snippet } from 'svelte';
2
3
  export type MarkerKind = 'neutral' | 'primary' | 'success' | 'warning' | 'danger';
3
4
  export type MapMarker = {
4
5
  id: string;
@@ -17,18 +18,67 @@ export type MapMarker = {
17
18
  width: number;
18
19
  };
19
20
  };
21
+ export type { Basemap, BasemapTiles, BasemapOsm, BasemapLayer, BasemapStack, BasemapOption } from './basemaps.js';
22
+ /** What a layer's `loader` is asked for: the view's lon/lat box, padded by a quarter on each side and clamped to the world. */
23
+ export type MapLayerRequest = {
24
+ /** `[west, south, east, north]` */
25
+ bbox: [number, number, number, number];
26
+ zoom: number;
27
+ /** Aborted when the view moves on before the request finished, or the layer goes away. */
28
+ signal: AbortSignal;
29
+ };
30
+ /** What a `loader` resolves to: GeoJSON (a FeatureCollection, a Feature, or an array of Features), or that with `truncated: true` when the box held more than you sent (the next move loads again even inside the same box). */
31
+ export type MapLayerData = object | {
32
+ geojson: object;
33
+ truncated?: boolean;
34
+ };
35
+ /** A layer's loading state, reported to its `onload`. */
36
+ export type MapLayerLoadState = {
37
+ loading: boolean;
38
+ count: number;
39
+ truncated: boolean;
40
+ error?: string;
41
+ };
20
42
  /**
21
- * Basemap: OpenStreetMap tiles (`'osm'`), none (themed graticule, works offline), any XYZ tile source, or
22
- * `{ osm: true }` for OSM tiles with your own `attribution` and/or `maxZoom`.
43
+ * One data layer of the `layers` prop: an OpenLayers vector layer the Map creates, styles and keeps in step with this object (matched by `id`;
44
+ * only what changed is applied, so an unchanged layer is never rebuilt). Features come from `geojson`, your own `source`, or a bbox `loader`.
23
45
  */
24
- export type Basemap = 'osm' | 'none' | {
25
- url: string;
26
- attribution?: string;
27
- maxZoom?: number;
28
- } | {
29
- osm: true;
30
- attribution?: string;
31
- maxZoom?: number;
46
+ export type MapLayer = {
47
+ /** Unique and stable: selection reports it as `layer`, `select(id, featureId)` and `layer(id)` take it. */
48
+ id: string;
49
+ /** GeoJSON in lon/lat (FeatureCollection or Feature). Replaced when a new object is passed. Feature ids: the GeoJSON `id`, else `properties.id`, else the index. */
50
+ geojson?: object;
51
+ /** Your own OpenLayers vector source (EPSG:3857 features) instead of `geojson`; the Map draws, hit-tests and fits it but never clears it (unless the layer also has a `loader`, whose answers replace its features). */
52
+ source?: import('ol/source/Vector.js').default;
53
+ /**
54
+ * Load features for the view: called (debounced 250ms) after the map moves while the layer is visible, unless the last answer covered the
55
+ * view and was not `truncated`. Each answer replaces the layer's features; a request the view outran is aborted and its answer ignored.
56
+ */
57
+ loader?: (request: MapLayerRequest) => Promise<MapLayerData | null | undefined>;
58
+ /** Loading state for a `loader` layer: `loading` while a request runs, then the feature `count`, `truncated`, or the `error` message. */
59
+ onload?: (state: MapLayerLoadState) => void;
60
+ /**
61
+ * The layer's look: a {@link import('./style.js').FeatureStyle} for every feature, or a function of a feature's properties returning one.
62
+ * A feature's own `style` object and simplestyle properties win over it (unless `simplestyle: false`); what neither sets takes the theme.
63
+ */
64
+ style?: import('./style.js').FeatureStyle | ((properties: Record<string, unknown>, feature: {
65
+ id: string | number | undefined;
66
+ type: string;
67
+ }) => import('./style.js').FeatureStyle | undefined);
68
+ /** Read each feature's own `style` and simplestyle properties. Default true. */
69
+ simplestyle?: boolean;
70
+ /** Default true. */
71
+ visible?: boolean;
72
+ /** Stacking order among all layers. Default `30 + index` (above the built-in GeoJSON, points and markers, later entries on top). */
73
+ zIndex?: number;
74
+ /** Take part in click, hover, keyboard selection and the default fit. Default true. */
75
+ interactive?: boolean;
76
+ /** A human-readable name, kept as the OpenLayers layer's `label` property (for a layer list you build). */
77
+ label?: string;
78
+ /** 0 to 1. Default 1. */
79
+ opacity?: number;
80
+ /** Hide overlapping labels and symbols (OpenLayers' `declutter`). Read when the layer is created. Default false. */
81
+ declutter?: boolean;
32
82
  };
33
83
  /** What `onviewchange` receives, and what `bind:extent` holds: the view after the map moved. */
34
84
  export type MapViewChange = {
@@ -98,6 +148,20 @@ export type MapApi = {
98
148
  * `id` `null`/`undefined` clears the selection. Returns false (and changes nothing) when the layer or the feature is not found.
99
149
  */
100
150
  select(layer: string | null, id: string | number | null | undefined): boolean;
151
+ /** Open the map's popup at `[lon, lat]` with your content (#303). It replaces the selection popup: one popup shows at a time. */
152
+ openPopup(lonLat: [number, number], options: MapPopupOptions): void;
153
+ /** Close the popup `openPopup` opened (its `onclose` runs). Does nothing when none is open. */
154
+ closePopup(): void;
155
+ /** Finish the line or polygon being drawn (`drawMode`), as Enter does. */
156
+ finishDrawing(): void;
157
+ /** Drop the sketch being drawn, as Escape does. */
158
+ abortDrawing(): void;
159
+ /** Remove the last vertex of the sketch being drawn, as Backspace does. */
160
+ undoLastPoint(): void;
161
+ /** The OpenLayers vector layer the `layers` entry `id` made (its source holds the features), or `undefined`. */
162
+ layer(id: string): import('ol/layer/Vector.js').default | undefined;
163
+ /** Load a `loader` layer again now, even when the last answer covered the view (after your data changed). */
164
+ reloadLayer(id: string): void;
101
165
  };
102
166
  /** Where the Map starts (`initialView`): a centre and zoom, or a lon/lat extent fitted once the container has a size. */
103
167
  export type MapInitialView = {
@@ -117,9 +181,102 @@ export type MapControls = {
117
181
  zoom?: boolean;
118
182
  /** Fit to data (see `fitTarget` and `onfit`). */
119
183
  fit?: boolean;
184
+ /** "Show my location" (off by default): `true`, or options. See `onlocate` / `onlocateerror`. */
185
+ locate?: boolean | MapLocateOptions;
186
+ /** The basemap switcher, shown when `basemaps` lists two or more. */
187
+ basemap?: boolean;
120
188
  };
121
189
  /** OpenLayers' attribution control of the Map (`attribution`). */
122
190
  export type MapAttribution = {
123
191
  /** `false` (expanded, the default), `true` (collapsed behind its button), or `'auto'`: collapsed while the map is narrower than 640px. */
124
192
  collapsed?: boolean | 'auto';
125
193
  };
194
+ /** What `openPopup` takes. */
195
+ export type MapPopupOptions = {
196
+ /** The popup body: a snippet, or an element you rendered (it is moved into the popup, and detached again when the popup closes). */
197
+ content: Snippet | HTMLElement;
198
+ /** Pan the map so the whole popup shows. Default true. */
199
+ autoPan?: boolean;
200
+ /** Show the × button. Default true; Escape closes the popup either way. */
201
+ closeButton?: boolean;
202
+ /** The popup's accessible name (it is a `role="dialog"`). Default: the `details` label. */
203
+ label?: string;
204
+ /** Runs once when the popup closes: × button, Escape, a click on the map, a new selection, another `openPopup`, or `closePopup()`. */
205
+ onclose?: () => void;
206
+ };
207
+ /** What the map draws or edits (`drawMode`): a new point, line or polygon, the vertices of existing features (`modify`), or whole features (`move`). */
208
+ export type MapDrawMode = 'Point' | 'LineString' | 'Polygon' | 'modify' | 'move';
209
+ /** A GeoJSON Feature in lon/lat (EPSG:4326). */
210
+ export type GeoJSONFeature = {
211
+ type: 'Feature';
212
+ id?: string | number;
213
+ geometry: {
214
+ type: string;
215
+ coordinates: unknown;
216
+ } | null;
217
+ properties: Record<string, unknown> | null;
218
+ };
219
+ /** What `ondrawend` receives. */
220
+ export type MapDrawEnd = {
221
+ /** The new feature as GeoJSON (lon/lat). */
222
+ feature: GeoJSONFeature;
223
+ /**
224
+ * The OpenLayers feature. With `editLayer` it is added to that layer's source right after this call: give it an id (`olFeature.setId(saved.id)`)
225
+ * once you have saved it, or remove it again (`source.removeFeature(olFeature)`). Without `editLayer` it is not added anywhere; add `feature` to your `geojson`.
226
+ */
227
+ olFeature: any;
228
+ /** The `editLayer` it was drawn into; absent for the map's own GeoJSON. */
229
+ layer?: string;
230
+ };
231
+ /** What `onmodifyend` and `onmoveend` receive: every feature the gesture changed, with its new geometry. */
232
+ export type MapEditEnd = {
233
+ features: {
234
+ id?: string | number;
235
+ feature: GeoJSONFeature;
236
+ olFeature: any;
237
+ }[];
238
+ /** The `editLayer`; absent for the map's own GeoJSON. */
239
+ layer?: string;
240
+ };
241
+ /** The `locate` control's options (`controls={{ locate: { ... } }}`). */
242
+ export type MapLocateOptions = {
243
+ /** Keep the view centred on each new position until the reader pans the map; pressing the button again re-centres and resumes. Default false. */
244
+ follow?: boolean;
245
+ /** Zoom in to at least this level on the first fix. Default 15. */
246
+ zoom?: number;
247
+ /** `PositionOptions.enableHighAccuracy`. Default true. */
248
+ enableHighAccuracy?: boolean;
249
+ /** `PositionOptions.timeout` in ms. Default 15000. */
250
+ timeout?: number;
251
+ /** `PositionOptions.maximumAge` in ms. Default 30000. */
252
+ maximumAge?: number;
253
+ };
254
+ /** What `onlocate` receives, on every position update while the locate control is on. */
255
+ export type MapLocation = {
256
+ /** `[lon, lat]` */
257
+ lonLat: [number, number];
258
+ /** Radius of the accuracy circle, in metres. */
259
+ accuracy: number;
260
+ heading: number | null;
261
+ speed: number | null;
262
+ timestamp: number;
263
+ };
264
+ /** What `onlocateerror` receives: `denied` (permission refused), `unavailable`, `timeout` or `unsupported` (no Geolocation API). `message` is the text the map shows. */
265
+ export type MapLocateError = {
266
+ code: 'denied' | 'unavailable' | 'timeout' | 'unsupported';
267
+ message: string;
268
+ };
269
+ /** What `oncontextmenu` receives: a right-click, a touch long-press, or the ContextMenu key / Shift+F10 on the focused map. */
270
+ export type MapContextMenuEvent = {
271
+ /** `[lon, lat]` of the point (the map centre, or the selected feature, from the keyboard). */
272
+ lonLat: [number, number];
273
+ /** The point in map pixels, from the map's top-left corner. */
274
+ pixel: [number, number];
275
+ /** The point in viewport (client) pixels: where to open a menu (`ContextMenu.open(x, y)`). */
276
+ x: number;
277
+ y: number;
278
+ /** The feature under the point (the selected one, from the keyboard): the map's own or a `trussInteractive` layer's. */
279
+ feature?: MapFeatureInfo;
280
+ /** What opened it. */
281
+ source: 'mouse' | 'touch' | 'keyboard';
282
+ };
package/dist/util.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type OLMap from 'ol/Map.js';
2
2
  export * from './style.js';
3
3
  export * from './points.js';
4
+ export * from './basemaps.js';
4
5
  /** Where a standalone control sits inside its (positioned) parent. `none` leaves placement to you. */
5
6
  export type ControlPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'none';
6
7
  export type ScaleUnit = 'metric' | 'imperial';
package/dist/util.js CHANGED
@@ -2,6 +2,7 @@ import { labelFor } from './labels.js';
2
2
  import { prefersReducedMotion } from '@ruckc/truss-ui';
3
3
  export * from './style.js';
4
4
  export * from './points.js';
5
+ export * from './basemaps.js';
5
6
  const LADDER = {
6
7
  metric: [['km', 1000], ['m', 1], ['cm', 0.01]],
7
8
  imperial: [['mi', 1609.344], ['ft', 0.3048], ['in', 0.0254]]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.56.0",
3
+ "version": "1.58.0",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,11 +20,16 @@
20
20
  ".": {
21
21
  "types": "./dist/index.d.ts",
22
22
  "svelte": "./dist/index.js"
23
+ },
24
+ "./ol-style": {
25
+ "types": "./dist/ol-style.d.ts",
26
+ "svelte": "./dist/ol-style.js",
27
+ "default": "./dist/ol-style.js"
23
28
  }
24
29
  },
25
30
  "peerDependencies": {
26
31
  "svelte": "^5.20.0",
27
- "@ruckc/truss-ui": "^1.0.0",
32
+ "@ruckc/truss-ui": "^1.58.0",
28
33
  "ol": "^10.0.0"
29
34
  },
30
35
  "devDependencies": {