@superrouteca/smap-react 1.1.7 → 1.2.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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 — 2026-10-28
4
+
5
+ - `<CustomMarkers>`: your own React content at points, rendered into each marker the map lays out (context, state
6
+ and events work as anywhere in the app); dragged with `draggable`, with tooltips and popups. The content keeps its
7
+ state while its point is out of view; the release of a drag is no click on anything inside it.
8
+ - `<Heatmap>`, `<Models>` (glTF 3D models), `<CanvasTiles>` (tiles you paint) and `<DrawTool>` (drawing and editing;
9
+ `onTool` hands over the tool).
10
+ - Every 1.2.0 call of the map works through the ref or `useSMap()`: `setBaseImagery`, `setGoogleBase`, `setTerrain`,
11
+ `syncWith`, `selectArea`, `addControl`, the layer switcher (`<Tool kind="layers">`), and on points, lines and areas
12
+ tooltips, dragging, colour-ring or HTML clusters and labels along lines.
13
+
3
14
  ## 1.1.7 — 2026-10-28
4
15
 
5
16
  - Plan editor: faster edits through sMap's fast path, with no code change. When your plan editor token answer names a
package/README.md CHANGED
@@ -105,6 +105,24 @@ the map's toolbar) that shows or hides each of them, with *Show all* and *Hide a
105
105
  yourself. The ref's `setToolVisible`, `setToolsVisible` and `tools()` switch and read them in code.
106
106
  - The map data credit and the sMap badge are never tools and always stay.
107
107
 
108
+ ## Markers, drawing and more (1.2.0)
109
+
110
+ ```jsx
111
+ <SMap center={[-79.38, 43.65]} zoom={12}>
112
+ {/* Your own React content at each point; drag it with the mouse or a finger. */}
113
+ <CustomMarkers id="vans" data={vans} idProperty="id" anchor="bottom" draggable
114
+ render={(p) => <VanBadge name={p.name} />} onDragEnd={(f, e) => save(f.properties.id, e.lngLat)} />
115
+ <Points id="stops" data={stops} options={{ cluster: { ring: 'color' }, tooltip: '{name}' }} />
116
+ <Lines id="route" data={route} options={{ label: 'name' }} />
117
+ <Heatmap id="density" data={stops} options={{ radius: 18 }} />
118
+ <DrawTool toolbar="top-left" onChange={(e) => setShapes(e.features)} />
119
+ <Tool id="layers" kind="layers" options={{ base: [{ id: 'streets', label: 'Streets' }, { id: 'satellite', label: 'Satellite', imagery }] }} />
120
+ </SMap>
121
+ ```
122
+
123
+ `<Models>` draws glTF models at points and `<CanvasTiles>` raster tiles you paint. The rest goes through the map
124
+ (the ref or `useSMap()`): `setBaseImagery`, `setGoogleBase`, `setTerrain`, `syncWith`, `selectArea`, `addControl`.
125
+
108
126
  ## Plan editor
109
127
 
110
128
  `<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
@@ -32,10 +32,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
  var index_exports = {};
33
33
  __export(index_exports, {
34
34
  ArcGisLayer: () => ArcGisLayer,
35
+ CanvasTiles: () => CanvasTiles,
36
+ CustomMarkers: () => CustomMarkers,
35
37
  Data: () => Data,
36
38
  DeckLayer: () => DeckLayer,
39
+ DrawTool: () => DrawTool,
40
+ Heatmap: () => Heatmap,
37
41
  Layers: () => Layers,
38
42
  Lines: () => Lines,
43
+ Models: () => Models,
39
44
  PlanEditor: () => PlanEditor,
40
45
  Points: () => Points,
41
46
  Polygons: () => Polygons,
@@ -389,8 +394,157 @@ function Tool(props) {
389
394
  return box ? (0, import_react_dom.createPortal)(props.children, box) : null;
390
395
  }
391
396
 
392
- // src/plan.tsx
397
+ // src/features.tsx
393
398
  var import_react4 = require("react");
399
+ var import_react_dom2 = require("react-dom");
400
+ var import_jsx_runtime3 = require("react/jsx-runtime");
401
+ function CustomMarkers(props) {
402
+ const map = useSMap();
403
+ const { id, data, render: _render, ...rest } = props;
404
+ const latest = (0, import_react4.useRef)(props);
405
+ latest.current = props;
406
+ const [entries, setEntries] = (0, import_react4.useState)(/* @__PURE__ */ new Map());
407
+ const held = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
408
+ const shown = (0, import_react4.useRef)(null);
409
+ const looks = optionsKey(rest);
410
+ const keyOf = (properties, feature) => {
411
+ const by = latest.current.idProperty;
412
+ const v = by ? properties[by] : feature.id;
413
+ return v === void 0 || v === null ? `@${JSON.stringify(feature.geometry)}` : String(v);
414
+ };
415
+ (0, import_react4.useEffect)(() => {
416
+ if (!map) {
417
+ return void 0;
418
+ }
419
+ held.current = /* @__PURE__ */ new Map();
420
+ let scheduled = false;
421
+ const publish = () => {
422
+ if (scheduled) {
423
+ return;
424
+ }
425
+ scheduled = true;
426
+ queueMicrotask(() => {
427
+ scheduled = false;
428
+ setEntries(new Map(held.current));
429
+ });
430
+ };
431
+ const options = {
432
+ ...latest.current,
433
+ render: (properties, feature) => {
434
+ const el = document.createElement("div");
435
+ held.current.set(keyOf(properties, feature), { el, properties, feature });
436
+ publish();
437
+ return el;
438
+ }
439
+ };
440
+ delete options.id;
441
+ delete options.data;
442
+ map.addCustomMarkers(id, latest.current.data, options);
443
+ shown.current = latest.current.data;
444
+ return () => {
445
+ shown.current = null;
446
+ held.current = /* @__PURE__ */ new Map();
447
+ setEntries(/* @__PURE__ */ new Map());
448
+ if (!removedMaps.has(map)) {
449
+ map.removeLayer(id);
450
+ }
451
+ };
452
+ }, [map, id, looks]);
453
+ (0, import_react4.useEffect)(() => {
454
+ if (!map || shown.current === null || shown.current === data) {
455
+ return;
456
+ }
457
+ shown.current = data;
458
+ map.setData(id, data);
459
+ const keep = /* @__PURE__ */ new Set();
460
+ const features = data && !Array.isArray(data) && data.features || [];
461
+ for (const f of features) {
462
+ keep.add(keyOf(f.properties || {}, f));
463
+ }
464
+ const by = latest.current.idProperty;
465
+ if (Array.isArray(data) && by) {
466
+ data.forEach((p) => keep.add(String(p[by])));
467
+ }
468
+ if (!Array.isArray(data) || by) {
469
+ let changed = false;
470
+ for (const k of [...held.current.keys()]) {
471
+ if (!keep.has(k)) {
472
+ held.current.delete(k);
473
+ changed = true;
474
+ }
475
+ }
476
+ if (changed) {
477
+ setEntries(new Map(held.current));
478
+ }
479
+ }
480
+ }, [map, id, data]);
481
+ 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
+ }
483
+ function useNativeLayer(add, id, looks, data) {
484
+ const map = useSMap();
485
+ const shown = (0, import_react4.useRef)(null);
486
+ const addRef = (0, import_react4.useRef)(add);
487
+ addRef.current = add;
488
+ (0, import_react4.useEffect)(() => {
489
+ if (!map) {
490
+ return void 0;
491
+ }
492
+ addRef.current(map);
493
+ shown.current = data;
494
+ return () => {
495
+ shown.current = null;
496
+ if (!removedMaps.has(map)) {
497
+ map.removeLayer(id);
498
+ }
499
+ };
500
+ }, [map, id, looks]);
501
+ (0, import_react4.useEffect)(() => {
502
+ if (!map || data === void 0 || shown.current === null || shown.current === data) {
503
+ return;
504
+ }
505
+ shown.current = data;
506
+ map.setData(id, data);
507
+ }, [map, id, data]);
508
+ }
509
+ function Heatmap(props) {
510
+ useNativeLayer((m) => m.addHeatmap(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
511
+ return null;
512
+ }
513
+ function Models(props) {
514
+ useNativeLayer((m) => m.addModels(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
515
+ return null;
516
+ }
517
+ function CanvasTiles(props) {
518
+ const draw = (0, import_react4.useRef)(props.draw);
519
+ draw.current = props.draw;
520
+ useNativeLayer((m) => m.addCanvasTiles(props.id, (...a) => draw.current(...a), props.options), props.id, optionsKey(props.options));
521
+ return null;
522
+ }
523
+ function DrawTool(props) {
524
+ const map = useSMap();
525
+ const latest = (0, import_react4.useRef)(props);
526
+ latest.current = props;
527
+ const { onChange: _c, onTool: _t, ...rest } = props;
528
+ const looks = optionsKey(rest);
529
+ (0, import_react4.useEffect)(() => {
530
+ if (!map) {
531
+ return void 0;
532
+ }
533
+ const { onChange: _a, onTool: _b, ...o } = latest.current;
534
+ const tool = map.drawTool({ ...o, onChange: (e) => latest.current.onChange?.(e) });
535
+ latest.current.onTool?.(tool);
536
+ return () => {
537
+ latest.current.onTool?.(null);
538
+ if (!removedMaps.has(map)) {
539
+ tool.destroy();
540
+ }
541
+ };
542
+ }, [map, looks]);
543
+ return null;
544
+ }
545
+
546
+ // src/plan.tsx
547
+ var import_react5 = require("react");
394
548
  function destroyOffMap(made) {
395
549
  made.layer.remove = () => {
396
550
  };
@@ -423,11 +577,11 @@ var EMPTY = {
423
577
  };
424
578
  function usePlanEditor(props) {
425
579
  const map = useSMap();
426
- const [editor, setEditor] = (0, import_react4.useState)(null);
427
- const [state, setState] = (0, import_react4.useState)(EMPTY);
428
- const latest = (0, import_react4.useRef)(props);
580
+ const [editor, setEditor] = (0, import_react5.useState)(null);
581
+ const [state, setState] = (0, import_react5.useState)(EMPTY);
582
+ const latest = (0, import_react5.useRef)(props);
429
583
  latest.current = props;
430
- const applied = (0, import_react4.useRef)(null);
584
+ const applied = (0, import_react5.useRef)(null);
431
585
  const credentialKey = "key" in props.credentials ? "key:" + props.credentials.key : "token";
432
586
  const madeKey = key2({
433
587
  baseUrl: props.baseUrl,
@@ -448,7 +602,7 @@ function usePlanEditor(props) {
448
602
  fastPathTimeout: props.fastPathTimeout,
449
603
  fastPathRefineTimeout: props.fastPathRefineTimeout
450
604
  });
451
- (0, import_react4.useEffect)(() => {
605
+ (0, import_react5.useEffect)(() => {
452
606
  if (!map) {
453
607
  return void 0;
454
608
  }
@@ -511,7 +665,7 @@ function usePlanEditor(props) {
511
665
  };
512
666
  }, [map, credentialKey, madeKey]);
513
667
  const incoming = planKey(props.plan);
514
- (0, import_react4.useEffect)(() => {
668
+ (0, import_react5.useEffect)(() => {
515
669
  if (!editor || !latest.current.plan) {
516
670
  return;
517
671
  }
@@ -523,39 +677,39 @@ function usePlanEditor(props) {
523
677
  editor.setPlan(latest.current.plan).catch(() => {
524
678
  });
525
679
  }, [editor, incoming]);
526
- (0, import_react4.useEffect)(() => {
680
+ (0, import_react5.useEffect)(() => {
527
681
  if (editor && editor.panel && props.language) {
528
682
  editor.panel.setLanguage(props.language);
529
683
  }
530
684
  }, [editor, props.language]);
531
685
  return { ...state, editor };
532
686
  }
533
- var PlanEditor = (0, import_react4.forwardRef)(function PlanEditor2(props, ref) {
687
+ var PlanEditor = (0, import_react5.forwardRef)(function PlanEditor2(props, ref) {
534
688
  const { editor } = usePlanEditor(props);
535
- (0, import_react4.useImperativeHandle)(ref, () => editor, [editor]);
689
+ (0, import_react5.useImperativeHandle)(ref, () => editor, [editor]);
536
690
  return null;
537
691
  });
538
692
 
539
693
  // src/interop.tsx
540
- var import_react5 = require("react");
694
+ var import_react6 = require("react");
541
695
  var sdk = __toESM(require("@superrouteca/smap"), 1);
542
- var import_jsx_runtime3 = require("react/jsx-runtime");
696
+ var import_jsx_runtime4 = require("react/jsx-runtime");
543
697
  function quietly(f) {
544
698
  try {
545
699
  f();
546
700
  } catch {
547
701
  }
548
702
  }
549
- var SourceContext = (0, import_react5.createContext)(null);
703
+ var SourceContext = (0, import_react6.createContext)(null);
550
704
  function Source(props) {
551
705
  const map = useSMap();
552
706
  const { id, source, children } = props;
553
- const latest = (0, import_react5.useRef)(source);
707
+ const latest = (0, import_react6.useRef)(source);
554
708
  latest.current = source;
555
- const inside = (0, import_react5.useRef)(/* @__PURE__ */ new Set());
556
- const [shown, setShown] = (0, import_react5.useState)(null);
709
+ const inside = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
710
+ const [shown, setShown] = (0, import_react6.useState)(null);
557
711
  const sourceKey = optionsKey(source);
558
- (0, import_react5.useEffect)(() => {
712
+ (0, import_react6.useEffect)(() => {
559
713
  if (!map) {
560
714
  return void 0;
561
715
  }
@@ -570,7 +724,7 @@ function Source(props) {
570
724
  quietly(() => map.removeSource(id));
571
725
  };
572
726
  }, [map, id, sourceKey]);
573
- const scope = (0, import_react5.useMemo)(() => ({
727
+ const scope = (0, import_react6.useMemo)(() => ({
574
728
  id,
575
729
  register: (layerId) => {
576
730
  inside.current.add(layerId);
@@ -580,7 +734,7 @@ function Source(props) {
580
734
  if (!map || !shown || shown.map !== map) {
581
735
  return null;
582
736
  }
583
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SourceContext.Provider, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react5.Fragment, { children }, shown.generation) });
737
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SourceContext.Provider, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react6.Fragment, { children }, shown.generation) });
584
738
  }
585
739
  function effectiveLayer(layer, sourceId, visible) {
586
740
  const out = { ...layer };
@@ -607,14 +761,14 @@ function applyDiff(prev, next, set) {
607
761
  }
608
762
  function StyleLayer(props) {
609
763
  const map = useSMap();
610
- const scope = (0, import_react5.useContext)(SourceContext);
764
+ const scope = (0, import_react6.useContext)(SourceContext);
611
765
  const { layer, before, slot, visible = true } = props;
612
766
  const current = effectiveLayer(layer, scope?.id, visible);
613
- const latest = (0, import_react5.useRef)(current);
767
+ const latest = (0, import_react6.useRef)(current);
614
768
  latest.current = current;
615
- const shown = (0, import_react5.useRef)(null);
769
+ const shown = (0, import_react6.useRef)(null);
616
770
  const structure = structureKey(current, before, slot);
617
- (0, import_react5.useEffect)(() => {
771
+ (0, import_react6.useEffect)(() => {
618
772
  if (!map) {
619
773
  return void 0;
620
774
  }
@@ -638,7 +792,7 @@ function StyleLayer(props) {
638
792
  };
639
793
  }, [map, structure, scope]);
640
794
  const looks = optionsKey(current.paint) + optionsKey(current.layout) + optionsKey(current.filter);
641
- (0, import_react5.useEffect)(() => {
795
+ (0, import_react6.useEffect)(() => {
642
796
  const s = shown.current;
643
797
  if (!map || !s || s.map !== map) {
644
798
  return;
@@ -659,12 +813,12 @@ function StyleLayer(props) {
659
813
  }
660
814
  function useAddedLayer(method, id, options, remove) {
661
815
  const map = useSMap();
662
- const latest = (0, import_react5.useRef)(options);
816
+ const latest = (0, import_react6.useRef)(options);
663
817
  latest.current = options;
664
- const removeLatest = (0, import_react5.useRef)(remove);
818
+ const removeLatest = (0, import_react6.useRef)(remove);
665
819
  removeLatest.current = remove;
666
820
  const looks = optionsKey(options);
667
- (0, import_react5.useEffect)(() => {
821
+ (0, import_react6.useEffect)(() => {
668
822
  if (!map) {
669
823
  return void 0;
670
824
  }
@@ -711,13 +865,13 @@ var dataLayerIds = (id) => [id, `${id}:lines`, `${id}:areas`];
711
865
  function Data(props) {
712
866
  const map = useSMap();
713
867
  const { id, data, format, lat, lng, options, slot, onTap, visible = true, popupOptions } = props;
714
- const latest = (0, import_react5.useRef)(props);
868
+ const latest = (0, import_react6.useRef)(props);
715
869
  latest.current = props;
716
- const shownVisible = (0, import_react5.useRef)(true);
870
+ const shownVisible = (0, import_react6.useRef)(true);
717
871
  const hasTap = !!onTap || typeof options?.onClick === "function";
718
872
  const hasPopup = !!props.popup || typeof options?.popup === "function";
719
873
  const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "") + "|" + (format ?? "") + "|" + (lat ?? "") + "|" + (lng ?? "");
720
- (0, import_react5.useEffect)(() => {
874
+ (0, import_react6.useEffect)(() => {
721
875
  if (!map) {
722
876
  return void 0;
723
877
  }
@@ -760,7 +914,7 @@ function Data(props) {
760
914
  ids.forEach((l) => quietly(() => map.removeLayer(l)));
761
915
  };
762
916
  }, [map, id, data, looks, hasTap, hasPopup]);
763
- (0, import_react5.useEffect)(() => {
917
+ (0, import_react6.useEffect)(() => {
764
918
  if (!map || shownVisible.current === visible) {
765
919
  return;
766
920
  }
@@ -772,10 +926,10 @@ function Data(props) {
772
926
  }
773
927
  function Layers(props) {
774
928
  const map = useSMap();
775
- const latest = (0, import_react5.useRef)(props.json);
929
+ const latest = (0, import_react6.useRef)(props.json);
776
930
  latest.current = props.json;
777
931
  const jsonKey = typeof props.json === "string" ? props.json : optionsKey(props.json);
778
- (0, import_react5.useEffect)(() => {
932
+ (0, import_react6.useEffect)(() => {
779
933
  if (!map) {
780
934
  return void 0;
781
935
  }
@@ -795,10 +949,10 @@ function Layers(props) {
795
949
  function DeckLayer(props) {
796
950
  const map = useSMap();
797
951
  const { layer } = props;
798
- const latest = (0, import_react5.useRef)(layer);
952
+ const latest = (0, import_react6.useRef)(layer);
799
953
  latest.current = layer;
800
- const shown = (0, import_react5.useRef)(null);
801
- (0, import_react5.useEffect)(() => {
954
+ const shown = (0, import_react6.useRef)(null);
955
+ (0, import_react6.useEffect)(() => {
802
956
  if (!map) {
803
957
  return void 0;
804
958
  }
@@ -811,7 +965,7 @@ function DeckLayer(props) {
811
965
  }
812
966
  };
813
967
  }, [map, layer.id]);
814
- (0, import_react5.useEffect)(() => {
968
+ (0, import_react6.useEffect)(() => {
815
969
  const s = shown.current;
816
970
  if (!map || !s || s.map !== map || s.layer === layer) {
817
971
  return;
@@ -825,7 +979,7 @@ function useRasterUrl(style, options) {
825
979
  const map = useSMap();
826
980
  const lang = options?.lang;
827
981
  const retina = options?.retina;
828
- return (0, import_react5.useMemo)(() => {
982
+ return (0, import_react6.useMemo)(() => {
829
983
  if (!map) {
830
984
  return null;
831
985
  }
@@ -854,10 +1008,15 @@ var import_smap2 = require("@superrouteca/smap");
854
1008
  // Annotate the CommonJS export names for ESM import in node:
855
1009
  0 && (module.exports = {
856
1010
  ArcGisLayer,
1011
+ CanvasTiles,
1012
+ CustomMarkers,
857
1013
  Data,
858
1014
  DeckLayer,
1015
+ DrawTool,
1016
+ Heatmap,
859
1017
  Layers,
860
1018
  Lines,
1019
+ Models,
861
1020
  PlanEditor,
862
1021
  Points,
863
1022
  Polygons,