@superrouteca/smap-react 1.1.6 → 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 +19 -0
- package/README.md +22 -1
- package/dist/index.cjs +209 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -3
- package/dist/index.d.ts +48 -3
- package/dist/index.js +198 -35
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -341,8 +341,157 @@ function Tool(props) {
|
|
|
341
341
|
return box ? createPortal(props.children, box) : null;
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
// src/features.tsx
|
|
345
|
+
import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
|
|
346
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
347
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
348
|
+
function CustomMarkers(props) {
|
|
349
|
+
const map = useSMap();
|
|
350
|
+
const { id, data, render: _render, ...rest } = props;
|
|
351
|
+
const latest = useRef4(props);
|
|
352
|
+
latest.current = props;
|
|
353
|
+
const [entries, setEntries] = useState3(/* @__PURE__ */ new Map());
|
|
354
|
+
const held = useRef4(/* @__PURE__ */ new Map());
|
|
355
|
+
const shown = useRef4(null);
|
|
356
|
+
const looks = optionsKey(rest);
|
|
357
|
+
const keyOf = (properties, feature) => {
|
|
358
|
+
const by = latest.current.idProperty;
|
|
359
|
+
const v = by ? properties[by] : feature.id;
|
|
360
|
+
return v === void 0 || v === null ? `@${JSON.stringify(feature.geometry)}` : String(v);
|
|
361
|
+
};
|
|
362
|
+
useEffect4(() => {
|
|
363
|
+
if (!map) {
|
|
364
|
+
return void 0;
|
|
365
|
+
}
|
|
366
|
+
held.current = /* @__PURE__ */ new Map();
|
|
367
|
+
let scheduled = false;
|
|
368
|
+
const publish = () => {
|
|
369
|
+
if (scheduled) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
scheduled = true;
|
|
373
|
+
queueMicrotask(() => {
|
|
374
|
+
scheduled = false;
|
|
375
|
+
setEntries(new Map(held.current));
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
const options = {
|
|
379
|
+
...latest.current,
|
|
380
|
+
render: (properties, feature) => {
|
|
381
|
+
const el = document.createElement("div");
|
|
382
|
+
held.current.set(keyOf(properties, feature), { el, properties, feature });
|
|
383
|
+
publish();
|
|
384
|
+
return el;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
delete options.id;
|
|
388
|
+
delete options.data;
|
|
389
|
+
map.addCustomMarkers(id, latest.current.data, options);
|
|
390
|
+
shown.current = latest.current.data;
|
|
391
|
+
return () => {
|
|
392
|
+
shown.current = null;
|
|
393
|
+
held.current = /* @__PURE__ */ new Map();
|
|
394
|
+
setEntries(/* @__PURE__ */ new Map());
|
|
395
|
+
if (!removedMaps.has(map)) {
|
|
396
|
+
map.removeLayer(id);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}, [map, id, looks]);
|
|
400
|
+
useEffect4(() => {
|
|
401
|
+
if (!map || shown.current === null || shown.current === data) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
shown.current = data;
|
|
405
|
+
map.setData(id, data);
|
|
406
|
+
const keep = /* @__PURE__ */ new Set();
|
|
407
|
+
const features = data && !Array.isArray(data) && data.features || [];
|
|
408
|
+
for (const f of features) {
|
|
409
|
+
keep.add(keyOf(f.properties || {}, f));
|
|
410
|
+
}
|
|
411
|
+
const by = latest.current.idProperty;
|
|
412
|
+
if (Array.isArray(data) && by) {
|
|
413
|
+
data.forEach((p) => keep.add(String(p[by])));
|
|
414
|
+
}
|
|
415
|
+
if (!Array.isArray(data) || by) {
|
|
416
|
+
let changed = false;
|
|
417
|
+
for (const k of [...held.current.keys()]) {
|
|
418
|
+
if (!keep.has(k)) {
|
|
419
|
+
held.current.delete(k);
|
|
420
|
+
changed = true;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (changed) {
|
|
424
|
+
setEntries(new Map(held.current));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}, [map, id, data]);
|
|
428
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: [...entries.entries()].map(([k, e]) => createPortal2(latest.current.render(e.properties, e.feature), e.el, `${id}\0${k}`)) });
|
|
429
|
+
}
|
|
430
|
+
function useNativeLayer(add, id, looks, data) {
|
|
431
|
+
const map = useSMap();
|
|
432
|
+
const shown = useRef4(null);
|
|
433
|
+
const addRef = useRef4(add);
|
|
434
|
+
addRef.current = add;
|
|
435
|
+
useEffect4(() => {
|
|
436
|
+
if (!map) {
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
addRef.current(map);
|
|
440
|
+
shown.current = data;
|
|
441
|
+
return () => {
|
|
442
|
+
shown.current = null;
|
|
443
|
+
if (!removedMaps.has(map)) {
|
|
444
|
+
map.removeLayer(id);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}, [map, id, looks]);
|
|
448
|
+
useEffect4(() => {
|
|
449
|
+
if (!map || data === void 0 || shown.current === null || shown.current === data) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
shown.current = data;
|
|
453
|
+
map.setData(id, data);
|
|
454
|
+
}, [map, id, data]);
|
|
455
|
+
}
|
|
456
|
+
function Heatmap(props) {
|
|
457
|
+
useNativeLayer((m) => m.addHeatmap(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
function Models(props) {
|
|
461
|
+
useNativeLayer((m) => m.addModels(props.id, props.data, props.options), props.id, optionsKey(props.options), props.data);
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
function CanvasTiles(props) {
|
|
465
|
+
const draw = useRef4(props.draw);
|
|
466
|
+
draw.current = props.draw;
|
|
467
|
+
useNativeLayer((m) => m.addCanvasTiles(props.id, (...a) => draw.current(...a), props.options), props.id, optionsKey(props.options));
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
function DrawTool(props) {
|
|
471
|
+
const map = useSMap();
|
|
472
|
+
const latest = useRef4(props);
|
|
473
|
+
latest.current = props;
|
|
474
|
+
const { onChange: _c, onTool: _t, ...rest } = props;
|
|
475
|
+
const looks = optionsKey(rest);
|
|
476
|
+
useEffect4(() => {
|
|
477
|
+
if (!map) {
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
const { onChange: _a, onTool: _b, ...o } = latest.current;
|
|
481
|
+
const tool = map.drawTool({ ...o, onChange: (e) => latest.current.onChange?.(e) });
|
|
482
|
+
latest.current.onTool?.(tool);
|
|
483
|
+
return () => {
|
|
484
|
+
latest.current.onTool?.(null);
|
|
485
|
+
if (!removedMaps.has(map)) {
|
|
486
|
+
tool.destroy();
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}, [map, looks]);
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
|
|
344
493
|
// src/plan.tsx
|
|
345
|
-
import { forwardRef as forwardRef2, useEffect as
|
|
494
|
+
import { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef5, useState as useState4 } from "react";
|
|
346
495
|
function destroyOffMap(made) {
|
|
347
496
|
made.layer.remove = () => {
|
|
348
497
|
};
|
|
@@ -370,15 +519,16 @@ var EMPTY = {
|
|
|
370
519
|
choices: null,
|
|
371
520
|
locked: [],
|
|
372
521
|
last: null,
|
|
373
|
-
preview: null
|
|
522
|
+
preview: null,
|
|
523
|
+
path: null
|
|
374
524
|
};
|
|
375
525
|
function usePlanEditor(props) {
|
|
376
526
|
const map = useSMap();
|
|
377
|
-
const [editor, setEditor] =
|
|
378
|
-
const [state, setState] =
|
|
379
|
-
const latest =
|
|
527
|
+
const [editor, setEditor] = useState4(null);
|
|
528
|
+
const [state, setState] = useState4(EMPTY);
|
|
529
|
+
const latest = useRef5(props);
|
|
380
530
|
latest.current = props;
|
|
381
|
-
const applied =
|
|
531
|
+
const applied = useRef5(null);
|
|
382
532
|
const credentialKey = "key" in props.credentials ? "key:" + props.credentials.key : "token";
|
|
383
533
|
const madeKey = key2({
|
|
384
534
|
baseUrl: props.baseUrl,
|
|
@@ -393,9 +543,13 @@ function usePlanEditor(props) {
|
|
|
393
543
|
colors: props.colors,
|
|
394
544
|
preview: props.preview,
|
|
395
545
|
panel: props.panel,
|
|
396
|
-
labels: props.labels
|
|
546
|
+
labels: props.labels,
|
|
547
|
+
smapUrl: props.smapUrl,
|
|
548
|
+
fastPath: props.fastPath,
|
|
549
|
+
fastPathTimeout: props.fastPathTimeout,
|
|
550
|
+
fastPathRefineTimeout: props.fastPathRefineTimeout
|
|
397
551
|
});
|
|
398
|
-
|
|
552
|
+
useEffect5(() => {
|
|
399
553
|
if (!map) {
|
|
400
554
|
return void 0;
|
|
401
555
|
}
|
|
@@ -417,7 +571,11 @@ function usePlanEditor(props) {
|
|
|
417
571
|
preview: p.preview,
|
|
418
572
|
language: p.language,
|
|
419
573
|
labels: p.labels,
|
|
420
|
-
panel: p.panel
|
|
574
|
+
panel: p.panel,
|
|
575
|
+
smapUrl: p.smapUrl,
|
|
576
|
+
fastPath: p.fastPath,
|
|
577
|
+
fastPathTimeout: p.fastPathTimeout,
|
|
578
|
+
fastPathRefineTimeout: p.fastPathRefineTimeout
|
|
421
579
|
};
|
|
422
580
|
for (const k of Object.keys(options)) {
|
|
423
581
|
if (options[k] === void 0) {
|
|
@@ -454,7 +612,7 @@ function usePlanEditor(props) {
|
|
|
454
612
|
};
|
|
455
613
|
}, [map, credentialKey, madeKey]);
|
|
456
614
|
const incoming = planKey(props.plan);
|
|
457
|
-
|
|
615
|
+
useEffect5(() => {
|
|
458
616
|
if (!editor || !latest.current.plan) {
|
|
459
617
|
return;
|
|
460
618
|
}
|
|
@@ -466,7 +624,7 @@ function usePlanEditor(props) {
|
|
|
466
624
|
editor.setPlan(latest.current.plan).catch(() => {
|
|
467
625
|
});
|
|
468
626
|
}, [editor, incoming]);
|
|
469
|
-
|
|
627
|
+
useEffect5(() => {
|
|
470
628
|
if (editor && editor.panel && props.language) {
|
|
471
629
|
editor.panel.setLanguage(props.language);
|
|
472
630
|
}
|
|
@@ -480,9 +638,9 @@ var PlanEditor = forwardRef2(function PlanEditor2(props, ref) {
|
|
|
480
638
|
});
|
|
481
639
|
|
|
482
640
|
// src/interop.tsx
|
|
483
|
-
import { createContext as createContext2, Fragment, useContext as useContext2, useEffect as
|
|
641
|
+
import { createContext as createContext2, Fragment as Fragment2, useContext as useContext2, useEffect as useEffect6, useMemo, useRef as useRef6, useState as useState5 } from "react";
|
|
484
642
|
import * as sdk from "@superrouteca/smap";
|
|
485
|
-
import { jsx as
|
|
643
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
486
644
|
function quietly(f) {
|
|
487
645
|
try {
|
|
488
646
|
f();
|
|
@@ -493,12 +651,12 @@ var SourceContext = createContext2(null);
|
|
|
493
651
|
function Source(props) {
|
|
494
652
|
const map = useSMap();
|
|
495
653
|
const { id, source, children } = props;
|
|
496
|
-
const latest =
|
|
654
|
+
const latest = useRef6(source);
|
|
497
655
|
latest.current = source;
|
|
498
|
-
const inside =
|
|
499
|
-
const [shown, setShown] =
|
|
656
|
+
const inside = useRef6(/* @__PURE__ */ new Set());
|
|
657
|
+
const [shown, setShown] = useState5(null);
|
|
500
658
|
const sourceKey = optionsKey(source);
|
|
501
|
-
|
|
659
|
+
useEffect6(() => {
|
|
502
660
|
if (!map) {
|
|
503
661
|
return void 0;
|
|
504
662
|
}
|
|
@@ -523,7 +681,7 @@ function Source(props) {
|
|
|
523
681
|
if (!map || !shown || shown.map !== map) {
|
|
524
682
|
return null;
|
|
525
683
|
}
|
|
526
|
-
return /* @__PURE__ */
|
|
684
|
+
return /* @__PURE__ */ jsx4(SourceContext.Provider, { value: scope, children: /* @__PURE__ */ jsx4(Fragment2, { children }, shown.generation) });
|
|
527
685
|
}
|
|
528
686
|
function effectiveLayer(layer, sourceId, visible) {
|
|
529
687
|
const out = { ...layer };
|
|
@@ -553,11 +711,11 @@ function StyleLayer(props) {
|
|
|
553
711
|
const scope = useContext2(SourceContext);
|
|
554
712
|
const { layer, before, slot, visible = true } = props;
|
|
555
713
|
const current = effectiveLayer(layer, scope?.id, visible);
|
|
556
|
-
const latest =
|
|
714
|
+
const latest = useRef6(current);
|
|
557
715
|
latest.current = current;
|
|
558
|
-
const shown =
|
|
716
|
+
const shown = useRef6(null);
|
|
559
717
|
const structure = structureKey(current, before, slot);
|
|
560
|
-
|
|
718
|
+
useEffect6(() => {
|
|
561
719
|
if (!map) {
|
|
562
720
|
return void 0;
|
|
563
721
|
}
|
|
@@ -581,7 +739,7 @@ function StyleLayer(props) {
|
|
|
581
739
|
};
|
|
582
740
|
}, [map, structure, scope]);
|
|
583
741
|
const looks = optionsKey(current.paint) + optionsKey(current.layout) + optionsKey(current.filter);
|
|
584
|
-
|
|
742
|
+
useEffect6(() => {
|
|
585
743
|
const s = shown.current;
|
|
586
744
|
if (!map || !s || s.map !== map) {
|
|
587
745
|
return;
|
|
@@ -602,12 +760,12 @@ function StyleLayer(props) {
|
|
|
602
760
|
}
|
|
603
761
|
function useAddedLayer(method, id, options, remove) {
|
|
604
762
|
const map = useSMap();
|
|
605
|
-
const latest =
|
|
763
|
+
const latest = useRef6(options);
|
|
606
764
|
latest.current = options;
|
|
607
|
-
const removeLatest =
|
|
765
|
+
const removeLatest = useRef6(remove);
|
|
608
766
|
removeLatest.current = remove;
|
|
609
767
|
const looks = optionsKey(options);
|
|
610
|
-
|
|
768
|
+
useEffect6(() => {
|
|
611
769
|
if (!map) {
|
|
612
770
|
return void 0;
|
|
613
771
|
}
|
|
@@ -654,13 +812,13 @@ var dataLayerIds = (id) => [id, `${id}:lines`, `${id}:areas`];
|
|
|
654
812
|
function Data(props) {
|
|
655
813
|
const map = useSMap();
|
|
656
814
|
const { id, data, format, lat, lng, options, slot, onTap, visible = true, popupOptions } = props;
|
|
657
|
-
const latest =
|
|
815
|
+
const latest = useRef6(props);
|
|
658
816
|
latest.current = props;
|
|
659
|
-
const shownVisible =
|
|
817
|
+
const shownVisible = useRef6(true);
|
|
660
818
|
const hasTap = !!onTap || typeof options?.onClick === "function";
|
|
661
819
|
const hasPopup = !!props.popup || typeof options?.popup === "function";
|
|
662
820
|
const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "") + "|" + (format ?? "") + "|" + (lat ?? "") + "|" + (lng ?? "");
|
|
663
|
-
|
|
821
|
+
useEffect6(() => {
|
|
664
822
|
if (!map) {
|
|
665
823
|
return void 0;
|
|
666
824
|
}
|
|
@@ -703,7 +861,7 @@ function Data(props) {
|
|
|
703
861
|
ids.forEach((l) => quietly(() => map.removeLayer(l)));
|
|
704
862
|
};
|
|
705
863
|
}, [map, id, data, looks, hasTap, hasPopup]);
|
|
706
|
-
|
|
864
|
+
useEffect6(() => {
|
|
707
865
|
if (!map || shownVisible.current === visible) {
|
|
708
866
|
return;
|
|
709
867
|
}
|
|
@@ -715,10 +873,10 @@ function Data(props) {
|
|
|
715
873
|
}
|
|
716
874
|
function Layers(props) {
|
|
717
875
|
const map = useSMap();
|
|
718
|
-
const latest =
|
|
876
|
+
const latest = useRef6(props.json);
|
|
719
877
|
latest.current = props.json;
|
|
720
878
|
const jsonKey = typeof props.json === "string" ? props.json : optionsKey(props.json);
|
|
721
|
-
|
|
879
|
+
useEffect6(() => {
|
|
722
880
|
if (!map) {
|
|
723
881
|
return void 0;
|
|
724
882
|
}
|
|
@@ -738,10 +896,10 @@ function Layers(props) {
|
|
|
738
896
|
function DeckLayer(props) {
|
|
739
897
|
const map = useSMap();
|
|
740
898
|
const { layer } = props;
|
|
741
|
-
const latest =
|
|
899
|
+
const latest = useRef6(layer);
|
|
742
900
|
latest.current = layer;
|
|
743
|
-
const shown =
|
|
744
|
-
|
|
901
|
+
const shown = useRef6(null);
|
|
902
|
+
useEffect6(() => {
|
|
745
903
|
if (!map) {
|
|
746
904
|
return void 0;
|
|
747
905
|
}
|
|
@@ -754,7 +912,7 @@ function DeckLayer(props) {
|
|
|
754
912
|
}
|
|
755
913
|
};
|
|
756
914
|
}, [map, layer.id]);
|
|
757
|
-
|
|
915
|
+
useEffect6(() => {
|
|
758
916
|
const s = shown.current;
|
|
759
917
|
if (!map || !s || s.map !== map || s.layer === layer) {
|
|
760
918
|
return;
|
|
@@ -796,10 +954,15 @@ var formats2 = {
|
|
|
796
954
|
import { popupTemplate, planTexts } from "@superrouteca/smap";
|
|
797
955
|
export {
|
|
798
956
|
ArcGisLayer,
|
|
957
|
+
CanvasTiles,
|
|
958
|
+
CustomMarkers,
|
|
799
959
|
Data,
|
|
800
960
|
DeckLayer,
|
|
961
|
+
DrawTool,
|
|
962
|
+
Heatmap,
|
|
801
963
|
Layers,
|
|
802
964
|
Lines,
|
|
965
|
+
Models,
|
|
803
966
|
PlanEditor,
|
|
804
967
|
Points,
|
|
805
968
|
Polygons,
|