@superrouteca/smap-react 1.2.15 → 1.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0 — 2026-10-30
4
+
5
+ - The map gaps G15–G37 of the Web SDK, the React way. The ref (and `useSMap()`) is the SDK map, so `fitBounds`, the
6
+ camera getters and moves (`getCenter`, `getZoom`, `getBounds`, `jumpTo`, `easeTo`, `zoomIn`, `zoomOut`), `project` /
7
+ `unproject`, `resize`, `featuresAt`, feature states, `openFeaturePopup`, `openTooltip`, `closeTooltip`,
8
+ `moveFeature`, `updateFeature`, images, `export` / `toDataURL` and `addThreeLayer` come with it.
9
+ - `<SMap>`: `cooperativeGestures`, `unavailableNotice` and `onUnavailable` (called when sMap refuses the site, no node
10
+ answers or the browser cannot draw the map, also before the map is ready). A map that cannot be shown is removed
11
+ with its notice when the map is made again.
12
+ - Layers: `onHover`, `onDblClick` and `onContextMenu` on `<Points>`, `<Lines>`, `<Polygons>` and `<Circles>`;
13
+ `onClusterClick(cluster, feature, event)` on `<Points>`; `featureStates` for the `states` looks (custom markers
14
+ too), sending only what changed. The new layer options (per-feature styles, `states`, `hoverState`, `rotation`,
15
+ arrows by share, `allowOverlap` / `priority` / `labelSize`, `outlineDash`, `sortProperty`, heat map `blur` and
16
+ `minOpacity`, model `color`) pass through.
17
+ - Every function in a layer's options (per-feature styles, `cluster.onClick`, `tooltip`, `marker.icon`, …) and in
18
+ `<CustomMarkers>`, `<Heatmap>`, `<Models>` and `<DrawTool>` now calls the newest one given; before, an inline
19
+ function kept the first one on the map.
20
+ - New `<Circles>` (circles in metres), `<MapImage>` and `useMapImage` (images of your own), `<SearchTool>` (the search
21
+ box with your own results) and `<ThreeLayer>` (three.js objects in the 3D view).
22
+ - `<DrawTool>`: `onDrawing` (length, area and validity while a shape is drawn) and the options `measure`, `style`,
23
+ `allowSelfIntersection` and `snapLayers`.
24
+ - The new SDK types are exported (`FitInput`, `MapEvent`, `LayerEvent`, `FeatureAt`, `ClusterInfo`, `DrawingEvent`,
25
+ `ImageInput`, `ExportOptions`, `SearchResult`, `ThreeLayerOptions`, `UnavailableEvent`, …).
26
+
27
+ ## 1.2.16 — 2026-10-30
28
+
29
+ - Comes with Web SDK 1.2.16: a layer with many numbered pins shows much sooner and zooming over many markers no longer drops frames.
30
+
31
+ - Licence: from this version the package is licensed under the Superroute SDK License — see `LICENSE` and [open.superroute.ca/developer/license](https://open.superroute.ca/developer/license). Versions published before keep the licence they were published with.
32
+
3
33
  ## 1.2.15 — 2026-10-29
4
34
 
5
35
  - Plan editor: an insert confirmed right after its stop was dropped no longer waits for the stop's legs, so it is
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
1
+ Superroute SDK License
2
2
 
3
- Copyright (c) 2026 Goodneo Solutions
3
+ Copyright (c) 2026 Superroute Inc. All rights reserved, except as granted below.
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ 1. Permission is granted, free of charge, to any person obtaining a copy of this software and its documentation
6
+ (the "Software") to install, use, copy and distribute the Software, including as part of their own products and
7
+ services, to connect to Superroute services, on any other platform, and in their own commercial projects.
11
8
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
9
+ 2. The Software may not be sold on its own, whether alone or as the main part of a product whose value lies in the
10
+ Software rather than in the product built with it.
14
11
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
12
+ 3. The copyright notices, this license and the attribution of the Software to Superroute may not be removed or
13
+ changed, and must be kept in every copy or substantial portion of the Software that is distributed.
14
+
15
+ 4. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16
+ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
20
+
21
+ 5. Use of Superroute services through the Software is governed by the terms of those services.
package/README.md CHANGED
@@ -5,13 +5,14 @@
5
5
 
6
6
  # sMap for React: `@superrouteca/smap-react`
7
7
 
8
- React components for maps from Superroute's sMap service: `<SMap>`, `<Points>`, `<Lines>`, `<Polygons>`, the
8
+ React components for maps from Superroute's sMap service: `<SMap>`, `<Points>`, `<Lines>`, `<Polygons>`,
9
+ `<Circles>`, `<CustomMarkers>`, `<Heatmap>`, `<Models>`, `<DrawTool>`, `<SearchTool>`, `<MapImage>`, `<ThreeLayer>`, the
9
10
  standard style layers (`<Source>`, `<StyleLayer>`), external layers (`<RasterLayer>`, `<WmsLayer>`, `<WmtsLayer>`,
10
11
  `<VectorTiles>`, `<ArcGisLayer>`), data files (`<Data>`), layer descriptions (`<Layers>`), deck.gl layers
11
12
  (`<DeckLayer>`) and the `useSMap()` hook, over [`@superrouteca/smap`](../js). Each component makes one call of the
12
13
  SDK and removes what it added when it unmounts.
13
14
 
14
- - Version 1.1.0, MIT licence (see `LICENSE` at the repository root)
15
+ - Version 1.1.0, Superroute SDK License (see `LICENSE` and [open.superroute.ca/developer/license](https://open.superroute.ca/developer/license))
15
16
  - React 18 or later and `@superrouteca/smap` 1.1.0 or later (a peer dependency); TypeScript types included
16
17
  - Server rendering (Next.js App Router included): the components are client components and the map is created only
17
18
  in the browser, after mounting
@@ -65,6 +66,8 @@ export function Deliveries({ stops, route, zones }) {
65
66
  | `nodes`, `baseUrl`, `nearest` | the service (default `https://tile.srsr.ca`) |
66
67
  | `projection`, `mapOptions` | `mercator` or `globe`; further options when the map is created |
67
68
  | `onReady(map)`, `onError(error)` | |
69
+ | `cooperativeGestures` | the wheel zooms only with Ctrl / ⌘, one finger scrolls the page (small maps on phones); read when the map is created |
70
+ | `unavailableNotice`, `onUnavailable(event)` | `false` leaves out the notice shown when the map cannot be shown; `onUnavailable` hears `forbidden`, `unreachable` or `unsupported`, also before the map is ready |
68
71
 
69
72
  The ref is the SDK map once it is ready (null before): `fitLayer`, `flyTo`, `setVisible`, `layers()`, `engine` and
70
73
  everything else of `@superrouteca/smap`. `useSMap()` gives the same map to components inside `<SMap>`.
@@ -123,6 +126,59 @@ the map's toolbar) that shows or hides each of them, with *Show all* and *Hide a
123
126
  `<Models>` draws glTF models at points and `<CanvasTiles>` raster tiles you paint. The rest goes through the map
124
127
  (the ref or `useSMap()`): `setBaseImagery`, `setGoogleBase`, `setTerrain`, `syncWith`, `selectArea`, `addControl`.
125
128
 
129
+ ## Camera, states, images and more (1.5.0)
130
+
131
+ The ref (or `useSMap()`) is the SDK map, so every 1.5.0 call comes with it: `fitBounds(bounds | positions | GeoJSON,
132
+ { padding, maxZoom, pitch, bearing, duration })`, `getCenter()`, `getZoom()`, `getBounds()`, `getBearing()`,
133
+ `getPitch()`, `jumpTo`, `easeTo`, `zoomIn`, `zoomOut`, `project` / `unproject`, `resize()` (a map in a tab or a
134
+ dialog), `featuresAt(point, { layers })`, `setFeatureState` / `featureState` / `removeFeatureState`,
135
+ `openFeaturePopup`, `openTooltip`, `closeTooltip`, `moveFeature`, `updateFeature`, `addImage` / `hasImage` /
136
+ `removeImage`, `export()` / `toDataURL()` (the map as a picture) and `addThreeLayer`; `map.on('click' | 'move' | …)`
137
+ gives the map's own events in the SDK's shape.
138
+
139
+ ```jsx
140
+ <SMap ref={map} cooperativeGestures onUnavailable={(e) => setNotice(e.reason)}>
141
+ <MapImage id="truck" image="/img/truck.png" pixelRatio={2} />
142
+ <Points id="vans" data={vans} options={{ icon: 'truck', rotation: { property: 'course' } }} />
143
+ <Points id="stops" data={stops}
144
+ options={{ idProperty: 'id', hoverState: true, label: 'name', allowOverlap: false, priority: { property: 'rank' },
145
+ color: (p) => (p.late ? '#dc2626' : '#2563eb'), cluster: true,
146
+ states: { hover: { radius: 8 }, selected: { color: '#000' } } }}
147
+ featureStates={selected ? { [selected]: { selected: true } } : undefined}
148
+ onHover={(f) => setHovered(f?.properties.id ?? null)}
149
+ onDblClick={(f) => edit(f.properties.id)} onContextMenu={(f, e) => openMenu(f, e.point)}
150
+ onClusterClick={async (cluster) => list(await cluster.leaves())} />
151
+ <Lines id="route" data={route} options={{ width: { property: 'width' }, arrows: { spacing: '15%' }, label: 'name' }} />
152
+ <Circles id="zones" data={depots} options={{ radius: { property: 'metres' }, fill: '#0ea5e9', opacity: 0.2 }} />
153
+ <Heatmap id="density" data={stops} options={{ radius: 18, blur: 12, minOpacity: 0.1 }} />
154
+ <SearchTool id="search" position="top-right" search={(text) => myGeocoder(text)} onPick={(r) => setPicked(r)} />
155
+ <DrawTool measure allowSelfIntersection={false} snapLayers={['zones']} style={(p) => ({ color: p.color, dash: [2, 2] })}
156
+ onDrawing={(e) => setFigures(e)} onChange={(e) => setShapes(e.features)} />
157
+ <ThreeLayer id="cranes" onAdd={(scene) => scene.add(crane)} />
158
+ </SMap>
159
+ ```
160
+
161
+ - `<Points>`, `<Lines>`, `<Polygons>` and `<Circles>` take `onHover(feature | null, event)`, `onDblClick` (the map does
162
+ not zoom) and `onContextMenu` (the browser's menu stays closed); `<Points>` takes `onClusterClick(cluster, feature,
163
+ event)`, the cluster's points from `cluster.leaves()`. `<CustomMarkers>` takes them as its own options.
164
+ - `featureStates` (`{ [featureId]: { name: value } }`) sets feature states for the layer's `states` looks (custom
165
+ markers: a class `smap-state-<name>`); only what changed is sent, and states the component did not set (`hover` of
166
+ `hoverState`) are left alone.
167
+ - Every function in `options` — per-feature styles (`color: (properties) => …`), `cluster.onClick`, `tooltip`,
168
+ `marker.icon` — and every callback prop calls the newest one given, so an inline function does not draw the layer
169
+ again. Values (numbers, colours, `{ property }`, arrays) are compared by value: a change draws the layer again. A
170
+ function's new result shows when the layer's data or the feature changes (`updateFeature`).
171
+ - `<Circles>` (`addCircles`): circles of a radius in metres around points, with every option of `<Polygons>`.
172
+ - `<MapImage id image pixelRatio sdf />` and `useMapImage(id, image, options)` (answers whether the image is on the
173
+ map) put an image of yours on the map for `icon`, `iconProperty` and `marker.icon`; a new image under the same id
174
+ replaces the old one, unmounting removes it.
175
+ - `<SearchTool>`: the search box tool with your own results (the SDK never calls a geocoder), shown and hidden by the
176
+ tools control.
177
+ - `<ThreeLayer>`: your three.js objects in the 3D view (call `sMap.useThree(THREE, GLTFLoader)` first; `onError`
178
+ hears a layer that cannot be added). Web and WebGL only.
179
+ - `<DrawTool>` takes `onDrawing` and the options `measure`, `style`, `allowSelfIntersection` and `snapLayers`;
180
+ `onTool`'s tool has `setProperties`. `<Models>` takes `options.color` per feature.
181
+
126
182
  ## Plan editor
127
183
 
128
184
  `<PlanEditor>` edits a plan of routes on the map with the ready-made panel (see the Web SDK's *Plan editor*): drag
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ var index_exports = {};
33
33
  __export(index_exports, {
34
34
  ArcGisLayer: () => ArcGisLayer,
35
35
  CanvasTiles: () => CanvasTiles,
36
+ Circles: () => Circles,
36
37
  CustomMarkers: () => CustomMarkers,
37
38
  Data: () => Data,
38
39
  DeckLayer: () => DeckLayer,
@@ -40,14 +41,17 @@ __export(index_exports, {
40
41
  Heatmap: () => Heatmap,
41
42
  Layers: () => Layers,
42
43
  Lines: () => Lines,
44
+ MapImage: () => MapImage,
43
45
  Models: () => Models,
44
46
  PlanEditor: () => PlanEditor,
45
47
  Points: () => Points,
46
48
  Polygons: () => Polygons,
47
49
  RasterLayer: () => RasterLayer,
48
50
  SMap: () => SMap,
51
+ SearchTool: () => SearchTool,
49
52
  Source: () => Source,
50
53
  StyleLayer: () => StyleLayer,
54
+ ThreeLayer: () => ThreeLayer,
51
55
  Tool: () => Tool,
52
56
  VectorTiles: () => VectorTiles,
53
57
  WmsLayer: () => WmsLayer,
@@ -55,6 +59,7 @@ __export(index_exports, {
55
59
  formats: () => formats2,
56
60
  planTexts: () => import_smap2.planTexts,
57
61
  popupTemplate: () => import_smap2.popupTemplate,
62
+ useMapImage: () => useMapImage,
58
63
  usePlanEditor: () => usePlanEditor,
59
64
  useRasterUrl: () => useRasterUrl,
60
65
  useSMap: () => useSMap
@@ -122,7 +127,9 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
122
127
  projection: p.projection,
123
128
  popup: p.popup,
124
129
  popupLoading: p.popupLoading,
125
- tools: p.tools
130
+ tools: p.tools,
131
+ cooperativeGestures: p.cooperativeGestures,
132
+ unavailableNotice: p.unavailableNotice
126
133
  };
127
134
  for (const k of Object.keys(options)) {
128
135
  if (options[k] === void 0) {
@@ -131,6 +138,7 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
131
138
  }
132
139
  let alive = true;
133
140
  let ready = false;
141
+ let removedEarly = false;
134
142
  let created;
135
143
  try {
136
144
  created = new import_smap.Map(options);
@@ -147,10 +155,19 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
147
155
  basemap: key(void 0)
148
156
  };
149
157
  created.onToolsChange((e) => latest.current.onToolsChange?.(e));
158
+ if (typeof created.on === "function") {
159
+ created.on("smap.unavailable", (e) => {
160
+ if (alive) {
161
+ latest.current.onUnavailable?.(e);
162
+ }
163
+ });
164
+ }
150
165
  created.ready.then(() => {
151
166
  ready = true;
152
167
  if (!alive) {
153
- created.remove();
168
+ if (!removedEarly) {
169
+ created.remove();
170
+ }
154
171
  return;
155
172
  }
156
173
  const overrides = latest.current.basemap;
@@ -175,6 +192,13 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
175
192
  setMap(null);
176
193
  if (ready) {
177
194
  created.remove();
195
+ } else if (created.unavailable) {
196
+ removedEarly = true;
197
+ try {
198
+ created.remove();
199
+ } catch (e) {
200
+ }
201
+ container.querySelectorAll(":scope > .smap-unavailable").forEach((n) => n.remove());
178
202
  }
179
203
  };
180
204
  }, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);
@@ -253,8 +277,74 @@ var import_react2 = require("react");
253
277
  function optionsKey(options) {
254
278
  return JSON.stringify(options ?? {}, (_k, v) => typeof v === "function" ? "[fn]" : v);
255
279
  }
280
+ var isPlain = (v) => {
281
+ if (!v || typeof v !== "object") {
282
+ return false;
283
+ }
284
+ if (Array.isArray(v)) {
285
+ return true;
286
+ }
287
+ const proto = Object.getPrototypeOf(v);
288
+ return proto === Object.prototype || proto === null;
289
+ };
290
+ function at(root, path) {
291
+ let v = root;
292
+ for (const k of path) {
293
+ if (!v || typeof v !== "object") {
294
+ return void 0;
295
+ }
296
+ v = v[k];
297
+ }
298
+ return v;
299
+ }
300
+ function liveFunctions(value, read, path = []) {
301
+ if (typeof value === "function") {
302
+ const first = value;
303
+ return ((...args) => {
304
+ const f = at(read(), path);
305
+ return (typeof f === "function" ? f : first)(...args);
306
+ });
307
+ }
308
+ if (!isPlain(value)) {
309
+ return value;
310
+ }
311
+ if (Array.isArray(value)) {
312
+ return value.map((v, i) => liveFunctions(v, read, [...path, i]));
313
+ }
314
+ const out = {};
315
+ for (const k of Object.keys(value)) {
316
+ out[k] = liveFunctions(value[k], read, [...path, k]);
317
+ }
318
+ return out;
319
+ }
320
+ var POINTER = ["onHover", "onDblClick", "onContextMenu"];
321
+ function handlersKey(p) {
322
+ return ["onTap", "popup", ...POINTER, "onClusterClick"].map((k) => p[k] ? "1" : "0").join("");
323
+ }
256
324
  function layerOptions(latest, hasTap, hasPopup) {
257
- const o = { ...latest.current.options || {} };
325
+ const o = liveFunctions({ ...latest.current.options || {} }, () => latest.current.options);
326
+ for (const name of POINTER) {
327
+ if (!latest.current[name]) {
328
+ continue;
329
+ }
330
+ o[name] = (feature, event) => {
331
+ const p = latest.current;
332
+ const own = p.options?.[name];
333
+ if (typeof own === "function") {
334
+ own(feature, event);
335
+ }
336
+ p[name]?.(feature, event);
337
+ };
338
+ }
339
+ if (latest.current.onClusterClick && o.cluster) {
340
+ const cluster = o.cluster === true ? {} : { ...o.cluster };
341
+ const own = cluster.onClick;
342
+ cluster.onClick = (feature, event, info) => {
343
+ own?.(feature, event, info);
344
+ latest.current.onClusterClick?.(info, feature, event);
345
+ };
346
+ o.cluster = cluster;
347
+ }
258
348
  if (hasTap) {
259
349
  o.onClick = (feature, event) => {
260
350
  const p = latest.current;
@@ -278,6 +368,45 @@ function layerOptions(latest, hasTap, hasPopup) {
278
368
  }
279
369
  return o;
280
370
  }
371
+ var stateKey = (v) => JSON.stringify(v === void 0 ? null : v);
372
+ function useFeatureStates(map, id, states, drawn) {
373
+ const applied = (0, import_react2.useRef)({ map: null, id: "", drawn: "", states: {} });
374
+ const latest = (0, import_react2.useRef)(states);
375
+ latest.current = states;
376
+ const statesKey = stateKey(states ?? {});
377
+ (0, import_react2.useEffect)(() => {
378
+ if (!map || removedMaps.has(map)) {
379
+ return;
380
+ }
381
+ const a = applied.current;
382
+ if (a.map !== map || a.id !== id || a.drawn !== drawn) {
383
+ applied.current = { map, id, drawn, states: {} };
384
+ }
385
+ const next = latest.current || {};
386
+ const prev = applied.current.states;
387
+ for (const fid of Object.keys(prev)) {
388
+ for (const name of Object.keys(prev[fid])) {
389
+ if (!next[fid] || !(name in next[fid])) {
390
+ map.removeFeatureState(id, fid, name);
391
+ }
392
+ }
393
+ }
394
+ for (const fid of Object.keys(next)) {
395
+ const changed = {};
396
+ let any = false;
397
+ for (const [name, v] of Object.entries(next[fid] || {})) {
398
+ if (!prev[fid] || !(name in prev[fid]) || stateKey(prev[fid][name]) !== stateKey(v)) {
399
+ changed[name] = v;
400
+ any = true;
401
+ }
402
+ }
403
+ if (any) {
404
+ map.setFeatureState(id, fid, changed);
405
+ }
406
+ }
407
+ applied.current.states = JSON.parse(statesKey);
408
+ }, [map, id, statesKey, drawn]);
409
+ }
281
410
  function useLayer(kind, props) {
282
411
  const map = useSMap();
283
412
  const { id, data, options, onTap, visible = true, popupOptions, slot } = props;
@@ -287,7 +416,7 @@ function useLayer(kind, props) {
287
416
  const shownVisible = (0, import_react2.useRef)(true);
288
417
  const hasTap = !!onTap || typeof options?.onClick === "function";
289
418
  const hasPopup = !!props.popup || typeof options?.popup === "function";
290
- const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "");
419
+ const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "") + handlersKey(props);
291
420
  (0, import_react2.useEffect)(() => {
292
421
  if (!map) {
293
422
  return void 0;
@@ -307,6 +436,7 @@ function useLayer(kind, props) {
307
436
  }
308
437
  };
309
438
  }, [map, id, looks, hasTap, hasPopup]);
439
+ useFeatureStates(map, id, props.featureStates, `${looks}|${hasTap}|${hasPopup}`);
310
440
  (0, import_react2.useEffect)(() => {
311
441
  const s = shown.current;
312
442
  if (!map || !s || s.map !== map || s.data === data) {
@@ -333,6 +463,9 @@ function Lines(props) {
333
463
  function Polygons(props) {
334
464
  return useLayer("addPolygons", props);
335
465
  }
466
+ function Circles(props) {
467
+ return useLayer("addCircles", props);
468
+ }
336
469
 
337
470
  // src/tools.tsx
338
471
  var import_react3 = require("react");
@@ -393,6 +526,30 @@ function Tool(props) {
393
526
  }
394
527
  return box ? (0, import_react_dom.createPortal)(props.children, box) : null;
395
528
  }
529
+ function SearchTool(props) {
530
+ const map = useSMap();
531
+ const latest = (0, import_react3.useRef)(props);
532
+ latest.current = props;
533
+ const { id, search: _s, onPick: _p, ...rest } = props;
534
+ const looks = optionsKey2(rest);
535
+ (0, import_react3.useEffect)(() => {
536
+ if (!map) {
537
+ return void 0;
538
+ }
539
+ const { id: _i, search: _a, onPick: _b, ...o } = latest.current;
540
+ map.addTool(id, "search", {
541
+ ...o,
542
+ search: (text) => latest.current.search(text),
543
+ onPick: (result) => latest.current.onPick?.(result)
544
+ });
545
+ return () => {
546
+ if (!removedMaps.has(map)) {
547
+ map.removeTool(id);
548
+ }
549
+ };
550
+ }, [map, id, looks]);
551
+ return null;
552
+ }
396
553
 
397
554
  // src/features.tsx
398
555
  var import_react4 = require("react");
@@ -400,7 +557,7 @@ var import_react_dom2 = require("react-dom");
400
557
  var import_jsx_runtime3 = require("react/jsx-runtime");
401
558
  function CustomMarkers(props) {
402
559
  const map = useSMap();
403
- const { id, data, render: _render, ...rest } = props;
560
+ const { id, data, render: _render, featureStates, ...rest } = props;
404
561
  const latest = (0, import_react4.useRef)(props);
405
562
  latest.current = props;
406
563
  const [entries, setEntries] = (0, import_react4.useState)(/* @__PURE__ */ new Map());
@@ -428,8 +585,9 @@ function CustomMarkers(props) {
428
585
  setEntries(new Map(held.current));
429
586
  });
430
587
  };
588
+ const { featureStates: _s, render: _r, ...given } = latest.current;
431
589
  const options = {
432
- ...latest.current,
590
+ ...liveFunctions(given, () => latest.current),
433
591
  render: (properties, feature) => {
434
592
  const el = document.createElement("div");
435
593
  held.current.set(keyOf(properties, feature), { el, properties, feature });
@@ -478,6 +636,7 @@ function CustomMarkers(props) {
478
636
  }
479
637
  }
480
638
  }, [map, id, data]);
639
+ useFeatureStates(map, id, featureStates, looks);
481
640
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: [...entries.entries()].map(([k, e]) => (0, import_react_dom2.createPortal)(latest.current.render(e.properties, e.feature), e.el, `${id}\0${k}`)) });
482
641
  }
483
642
  function useNativeLayer(add, id, looks, data) {
@@ -506,12 +665,19 @@ function useNativeLayer(add, id, looks, data) {
506
665
  map.setData(id, data);
507
666
  }, [map, id, data]);
508
667
  }
668
+ function useLatest(value) {
669
+ const ref = (0, import_react4.useRef)(value);
670
+ ref.current = value;
671
+ return ref;
672
+ }
509
673
  function Heatmap(props) {
510
- useNativeLayer((m) => m.addHeatmap(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
674
+ const latest = useLatest(props);
675
+ useNativeLayer((m) => m.addHeatmap(props.id, props.data, liveFunctions(props.options, () => latest.current.options)), props.id, optionsKey(props.options), props.data);
511
676
  return null;
512
677
  }
513
678
  function Models(props) {
514
- useNativeLayer((m) => m.addModels(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
679
+ const latest = useLatest(props);
680
+ useNativeLayer((m) => m.addModels(props.id, props.data, liveFunctions(props.options, () => latest.current.options)), props.id, optionsKey(props.options), props.data);
515
681
  return null;
516
682
  }
517
683
  function CanvasTiles(props) {
@@ -524,14 +690,18 @@ function DrawTool(props) {
524
690
  const map = useSMap();
525
691
  const latest = (0, import_react4.useRef)(props);
526
692
  latest.current = props;
527
- const { onChange: _c, onTool: _t, ...rest } = props;
528
- const looks = optionsKey(rest);
693
+ const { onChange: _c, onTool: _t, onDrawing: _d, ...rest } = props;
694
+ const looks = optionsKey(rest) + (props.onDrawing ? "|drawing" : "");
529
695
  (0, import_react4.useEffect)(() => {
530
696
  if (!map) {
531
697
  return void 0;
532
698
  }
533
- const { onChange: _a, onTool: _b, ...o } = latest.current;
534
- const tool = map.drawTool({ ...o, onChange: (e) => latest.current.onChange?.(e) });
699
+ const { onChange: _a, onTool: _b, onDrawing: _e, ...o } = latest.current;
700
+ const options = { ...liveFunctions(o, () => latest.current), onChange: (e) => latest.current.onChange?.(e) };
701
+ if (latest.current.onDrawing) {
702
+ options.onDrawing = (e) => latest.current.onDrawing?.(e);
703
+ }
704
+ const tool = map.drawTool(options);
535
705
  latest.current.onTool?.(tool);
536
706
  return () => {
537
707
  latest.current.onTool?.(null);
@@ -542,6 +712,92 @@ function DrawTool(props) {
542
712
  }, [map, looks]);
543
713
  return null;
544
714
  }
715
+ function useMapImage(id, image, options) {
716
+ const map = useSMap();
717
+ const [loaded, setLoaded] = (0, import_react4.useState)(null);
718
+ const onError = useLatest(options?.onError);
719
+ const pixelRatio = options?.pixelRatio;
720
+ const sdf = options?.sdf;
721
+ const last = (0, import_react4.useRef)(null);
722
+ const lastTarget = (0, import_react4.useRef)({ map: null, id: "" });
723
+ lastTarget.current = { map, id };
724
+ (0, import_react4.useEffect)(() => {
725
+ if (!map || image === null || image === void 0) {
726
+ return void 0;
727
+ }
728
+ let alive = true;
729
+ const mine = {};
730
+ last.current = mine;
731
+ const o = {};
732
+ if (pixelRatio !== void 0) {
733
+ o.pixelRatio = pixelRatio;
734
+ }
735
+ if (sdf !== void 0) {
736
+ o.sdf = sdf;
737
+ }
738
+ let added;
739
+ try {
740
+ added = Promise.resolve(map.addImage(id, image, o));
741
+ } catch (e) {
742
+ onError.current?.(e);
743
+ return void 0;
744
+ }
745
+ added.then(() => {
746
+ if (alive) {
747
+ setLoaded({ map, id, image });
748
+ }
749
+ }, (e) => {
750
+ if (alive) {
751
+ onError.current?.(e);
752
+ }
753
+ });
754
+ return () => {
755
+ alive = false;
756
+ setLoaded(null);
757
+ queueMicrotask(() => {
758
+ const replaced = last.current !== mine && lastTarget.current.map === map && lastTarget.current.id === id;
759
+ if (!replaced && !removedMaps.has(map)) {
760
+ map.removeImage(id);
761
+ }
762
+ });
763
+ };
764
+ }, [map, id, image, pixelRatio, sdf]);
765
+ return !!loaded && loaded.map === map && loaded.id === id && loaded.image === image;
766
+ }
767
+ function MapImage(props) {
768
+ const loaded = useMapImage(props.id, props.image, { pixelRatio: props.pixelRatio, sdf: props.sdf, onError: props.onError });
769
+ const onLoad = useLatest(props.onLoad);
770
+ (0, import_react4.useEffect)(() => {
771
+ if (loaded) {
772
+ onLoad.current?.();
773
+ }
774
+ }, [loaded]);
775
+ return null;
776
+ }
777
+ function ThreeLayer(props) {
778
+ const map = useSMap();
779
+ const latest = useLatest(props);
780
+ const { id, onAdd, render, onRemove, onError: _e, ...placement } = props;
781
+ const looks = optionsKey(placement) + (onAdd ? "a" : "") + (render ? "r" : "") + (onRemove ? "x" : "");
782
+ (0, import_react4.useEffect)(() => {
783
+ if (!map) {
784
+ return void 0;
785
+ }
786
+ const { id: _i, onError: _o, ...given } = latest.current;
787
+ try {
788
+ map.addThreeLayer(id, liveFunctions(given, () => latest.current));
789
+ } catch (e) {
790
+ latest.current.onError?.(e);
791
+ return void 0;
792
+ }
793
+ return () => {
794
+ if (!removedMaps.has(map)) {
795
+ map.removeLayer(id);
796
+ }
797
+ };
798
+ }, [map, id, looks]);
799
+ return null;
800
+ }
545
801
 
546
802
  // src/plan.tsx
547
803
  var import_react5 = require("react");
@@ -1015,6 +1271,7 @@ var import_smap2 = require("@superrouteca/smap");
1015
1271
  0 && (module.exports = {
1016
1272
  ArcGisLayer,
1017
1273
  CanvasTiles,
1274
+ Circles,
1018
1275
  CustomMarkers,
1019
1276
  Data,
1020
1277
  DeckLayer,
@@ -1022,14 +1279,17 @@ var import_smap2 = require("@superrouteca/smap");
1022
1279
  Heatmap,
1023
1280
  Layers,
1024
1281
  Lines,
1282
+ MapImage,
1025
1283
  Models,
1026
1284
  PlanEditor,
1027
1285
  Points,
1028
1286
  Polygons,
1029
1287
  RasterLayer,
1030
1288
  SMap,
1289
+ SearchTool,
1031
1290
  Source,
1032
1291
  StyleLayer,
1292
+ ThreeLayer,
1033
1293
  Tool,
1034
1294
  VectorTiles,
1035
1295
  WmsLayer,
@@ -1037,6 +1297,7 @@ var import_smap2 = require("@superrouteca/smap");
1037
1297
  formats,
1038
1298
  planTexts,
1039
1299
  popupTemplate,
1300
+ useMapImage,
1040
1301
  usePlanEditor,
1041
1302
  useRasterUrl,
1042
1303
  useSMap