@ruckc/truss-ol 1.58.0 → 1.59.1

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
@@ -65,8 +65,9 @@ npm install @ruckc/truss-ol @ruckc/truss-ui ol
65
65
  | `controls`, `fitTarget`, `onfit` | `controls={{ zoom: false }}` / `{{ fit: false }}` / `{{ basemap: false }}` hide built-in buttons (all show by default, the basemap switcher once `basemaps` lists two or more; the `toolbar` snippet always shows). `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. |
66
66
  | `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. |
67
67
  | `variant` | `'bare'`: no border, no radius, and the full height of its container unless `height` is set (an edge-to-edge map). |
68
- | `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`, ...). |
69
- | `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. |
68
+ | `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`, ...); `onselect` also gets `lonLat`, where the click landed (from the keyboard: the marker, or the feature's popup anchor). |
69
+ | `popup`, `featurePopup`, `toolbar` | Snippets: marker popup body, feature popup body, extra toolbar controls. `featurePopup={false}` turns the built-in feature popup off (see [Your own popup](#your-own-popup-for-a-selection)). |
70
+ | `popupAutoPan` | Pan the map so the selection popup shows whole when a marker or feature is selected. Default true. |
70
71
  | `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. |
71
72
  | `onlocate`, `onlocateerror` | The `controls.locate` button's positions and errors. |
72
73
  | `oncontextmenu` | Right-click, touch long-press, ContextMenu key / Shift+F10: `{ lonLat, pixel, x, y, feature?, source }`. |
@@ -84,7 +85,7 @@ Each `layers` entry is an OpenLayers vector layer the Map creates and keeps in s
84
85
 
85
86
  - **Style:** `style` is a `FeatureStyle` for every feature or `(properties, { id, type }) => FeatureStyle`. A feature's own `style` object and simplestyle properties win over it (`simplestyle: false` turns that off); whatever neither sets takes the theme tokens.
86
87
  - **Order and visibility:** `zIndex` defaults to `30 + index` (above the built-in GeoJSON, points and markers; later entries on top); `visible`, `opacity`, `declutter` (read when the layer is created) and `label` (kept as the OpenLayers layer's `label` property, for your layer list).
87
- - **Selection:** layers are `interactive` by default: click, hover, Enter/Shift+Enter, `onselect` (`layer: id`), `select(id, featureId)`, the popup and the default fit all include them. `interactive: false` leaves a layer out of hit testing (the fit still covers it while visible).
88
+ - **Selection:** layers are `interactive` by default: click, hover, Enter/Shift+Enter, `onselect` (`layer: id`), `select(id, featureId)`, the popup and the default fit all include them. `interactive: false` leaves a layer out of hit testing (the fit still covers it while visible). `popup: false` keeps the layer selectable but shows no built-in popup for its features.
88
89
  - **Loader:** `loader({ bbox, zoom, signal })` is called after the map moves (debounced 250ms) with the view padded by a quarter, unless the last answer covered the view. Resolve to GeoJSON, or `{ geojson, truncated: true }` when the box held more than you sent (the next move loads again). A request the view outran is aborted (`signal`) and its answer ignored. `onload({ loading, count, truncated, error? })` reports progress; `reloadLayer(id)` loads again now.
89
90
  - Pass a plain array (or `$state.raw`), as for `geojson`; each entry's own fields are still watched, so a change inside a `$state` list applies too.
90
91
 
@@ -183,8 +184,21 @@ api.select(null, null); // clear
183
184
  <!-- anywhere: api.openPopup(lonLat, { content: place, label: hit.name, onclose }) / api.closePopup() -->
184
185
  ```
185
186
 
186
- - **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.
187
- - **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.
187
+ - **Popup:** `openPopup(lonLat, { content: Snippet | HTMLElement, autoPan?, closeButton?, label?, maxWidth?, 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. The card is at most 260px wide: `maxWidth` (px, or any CSS length such as `'min(360px, 80vw)'`) widens one popup, and the `--trm-popup-max-width` custom property on the Map or an ancestor sets it for every popup, the selection popup included.
188
+
189
+ #### Your own popup for a selection
190
+
191
+ `featurePopup={false}` turns off the built-in property-list popup for features (GeoJSON, points and layers; markers keep theirs). The selection, its halo, `bind:selected`, keyboard selection and `onselect` all work as before, and `onselect` reports `lonLat`: where the click or tap landed, or from the keyboard the feature's popup anchor (a point's position, the centre of a line's or polygon's extent). Open your own popup there:
192
+
193
+ ```svelte
194
+ {#snippet details()}<PlaceCard feature={hit} />{/snippet}
195
+
196
+ <Map {layers} featurePopup={false} onready={(a) => (api = a)}
197
+ onselect={(s) => { hit = s; if (s) api.openPopup(s.lonLat, { content: details }); }} />
198
+ ```
199
+
200
+ To turn it off for one layer only, give its `layers` entry `popup: false` (or a `trussInteractive` layer of your own the `trussPopup: false` property). The built-in popup pans into view when it opens (`popupAutoPan`, default true), as `openPopup`'s `autoPan` does.
201
+ - **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 once, when `drawMode` or `editLayer` is first set; after that every mode switch is synchronous. Clicks and drawing keys given while the very first draw mode still loads are buffered and replayed in order once it is live (never dropped, never taken as a selection); set `editLayer` up front to have the interactions ready before the first switch.
188
202
  - **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.
189
203
  - **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).
190
204
 
package/dist/Map.svelte CHANGED
@@ -119,6 +119,7 @@
119
119
  geojson,
120
120
  featureStyle,
121
121
  featurePopup,
122
+ popupAutoPan = true,
122
123
  fitOnDataChange = false,
123
124
  refitOnResize = false,
124
125
  minZoom = 1,
@@ -269,8 +270,15 @@
269
270
  maxZoom?: number;
270
271
  /** Custom popup body for the selected marker. */
271
272
  popup?: Snippet<[marker: MapMarker]>;
272
- /** Custom popup body for a selected GeoJSON feature or point; without it the popup lists the feature's properties. */
273
- featurePopup?: Snippet<[feature: MapFeatureInfo]>;
273
+ /**
274
+ * Custom popup body for a selected GeoJSON feature, point or layer feature; without it the popup lists the feature's properties.
275
+ * `false` shows no popup for features (selection, its halo, `onselect` and the keyboard still work): open your own with
276
+ * `onselect={(s) => s && api.openPopup(s.lonLat, { content })}`. One layer can opt out alone with `popup: false` on its `layers` entry
277
+ * (or the `trussPopup: false` property on a `trussInteractive` layer of your own).
278
+ */
279
+ featurePopup?: Snippet<[feature: MapFeatureInfo]> | false;
280
+ /** Pan the map so the whole selection popup shows when a marker or feature is selected, as `openPopup`'s `autoPan` does. Default true. */
281
+ popupAutoPan?: boolean;
274
282
  /** Extra controls appended to the toolbar. */
275
283
  toolbar?: Snippet;
276
284
  /**
@@ -340,6 +348,10 @@
340
348
  // the app layer (`trussInteractive`, or picked by `select(layerId, …)`) the selected feature belongs to; undefined for the map's own features
341
349
  let selLayer = $state.raw<any>(undefined);
342
350
  let fsel = $state.raw<MapFeatureInfo | null>(null);
351
+ /** #305: the selected feature's layer shows no popup (`popup: false` on its `layers` entry, or `trussPopup: false` on an app layer). */
352
+ let layerNoPopup = $state(false);
353
+ /** #305: the selection popup is off for the selected feature (`featurePopup={false}`, or its layer's own setting). */
354
+ const noPopup = $derived(!!fsel && (featurePopup === false || layerNoPopup));
343
355
  let tip = $state.raw<MapFeatureInfo | null>(null);
344
356
  let tipEl: HTMLDivElement;
345
357
  const uid = $props.id();
@@ -390,6 +402,8 @@
390
402
  const locOpts = $derived(locateOptions(controls?.locate));
391
403
  const sketchMode = $derived(isDrawMode(drawMode));
392
404
  /** Moves an element the app rendered into the popup, and detaches it again when the popup closes. */
405
+ /** #306: `openPopup`'s `maxWidth` (a number is px) as the card's custom property; nothing when unset, so the inherited value applies. */
406
+ const popupWidth = (w: number | string | undefined): Record<string, string> => w === undefined ? {} : { '--trm-popup-max-width': typeof w === 'number' ? `${w}px` : w };
393
407
  const adopt = (content: HTMLElement) => (node: HTMLElement) => { node.append(content); return () => content.remove(); };
394
408
  let sync: { limits(): void; markers(): void; geo(): void; points(): void; base(): void; layers(): void; style(): void; select(): void; view(): void; attribution(): void } | undefined;
395
409
  /** The OpenLayers vector layer of the `layers` entry `id`. */
@@ -679,6 +693,7 @@
679
693
  };
680
694
 
681
695
  let clicked: { id: string; at: number[] } | undefined; // where a click landed, to anchor the popup of a shape
696
+ let panKey: string | undefined; // #305: the selection whose popup was last panned into view
682
697
 
683
698
  // ---- sync functions (called from effects)
684
699
  sync = {
@@ -759,6 +774,7 @@
759
774
  const pos = clicked && clicked.id === selected ? clicked.at : g.getType() === 'Point' ? g.getCoordinates() : getCenter(g.getExtent());
760
775
  const { geometry, ...properties } = f.getProperties();
761
776
  const layer = selLayer ? layerIdOf(selLayer) : undefined;
777
+ layerNoPopup = !!selLayer && selLayer.get('trussPopup') === false;
762
778
  fsel = { id: selected!, properties, geometryType: g.getType(), lonLat: toLonLat(pos) as [number, number], ...(layer !== undefined && { layer }) };
763
779
  announce = featureTitle(properties);
764
780
  overlay.setPosition(pos);
@@ -767,6 +783,12 @@
767
783
  announce = m?.label ?? '';
768
784
  overlay.setPosition(m ? fromLonLat([m.lon, m.lat]) : undefined);
769
785
  }
786
+ // #305: a new selection pans its popup into view, once it has rendered (not when it is hidden, nor on a resync of the same selection)
787
+ const key = m || g ? `${selLayer ? layerIdOf(selLayer) : ''}|${selected}` : undefined;
788
+ if (key !== panKey) {
789
+ panKey = key;
790
+ if (key && popupAutoPan) void tick().then(() => { if (panKey === key && !popupEl.hidden) overlay.panIntoView({ animation: { duration: moveMs(250) }, margin: 24 }); });
791
+ }
770
792
  },
771
793
  view() {
772
794
  // apply only what the consumer changed since the last value we saw: the defaults never undo a fit, a pan or a zoom
@@ -814,7 +836,7 @@
814
836
  const k = String(id);
815
837
  if (!(l ? l.getSource().getFeatureById(k) : markerSrc.getFeatureById(k) ?? geoSrc.getFeatureById(k) ?? ptSrc.getFeatureById(k) ?? aggSrc.getFeatureById(k))) return false;
816
838
  x303?.selChange();
817
- clicked = undefined; selLayer = l; selected = mine = k; sync!.select();
839
+ clicked = panKey = undefined; selLayer = l; selected = mine = k; sync!.select();
818
840
  return true;
819
841
  }
820
842
  };
@@ -847,10 +869,11 @@
847
869
  selLayer = own(l) ? undefined : l;
848
870
  const id = String(raw);
849
871
  clicked = at ? { id, at } : undefined;
850
- selected = mine = id;
872
+ selected = mine = id; panKey = undefined; // a click or key always pans its popup into view, even on the selected feature
851
873
  sync!.select();
852
- if (l === markerLayer && sel) onselect?.({ type: 'marker', marker: sel });
853
- else if (fsel) onselect?.({ type: 'feature', id: raw, properties: fsel.properties, geometryType: fsel.geometryType, ...(fsel.layer !== undefined && { layer: fsel.layer }) });
874
+ // #305: `lonLat` is where the click landed; from the keyboard, the marker or the feature's popup anchor
875
+ if (l === markerLayer && sel) onselect?.({ type: 'marker', marker: sel, lonLat: at ? toLonLat(at) as [number, number] : [sel.lon, sel.lat] });
876
+ else if (fsel) onselect?.({ type: 'feature', id: raw, properties: fsel.properties, geometryType: fsel.geometryType, lonLat: fsel.lonLat, ...(fsel.layer !== undefined && { layer: fsel.layer }) });
854
877
  else clear();
855
878
  };
856
879
  /** Features shown inside the current view, in a stable order, for keyboard selection: the map's own, then the `trussInteractive` layers'. */
@@ -875,7 +898,7 @@
875
898
  };
876
899
  el.addEventListener('keydown', onkey);
877
900
  map.on('singleclick', (e) => {
878
- if (click303()) return;
901
+ if (click303(e.originalEvent)) return;
879
902
  const hit = map.forEachFeatureAtPixel(e.pixel, (f, l) => ({ f, l }), { hitTolerance: 6, layerFilter: hittable });
880
903
  const cl = hit?.f.get('_cluster');
881
904
  if (cl) {
@@ -1047,10 +1070,14 @@
1047
1070
  return false;
1048
1071
  }
1049
1072
  /** Whether OpenLayers' click is not a selection: the lift of a long-press, or a click that adds a vertex. */
1050
- function click303(): boolean {
1073
+ function click303(ev: Event): boolean {
1051
1074
  if (pressed) { pressed = false; return true; }
1052
- return editor.drawing;
1075
+ return editor.drawing || queuedClicks.has(ev);
1053
1076
  }
1077
+ // #306: a click while the first draw mode loads is a vertex, added once it is live (OpenLayers' `click` comes at once,
1078
+ // `singleclick` 250ms later, by when the mode may be live: the event tells the buffered click from a selection)
1079
+ const queuedClicks = new WeakSet<Event>();
1080
+ map.on('click', (e) => { if (editor.pending) { editor.queue(e.coordinate); queuedClicks.add(e.originalEvent); } });
1054
1081
  /** The theme changed: the location layer and the sketch redraw with the new tokens. */
1055
1082
  function restyle303() { locLayer?.changed(); editor.restyle(); }
1056
1083
 
@@ -1060,7 +1087,9 @@
1060
1087
  selChange: () => { hush = false; closeApp(); },
1061
1088
  finish: editor.finish, abort: editor.abort, undo: editor.undo,
1062
1089
  edit: () => {
1063
- void editor.set(drawMode, editLayer, snap);
1090
+ editor.set(drawMode, editLayer, snap);
1091
+ // #306: an editLayer alone loads the interactions, so even the first drawMode switch is synchronous
1092
+ if (editLayer !== undefined) editor.preload();
1064
1093
  // announced once the effects of this change have run (a selection sync resets the live region)
1065
1094
  const m = drawMode;
1066
1095
  if (m !== lastMode && m) void tick().then(() => { if (drawMode === m) announce = L.drawing(m); });
@@ -1140,7 +1169,7 @@
1140
1169
  $effect(() => { basemap; activeBasemap; if (ready) sync?.base(); });
1141
1170
  // #302: each layer's own fields are read here, so a change to one (even inside a `$state` list) resyncs; the sync itself is untracked
1142
1171
  $effect(() => {
1143
- for (const l of layers ?? []) { l.id; l.geojson; l.source; l.loader; l.onload; l.style; l.simplestyle; l.visible; l.zIndex; l.interactive; l.label; l.opacity; l.declutter; }
1172
+ for (const l of layers ?? []) { l.id; l.geojson; l.source; l.loader; l.onload; l.style; l.simplestyle; l.visible; l.zIndex; l.interactive; l.popup; l.label; l.opacity; l.declutter; }
1144
1173
  if (ready) untrack(() => { sync?.layers(); refit(); });
1145
1174
  });
1146
1175
  // a `selected` the consumer set (not one a click, the keyboard or `select()` set) names one of the map's own features
@@ -1161,7 +1190,7 @@
1161
1190
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
1162
1191
  <div class="map" bind:this={el} tabindex="0" role="application" aria-label={L.map}></div>
1163
1192
 
1164
- <div class="popup" bind:this={popupEl} hidden={!!app || hush || (!sel && !fsel)}>
1193
+ <div class="popup" bind:this={popupEl} hidden={!!app || hush || (!sel && !fsel) || noPopup}>
1165
1194
  {#if sel}
1166
1195
  <div class="card" role="dialog" aria-label={sel.label ?? L.location}>
1167
1196
  <button type="button" class="x" aria-label={L.close} onclick={() => { selected = undefined; onselect?.(null); }}>×</button>
@@ -1186,7 +1215,7 @@
1186
1215
  <!-- #303: the popup openPopup() opens, in the selection popup's card -->
1187
1216
  <div class="popup" bind:this={appEl} hidden={!app}>
1188
1217
  {#if app}
1189
- <div class="card app" class:nox={app.closeButton === false} role="dialog" aria-label={app.label ?? L.details} tabindex="-1">
1218
+ <div class="card app" class:nox={app.closeButton === false} role="dialog" aria-label={app.label ?? L.details} tabindex="-1" {@attach cssvars(() => popupWidth(app?.maxWidth))}>
1190
1219
  {#if app.closeButton !== false}<button type="button" class="x" aria-label={L.close} onclick={() => x303?.close()}>×</button>{/if}
1191
1220
  <div class="body">
1192
1221
  {#if typeof app.content === 'function'}{@render app.content()}{:else}<div class="adopt" {@attach adopt(app.content)}></div>{/if}
@@ -1251,7 +1280,7 @@
1251
1280
  /* the buttons sit at least 24px apart centre to centre (WCAG 2.5.8 spacing): 2px apart, 4px once compact makes them 20px (#292) */
1252
1281
  .controls { position: absolute; z-index: 3; left: 8px; top: 8px; display: flex; flex-direction: column; gap: max(2px, calc(24px - var(--tr-control-h-sm))); padding: 2px; background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); box-shadow: var(--tr-elevation-2); }
1253
1282
  .popup[hidden] { display: none; }
1254
- .card { position: relative; min-width: 160px; max-width: 260px; padding: 10px 28px 10px 12px; background: var(--tr-surface-container-low); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); box-shadow: var(--tr-elevation-3); color: var(--tr-on-surface); font: var(--tr-text-md) var(--tr-font-sans); cursor: default; }
1283
+ .card { position: relative; min-width: 160px; max-width: var(--trm-popup-max-width, 260px); padding: 10px 28px 10px 12px; background: var(--tr-surface-container-low); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); box-shadow: var(--tr-elevation-3); color: var(--tr-on-surface); font: var(--tr-text-md) var(--tr-font-sans); cursor: default; }
1255
1284
  .card::after { content: ''; position: absolute; left: 50%; bottom: -6px; width: 10px; height: 10px; transform: translateX(-50%) rotate(45deg); background: var(--tr-surface-container-low); border-right: 1px solid var(--tr-outline-variant); border-bottom: 1px solid var(--tr-outline-variant); }
1256
1285
  .t { font-weight: 700; }
1257
1286
  .d { color: var(--tr-on-surface-variant); font-size: var(--tr-text-sm); margin-top: 2px; }
@@ -1297,6 +1326,7 @@
1297
1326
  */
1298
1327
  :global(.trm .ol-attribution.ol-control) { right: 8px; bottom: 8px; max-width: 70%; background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-pill); font: var(--tr-text-xs) var(--tr-font-sans); color: var(--tr-on-surface-variant); }
1299
1328
  :global(.trm .ol-attribution.ol-control ul) { margin: 0; padding: 2px 10px; color: var(--tr-on-surface-variant); text-shadow: none; }
1329
+ :global(.trm .ol-attribution.ol-control li:not(:last-child)::after) { content: ' | '; white-space: pre; }
1300
1330
  :global(.trm .ol-attribution.ol-control a) { color: var(--tr-primary-text, var(--tr-primary)); }
1301
1331
  :global(.trm .ol-attribution.ol-control button) { background: none; color: var(--tr-on-surface-variant); }
1302
1332
  :global(.trm .ol-attribution.ol-control button:hover) { background: var(--tr-surface-container-high); color: var(--tr-on-surface); outline: none; }
@@ -162,8 +162,15 @@ type $$ComponentProps = {
162
162
  maxZoom?: number;
163
163
  /** Custom popup body for the selected marker. */
164
164
  popup?: Snippet<[marker: MapMarker]>;
165
- /** Custom popup body for a selected GeoJSON feature or point; without it the popup lists the feature's properties. */
166
- featurePopup?: Snippet<[feature: MapFeatureInfo]>;
165
+ /**
166
+ * Custom popup body for a selected GeoJSON feature, point or layer feature; without it the popup lists the feature's properties.
167
+ * `false` shows no popup for features (selection, its halo, `onselect` and the keyboard still work): open your own with
168
+ * `onselect={(s) => s && api.openPopup(s.lonLat, { content })}`. One layer can opt out alone with `popup: false` on its `layers` entry
169
+ * (or the `trussPopup: false` property on a `trussInteractive` layer of your own).
170
+ */
171
+ featurePopup?: Snippet<[feature: MapFeatureInfo]> | false;
172
+ /** Pan the map so the whole selection popup shows when a marker or feature is selected, as `openPopup`'s `autoPan` does. Default true. */
173
+ popupAutoPan?: boolean;
167
174
  /** Extra controls appended to the toolbar. */
168
175
  toolbar?: Snippet;
169
176
  /**
@@ -2,8 +2,11 @@
2
2
  /** An XYZ tile layer: `url` with `{z}`, `{x}`, `{y}` (or `{-y}`) placeholders. */
3
3
  export type BasemapTiles = {
4
4
  url: string;
5
- /** Credits shown in the attribution control (HTML is allowed, as OpenLayers renders it). */
6
- attribution?: string;
5
+ /**
6
+ * Credits shown in the attribution control (HTML is allowed, as OpenLayers renders it). A list gives one item per entry; identical
7
+ * entries across the layers of a stack (a shared "Powered by Esri") are shown once.
8
+ */
9
+ attribution?: string | string[];
7
10
  /** The deepest zoom the source serves; the map upsamples beyond it. Default 19. */
8
11
  maxZoom?: number;
9
12
  /** The shallowest zoom the source serves. Default 0. */
@@ -19,7 +22,7 @@ export type BasemapTiles = {
19
22
  /** OpenStreetMap's own tiles with your `attribution` and/or `maxZoom`. Themed (inverted in dark mode) unless `themed: false`. */
20
23
  export type BasemapOsm = {
21
24
  osm: true;
22
- attribution?: string;
25
+ attribution?: string | string[];
23
26
  maxZoom?: number;
24
27
  opacity?: number;
25
28
  themed?: boolean;
@@ -52,7 +55,7 @@ export type BasemapOption = {
52
55
  export type TileSpec = {
53
56
  osm: boolean;
54
57
  url?: string;
55
- attribution?: string;
58
+ attribution?: string | string[];
56
59
  maxZoom: number;
57
60
  minZoom?: number;
58
61
  opacity?: number;
@@ -79,7 +82,7 @@ export declare const esriBasemaps: {
79
82
  id: string;
80
83
  layers: {
81
84
  url: string;
82
- attribution: string;
85
+ attribution: string[];
83
86
  maxZoom: number;
84
87
  }[];
85
88
  };
@@ -87,7 +90,7 @@ export declare const esriBasemaps: {
87
90
  id: string;
88
91
  layers: {
89
92
  url: string;
90
- attribution: string;
93
+ attribution: string[];
91
94
  maxZoom: number;
92
95
  }[];
93
96
  };
@@ -95,7 +98,7 @@ export declare const esriBasemaps: {
95
98
  id: string;
96
99
  layers: {
97
100
  url: string;
98
- attribution: string;
101
+ attribution: string[];
99
102
  maxZoom: number;
100
103
  }[];
101
104
  };
package/dist/basemaps.js CHANGED
@@ -25,13 +25,14 @@ export function pickBasemap(list, id) {
25
25
  const ARC = 'https://server.arcgisonline.com/ArcGIS/rest/services';
26
26
  const tiles = (service) => `${ARC}/${service}/MapServer/tile/{z}/{y}/{x}`;
27
27
  const POWERED = 'Powered by <a href="https://www.esri.com" target="_blank" rel="noopener">Esri</a>';
28
- // The credits are each service's own `copyrightText` (its REST endpoint, `?f=json`), as Esri asks them to be shown.
29
- const IMAGERY = `${POWERED} | Source: Esri, Vantor, Earthstar Geographics, and the GIS User Community`;
30
- const STREETS = `${POWERED} | Sources: Esri, HERE, Garmin, USGS, Intermap, INCREMENT P, NRCan, Esri Japan, METI, Esri China (Hong Kong), Esri Korea, Esri (Thailand), NGCC, © OpenStreetMap contributors, and the GIS User Community`;
31
- const TOPO = `${POWERED} | Sources: Esri, HERE, Garmin, Intermap, increment P Corp., GEBCO, USGS, FAO, NPS, NRCAN, GeoBase, IGN, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), © OpenStreetMap contributors, and the GIS User Community`;
32
- const PLACES = `${POWERED} | Esri, HERE, Garmin, © OpenStreetMap contributors, and the GIS user community`;
28
+ // The credits are each service's own `copyrightText` (its REST endpoint, `?f=json`), as Esri asks them to be shown. "Powered by Esri" is its
29
+ // own item, identical across the presets, so a stack (the hybrid) shows it once and each layer's credit as its own item.
30
+ const IMAGERY_CREDIT = `Source: Esri, Vantor, Earthstar Geographics, and the GIS User Community`;
31
+ const STREETS_CREDIT = `Sources: Esri, HERE, Garmin, USGS, Intermap, INCREMENT P, NRCan, Esri Japan, METI, Esri China (Hong Kong), Esri Korea, Esri (Thailand), NGCC, © OpenStreetMap contributors, and the GIS User Community`;
32
+ const TOPO_CREDIT = `Sources: Esri, HERE, Garmin, Intermap, increment P Corp., GEBCO, USGS, FAO, NPS, NRCAN, GeoBase, IGN, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), © OpenStreetMap contributors, and the GIS User Community`;
33
+ const PLACES_CREDIT = 'Esri, HERE, Garmin, © OpenStreetMap contributors, and the GIS user community';
33
34
  /** Esri's place-name and boundary overlay (Reference/World_Boundaries_and_Places), to stack over imagery. */
34
- export const esriLabels = { url: tiles('Reference/World_Boundaries_and_Places'), attribution: PLACES, maxZoom: 19 };
35
+ export const esriLabels = { url: tiles('Reference/World_Boundaries_and_Places'), attribution: [POWERED, PLACES_CREDIT], maxZoom: 19 };
35
36
  /**
36
37
  * Esri ArcGIS Online basemaps as `basemaps` entries (each also works as `basemap`): World_Imagery, World_Street_Map, World_Topo_Map, and
37
38
  * World_Imagery with the World_Boundaries_and_Places labels on top. Each carries the attribution Esri's service publishes. None is themed,
@@ -43,8 +44,8 @@ export const esriLabels = { url: tiles('Reference/World_Boundaries_and_Places'),
43
44
  * services. See https://goto.arcgisonline.com/maps/World_Imagery and the other services' pages.
44
45
  */
45
46
  export const esriBasemaps = {
46
- imagery: { id: 'esri-imagery', layers: [{ url: tiles('World_Imagery'), attribution: IMAGERY, maxZoom: 19 }] },
47
- streets: { id: 'esri-streets', layers: [{ url: tiles('World_Street_Map'), attribution: STREETS, maxZoom: 19 }] },
48
- topo: { id: 'esri-topo', layers: [{ url: tiles('World_Topo_Map'), attribution: TOPO, maxZoom: 19 }] },
49
- hybrid: { id: 'esri-hybrid', layers: [{ url: tiles('World_Imagery'), attribution: IMAGERY, maxZoom: 19 }, esriLabels] }
47
+ imagery: { id: 'esri-imagery', layers: [{ url: tiles('World_Imagery'), attribution: [POWERED, IMAGERY_CREDIT], maxZoom: 19 }] },
48
+ streets: { id: 'esri-streets', layers: [{ url: tiles('World_Street_Map'), attribution: [POWERED, STREETS_CREDIT], maxZoom: 19 }] },
49
+ topo: { id: 'esri-topo', layers: [{ url: tiles('World_Topo_Map'), attribution: [POWERED, TOPO_CREDIT], maxZoom: 19 }] },
50
+ hybrid: { id: 'esri-hybrid', layers: [{ url: tiles('World_Imagery'), attribution: [POWERED, IMAGERY_CREDIT], maxZoom: 19 }, esriLabels] }
50
51
  };
package/dist/edit.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type OLMap from 'ol/Map.js';
2
2
  import type { GeoJSONFeature, MapDrawEnd, MapDrawMode, MapEditEnd } from './types.js';
3
3
  /**
4
- * @internal Drawing and editing for the Map (#303): OpenLayers' Draw, Modify, Translate and Snap, loaded on first use.
4
+ * @internal Drawing and editing for the Map (#303): OpenLayers' Draw, Modify, Translate and Snap, loaded once on first use (#306: then
5
+ * every mode switch is synchronous; clicks and keys that arrive while the first draw mode loads are buffered and replayed).
5
6
  * The target is a vector layer found by its `id` property (`editLayer`, an app layer or, later, a `layers` entry of #302), or the
6
7
  * Map's own GeoJSON layer. Kept out of Map.svelte so the component only wires props to it.
7
8
  */
@@ -24,11 +25,25 @@ export type EditDeps = {
24
25
  export declare const isDrawMode: (m: MapDrawMode | null | undefined) => m is "Point" | "LineString" | "Polygon";
25
26
  /** Real vertices of a sketch (the last coordinate follows the pointer; a polygon's ring is closed back to its first vertex as well). */
26
27
  export declare function sketchVertices(type: string, coords: any): number;
28
+ type Interactions = {
29
+ Draw: any;
30
+ Modify: any;
31
+ Translate: any;
32
+ Snap: any;
33
+ };
34
+ /** #306: OpenLayers' interaction classes, imported once per page (every map shares them). */
35
+ export declare function loadInteractions(): Promise<Interactions>;
27
36
  export declare function createEditor(d: EditDeps): {
28
- set: (m: MapDrawMode | null, layer: string | undefined, snap: boolean) => Promise<void>;
37
+ set: (m: MapDrawMode | null, layer: string | undefined, snap: boolean) => void;
29
38
  finish: () => void;
30
39
  abort: () => void;
31
40
  undo: () => void;
41
+ /** Load the interactions now (when `editLayer` is set before any `drawMode`), so the first switch is synchronous too. */
42
+ preload(): void;
43
+ /** A draw mode is still loading: clicks are to be `queue`d, not taken as a selection. */
44
+ readonly pending: boolean;
45
+ /** Add a vertex at `at` (map coordinates) as soon as the pending draw mode is live. */
46
+ queue(at: number[]): void;
32
47
  /** Whether a draw mode (point, line, polygon) is active. */
33
48
  readonly drawing: boolean;
34
49
  /**
@@ -40,3 +55,4 @@ export declare function createEditor(d: EditDeps): {
40
55
  restyle(): void;
41
56
  dispose(): void;
42
57
  };
58
+ export {};
package/dist/edit.js CHANGED
@@ -3,6 +3,14 @@ export const isDrawMode = (m) => m === 'Point' || m === 'LineString' || m === 'P
3
3
  export function sketchVertices(type, coords) {
4
4
  return type === 'Polygon' ? Math.max(0, coords[0].length - 2) : coords.length - 1;
5
5
  }
6
+ let loaded;
7
+ let loading;
8
+ /** #306: OpenLayers' interaction classes, imported once per page (every map shares them). */
9
+ export function loadInteractions() {
10
+ return (loading ??= Promise.all([
11
+ import('ol/interaction/Draw.js'), import('ol/interaction/Modify.js'), import('ol/interaction/Translate.js'), import('ol/interaction/Snap.js')
12
+ ]).then(([a, b, c, e]) => (loaded = { Draw: a.default, Modify: b.default, Translate: c.default, Snap: e.default })));
13
+ }
6
14
  export function createEditor(d) {
7
15
  let mode = null;
8
16
  let ints = [];
@@ -10,6 +18,9 @@ export function createEditor(d) {
10
18
  let sketch;
11
19
  let token = 0;
12
20
  let unwait;
21
+ /** #306: a draw mode is waiting for the interactions to load; vertices given meanwhile (map coordinates) are added once they are live. */
22
+ let pending = false;
23
+ let queued = [];
13
24
  const teardown = () => {
14
25
  for (const i of ints)
15
26
  d.map.removeInteraction(i);
@@ -18,9 +29,14 @@ export function createEditor(d) {
18
29
  sketch = undefined;
19
30
  unwait?.();
20
31
  unwait = undefined;
32
+ pending = false;
33
+ queued = [];
21
34
  };
22
- /** Switch to `m` on the layer `layer` (`undefined`: the Map's own GeoJSON); `null` stops. A layer that is not on the map yet is waited for. */
23
- async function set(m, layer, snap) {
35
+ /**
36
+ * Switch to `m` on the layer `layer` (`undefined`: the Map's own GeoJSON); `null` stops. A layer that is not on the map yet is waited for.
37
+ * Synchronous once the interactions are loaded; the first switch loads them (and buffers input meanwhile, see `queue`).
38
+ */
39
+ function set(m, layer, snap) {
24
40
  const t = ++token;
25
41
  teardown();
26
42
  mode = m;
@@ -31,16 +47,31 @@ export function createEditor(d) {
31
47
  // a layer the app adds a moment later (created, then added in its own effect): start once it is there
32
48
  const coll = d.map.getLayers();
33
49
  const on = () => { if (d.find(layer))
34
- void set(m, layer, snap); };
50
+ set(m, layer, snap); };
35
51
  coll.on('add', on);
36
52
  unwait = () => coll.un('add', on);
37
53
  return;
38
54
  }
39
- const [{ default: Draw }, { default: Modify }, { default: Translate }, { default: Snap }] = await Promise.all([
40
- import('ol/interaction/Draw.js'), import('ol/interaction/Modify.js'), import('ol/interaction/Translate.js'), import('ol/interaction/Snap.js')
41
- ]);
42
- if (t !== token)
55
+ if (loaded) {
56
+ build(loaded, m, layer, l, snap);
43
57
  return;
58
+ }
59
+ pending = isDrawMode(m);
60
+ void loadInteractions().then((mods) => {
61
+ if (t !== token)
62
+ return;
63
+ const q = queued;
64
+ pending = false;
65
+ queued = [];
66
+ build(mods, m, layer, l, snap);
67
+ for (const at of q)
68
+ if (at === 'finish')
69
+ finish();
70
+ else
71
+ add(at);
72
+ });
73
+ }
74
+ function build({ Draw, Modify, Translate, Snap }, m, layer, l, snap) {
44
75
  const source = l.getSource();
45
76
  const tag = layer === undefined ? {} : { layer };
46
77
  const report = (fs) => fs.map((f) => ({ ...(f.getId() !== undefined && { id: f.getId() }), feature: d.toGeoJSON(f), olFeature: f }));
@@ -86,6 +117,12 @@ export function createEditor(d) {
86
117
  return {
87
118
  set,
88
119
  finish, abort, undo,
120
+ /** Load the interactions now (when `editLayer` is set before any `drawMode`), so the first switch is synchronous too. */
121
+ preload() { void loadInteractions(); },
122
+ /** A draw mode is still loading: clicks are to be `queue`d, not taken as a selection. */
123
+ get pending() { return pending; },
124
+ /** Add a vertex at `at` (map coordinates) as soon as the pending draw mode is live. */
125
+ queue(at) { queued.push(at); },
89
126
  /** Whether a draw mode (point, line, polygon) is active. */
90
127
  get drawing() { return !!draw; },
91
128
  /**
@@ -93,6 +130,21 @@ export function createEditor(d) {
93
130
  * Backspace removes the last vertex, Escape drops the sketch. Returns whether the key was used.
94
131
  */
95
132
  key(e, center) {
133
+ if (pending) {
134
+ // the keys of a draw mode that is still loading: kept in order and replayed once it is live
135
+ if (e.key === ' ' || (e.key === 'Enter' && mode === 'Point'))
136
+ queued.push(center);
137
+ else if (e.key === 'Enter')
138
+ queued.push('finish');
139
+ else if (e.key === 'Backspace')
140
+ queued.pop();
141
+ else if (e.key === 'Escape')
142
+ queued = [];
143
+ else
144
+ return false;
145
+ e.preventDefault();
146
+ return true;
147
+ }
96
148
  if (!draw)
97
149
  return false;
98
150
  if (e.key === ' ' || (e.key === 'Enter' && mode === 'Point'))
package/dist/layers-ol.js CHANGED
@@ -134,6 +134,7 @@ export class LayerManager {
134
134
  l.setZIndex(spec.zIndex ?? 30 + i);
135
135
  l.setOpacity(spec.opacity ?? 1);
136
136
  l.set('trussInteractive', spec.interactive !== false);
137
+ l.set('trussPopup', spec.popup !== false);
137
138
  l.set('label', spec.label);
138
139
  }
139
140
  #drop(e) {
package/dist/types.d.ts CHANGED
@@ -73,6 +73,8 @@ export type MapLayer = {
73
73
  zIndex?: number;
74
74
  /** Take part in click, hover, keyboard selection and the default fit. Default true. */
75
75
  interactive?: boolean;
76
+ /** Show the Map's selection popup for this layer's features. `false` keeps the selection, its halo and `onselect`: open your own popup there (#305). Default true. */
77
+ popup?: boolean;
76
78
  /** A human-readable name, kept as the OpenLayers layer's `label` property (for a layer list you build). */
77
79
  label?: string;
78
80
  /** 0 to 1. Default 1. */
@@ -89,8 +91,15 @@ export type MapViewChange = {
89
91
  export type MapSelection = {
90
92
  type: 'marker';
91
93
  marker: MapMarker;
94
+ /** `[lon, lat]` where the click landed; from the keyboard, the marker's own position (#305). */
95
+ lonLat: [number, number];
92
96
  } | {
93
97
  type: 'feature';
98
+ /**
99
+ * `[lon, lat]` where the click or tap landed; from the keyboard, the feature's popup anchor (a point's own position, the centre of a
100
+ * line's or polygon's extent). Open your own popup there: `api.openPopup(s.lonLat, { content })` with `featurePopup={false}` (#305).
101
+ */
102
+ lonLat: [number, number];
94
103
  id?: string | number;
95
104
  properties: Record<string, unknown>;
96
105
  /** `Point`, `LineString`, `Polygon`, `MultiPolygon`, ... */
@@ -197,6 +206,11 @@ export type MapPopupOptions = {
197
206
  content: Snippet | HTMLElement;
198
207
  /** Pan the map so the whole popup shows. Default true. */
199
208
  autoPan?: boolean;
209
+ /**
210
+ * The card's widest size: px, or any CSS length (`'min(360px, 80vw)'`). Default: the `--trm-popup-max-width` custom property
211
+ * (set it on the Map or an ancestor for every popup, the selection popup included), else 260px (#306).
212
+ */
213
+ maxWidth?: number | string;
200
214
  /** Show the × button. Default true; Escape closes the popup either way. */
201
215
  closeButton?: boolean;
202
216
  /** The popup's accessible name (it is a `role="dialog"`). Default: the `details` label. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.58.0",
3
+ "version": "1.59.1",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "svelte": "^5.20.0",
32
- "@ruckc/truss-ui": "^1.58.0",
32
+ "@ruckc/truss-ui": "^1.59.1",
33
33
  "ol": "^10.0.0"
34
34
  },
35
35
  "devDependencies": {