@classic-homes/maps-react 0.6.0 → 0.6.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/dist/index.cjs +94 -29
- package/dist/index.js +94 -29
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -754,7 +754,53 @@ var Map2 = React6__namespace.forwardRef(
|
|
|
754
754
|
}
|
|
755
755
|
);
|
|
756
756
|
Map2.displayName = "Map";
|
|
757
|
-
|
|
757
|
+
function createSourceRegistry() {
|
|
758
|
+
const versions = /* @__PURE__ */ new Map();
|
|
759
|
+
const stacking = /* @__PURE__ */ new Map();
|
|
760
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
761
|
+
let counter = 0;
|
|
762
|
+
const notify = () => {
|
|
763
|
+
for (const listener of [...listeners]) listener();
|
|
764
|
+
};
|
|
765
|
+
return {
|
|
766
|
+
version: (id) => versions.get(id) ?? 0,
|
|
767
|
+
added(id) {
|
|
768
|
+
versions.set(id, ++counter);
|
|
769
|
+
notify();
|
|
770
|
+
},
|
|
771
|
+
removed(id, layersAbove) {
|
|
772
|
+
stacking.set(id, layersAbove ?? /* @__PURE__ */ new Map());
|
|
773
|
+
if (versions.delete(id)) notify();
|
|
774
|
+
},
|
|
775
|
+
layersAbove: (sourceId, layerId) => stacking.get(sourceId)?.get(layerId) ?? [],
|
|
776
|
+
subscribe(listener) {
|
|
777
|
+
listeners.add(listener);
|
|
778
|
+
return () => {
|
|
779
|
+
listeners.delete(listener);
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
var registries = /* @__PURE__ */ new WeakMap();
|
|
785
|
+
function getSourceRegistry(map) {
|
|
786
|
+
let registry = registries.get(map);
|
|
787
|
+
if (!registry) {
|
|
788
|
+
registry = createSourceRegistry();
|
|
789
|
+
registries.set(map, registry);
|
|
790
|
+
}
|
|
791
|
+
return registry;
|
|
792
|
+
}
|
|
793
|
+
var noopSubscribe = () => () => {
|
|
794
|
+
};
|
|
795
|
+
var zero = () => 0;
|
|
796
|
+
function useSourceVersion(map, sourceId) {
|
|
797
|
+
const registry = map ? getSourceRegistry(map) : null;
|
|
798
|
+
const getSnapshot = React6__namespace.useCallback(
|
|
799
|
+
() => registry ? registry.version(sourceId) : 0,
|
|
800
|
+
[registry, sourceId]
|
|
801
|
+
);
|
|
802
|
+
return React6__namespace.useSyncExternalStore(registry?.subscribe ?? noopSubscribe, getSnapshot, zero);
|
|
803
|
+
}
|
|
758
804
|
var Source = ({
|
|
759
805
|
id,
|
|
760
806
|
type,
|
|
@@ -777,7 +823,6 @@ var Source = ({
|
|
|
777
823
|
const { map, loaded, styleVersion } = useMap();
|
|
778
824
|
const initialFitDone = React6__namespace.useRef(false);
|
|
779
825
|
const appliedDataRef = React6__namespace.useRef(void 0);
|
|
780
|
-
const [sourceVersion, setSourceVersion] = React6__namespace.useState(0);
|
|
781
826
|
const fitBoundsParamsRef = React6__namespace.useRef({
|
|
782
827
|
shouldFitBounds,
|
|
783
828
|
data,
|
|
@@ -928,7 +973,8 @@ var Source = ({
|
|
|
928
973
|
map.once("idle", handleIdle);
|
|
929
974
|
map.addSource(id, sourceConfig);
|
|
930
975
|
appliedDataRef.current = type === "geojson" ? data : void 0;
|
|
931
|
-
|
|
976
|
+
const registry = getSourceRegistry(map);
|
|
977
|
+
registry.added(id);
|
|
932
978
|
const source = map.getSource(id);
|
|
933
979
|
if (source && map.isSourceLoaded(id)) {
|
|
934
980
|
map.off("sourcedata", handleSourceData);
|
|
@@ -947,11 +993,14 @@ var Source = ({
|
|
|
947
993
|
return () => {
|
|
948
994
|
cleanupListeners();
|
|
949
995
|
if (map) {
|
|
996
|
+
const layersAbove = /* @__PURE__ */ new Map();
|
|
950
997
|
try {
|
|
951
998
|
const style = map.getStyle();
|
|
952
999
|
if (style?.layers) {
|
|
953
|
-
style.layers.
|
|
1000
|
+
const ids = style.layers.map((layer) => layer.id);
|
|
1001
|
+
style.layers.forEach((layer, index) => {
|
|
954
1002
|
if ("source" in layer && layer.source === id) {
|
|
1003
|
+
layersAbove.set(layer.id, ids.slice(index + 1));
|
|
955
1004
|
if (map.getLayer(layer.id)) {
|
|
956
1005
|
map.removeLayer(layer.id);
|
|
957
1006
|
}
|
|
@@ -963,6 +1012,7 @@ var Source = ({
|
|
|
963
1012
|
}
|
|
964
1013
|
} catch {
|
|
965
1014
|
}
|
|
1015
|
+
registry.removed(id, layersAbove);
|
|
966
1016
|
}
|
|
967
1017
|
};
|
|
968
1018
|
} catch (err) {
|
|
@@ -1018,8 +1068,7 @@ var Source = ({
|
|
|
1018
1068
|
console.error(`[maps-react] Failed to update source "${id}" data:`, err);
|
|
1019
1069
|
}
|
|
1020
1070
|
}, [map, loaded, id, type, data, cluster]);
|
|
1021
|
-
|
|
1022
|
-
return /* @__PURE__ */ jsxRuntime.jsx(SourceContext.Provider, { value: sourceContext, children });
|
|
1071
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
1023
1072
|
};
|
|
1024
1073
|
Source.displayName = "Source";
|
|
1025
1074
|
var Marker = React6__namespace.forwardRef(
|
|
@@ -1452,14 +1501,16 @@ function useLayer({
|
|
|
1452
1501
|
hoverThrottleMs = 0
|
|
1453
1502
|
}) {
|
|
1454
1503
|
const { map, loaded, styleVersion } = useMap();
|
|
1455
|
-
const
|
|
1456
|
-
const sourceVersion = sourceContext?.id === source ? sourceContext.version : 0;
|
|
1504
|
+
const sourceVersion = useSourceVersion(map, source);
|
|
1457
1505
|
const [layerAdded, setLayerAdded] = React6__namespace.useState(false);
|
|
1458
1506
|
const hoveredFeatureId = React6__namespace.useRef(null);
|
|
1459
1507
|
const lastHoverCallTime = React6__namespace.useRef(0);
|
|
1460
1508
|
const lastMousePosition = React6__namespace.useRef(null);
|
|
1461
1509
|
const lastAppliedPaintRef = React6__namespace.useRef(void 0);
|
|
1462
1510
|
const lastAppliedLayoutRef = React6__namespace.useRef(void 0);
|
|
1511
|
+
const latestRef = React6__namespace.useRef({ visible, minZoom, maxZoom, filter, paint, layout });
|
|
1512
|
+
latestRef.current = { visible, minZoom, maxZoom, filter, paint, layout };
|
|
1513
|
+
const restoreLayerRef = React6__namespace.useRef(null);
|
|
1463
1514
|
React6__namespace.useEffect(() => {
|
|
1464
1515
|
hoveredFeatureId.current = null;
|
|
1465
1516
|
}, [styleVersion]);
|
|
@@ -1467,52 +1518,63 @@ function useLayer({
|
|
|
1467
1518
|
if (!map || !loaded) return;
|
|
1468
1519
|
let added = false;
|
|
1469
1520
|
let timeoutId = null;
|
|
1470
|
-
const
|
|
1521
|
+
const stopWaiting = () => {
|
|
1522
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1523
|
+
timeoutId = null;
|
|
1524
|
+
map.off("sourcedata", checkSource);
|
|
1525
|
+
};
|
|
1526
|
+
function checkSource() {
|
|
1471
1527
|
if (map.getSource(source)) {
|
|
1472
|
-
|
|
1473
|
-
timeoutId = null;
|
|
1474
|
-
map.off("sourcedata", checkSource);
|
|
1528
|
+
stopWaiting();
|
|
1475
1529
|
addLayer();
|
|
1476
1530
|
}
|
|
1477
|
-
}
|
|
1478
|
-
function addLayer() {
|
|
1531
|
+
}
|
|
1532
|
+
function addLayer(insertBefore = beforeId) {
|
|
1479
1533
|
if (map.getLayer(id)) {
|
|
1480
1534
|
added = true;
|
|
1481
1535
|
setLayerAdded(true);
|
|
1482
1536
|
return;
|
|
1483
1537
|
}
|
|
1538
|
+
const { visible: visible2, minZoom: minZoom2, maxZoom: maxZoom2, filter: filter2, paint: paint2, layout: layout2 } = latestRef.current;
|
|
1484
1539
|
try {
|
|
1485
1540
|
const layerConfig = {
|
|
1486
1541
|
id,
|
|
1487
1542
|
type,
|
|
1488
1543
|
source,
|
|
1489
|
-
paint,
|
|
1544
|
+
paint: paint2,
|
|
1490
1545
|
layout: {
|
|
1491
|
-
visibility:
|
|
1492
|
-
...
|
|
1546
|
+
visibility: visible2 ? "visible" : "none",
|
|
1547
|
+
...layout2
|
|
1493
1548
|
}
|
|
1494
1549
|
};
|
|
1495
1550
|
if (sourceLayer) {
|
|
1496
1551
|
layerConfig["source-layer"] = sourceLayer;
|
|
1497
1552
|
}
|
|
1498
|
-
if (
|
|
1499
|
-
layerConfig.minzoom =
|
|
1553
|
+
if (minZoom2 !== void 0) {
|
|
1554
|
+
layerConfig.minzoom = minZoom2;
|
|
1500
1555
|
}
|
|
1501
|
-
if (
|
|
1502
|
-
layerConfig.maxzoom =
|
|
1556
|
+
if (maxZoom2 !== void 0) {
|
|
1557
|
+
layerConfig.maxzoom = maxZoom2;
|
|
1503
1558
|
}
|
|
1504
|
-
if (
|
|
1505
|
-
layerConfig.filter =
|
|
1559
|
+
if (filter2) {
|
|
1560
|
+
layerConfig.filter = filter2;
|
|
1506
1561
|
}
|
|
1507
|
-
map.addLayer(layerConfig,
|
|
1562
|
+
map.addLayer(layerConfig, insertBefore);
|
|
1508
1563
|
added = true;
|
|
1509
|
-
lastAppliedPaintRef.current = { ...
|
|
1510
|
-
lastAppliedLayoutRef.current = withoutVisibility(
|
|
1564
|
+
lastAppliedPaintRef.current = { ...paint2 };
|
|
1565
|
+
lastAppliedLayoutRef.current = withoutVisibility(layout2);
|
|
1511
1566
|
setLayerAdded(true);
|
|
1512
1567
|
} catch (err) {
|
|
1513
1568
|
console.error(`[maps-react] Failed to add layer "${id}":`, err);
|
|
1514
1569
|
}
|
|
1515
1570
|
}
|
|
1571
|
+
restoreLayerRef.current = () => {
|
|
1572
|
+
if (map.getLayer(id) || !map.getSource(source)) return;
|
|
1573
|
+
hoveredFeatureId.current = null;
|
|
1574
|
+
stopWaiting();
|
|
1575
|
+
const above = beforeId ? void 0 : getSourceRegistry(map).layersAbove(source, id).find((layerId) => map.getLayer(layerId));
|
|
1576
|
+
addLayer(beforeId ?? above);
|
|
1577
|
+
};
|
|
1516
1578
|
if (map.getSource(source)) {
|
|
1517
1579
|
addLayer();
|
|
1518
1580
|
} else {
|
|
@@ -1526,8 +1588,8 @@ function useLayer({
|
|
|
1526
1588
|
map.on("sourcedata", checkSource);
|
|
1527
1589
|
}
|
|
1528
1590
|
return () => {
|
|
1529
|
-
|
|
1530
|
-
|
|
1591
|
+
restoreLayerRef.current = null;
|
|
1592
|
+
stopWaiting();
|
|
1531
1593
|
if (added) {
|
|
1532
1594
|
try {
|
|
1533
1595
|
if (map.getLayer(id)) {
|
|
@@ -1538,7 +1600,10 @@ function useLayer({
|
|
|
1538
1600
|
}
|
|
1539
1601
|
setLayerAdded(false);
|
|
1540
1602
|
};
|
|
1541
|
-
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion
|
|
1603
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1604
|
+
React6__namespace.useEffect(() => {
|
|
1605
|
+
if (sourceVersion) restoreLayerRef.current?.();
|
|
1606
|
+
}, [sourceVersion]);
|
|
1542
1607
|
React6__namespace.useEffect(() => {
|
|
1543
1608
|
if (!map || !layerAdded) return;
|
|
1544
1609
|
if (!map.getLayer(id)) return;
|
package/dist/index.js
CHANGED
|
@@ -735,7 +735,53 @@ var Map2 = React6.forwardRef(
|
|
|
735
735
|
}
|
|
736
736
|
);
|
|
737
737
|
Map2.displayName = "Map";
|
|
738
|
-
|
|
738
|
+
function createSourceRegistry() {
|
|
739
|
+
const versions = /* @__PURE__ */ new Map();
|
|
740
|
+
const stacking = /* @__PURE__ */ new Map();
|
|
741
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
742
|
+
let counter = 0;
|
|
743
|
+
const notify = () => {
|
|
744
|
+
for (const listener of [...listeners]) listener();
|
|
745
|
+
};
|
|
746
|
+
return {
|
|
747
|
+
version: (id) => versions.get(id) ?? 0,
|
|
748
|
+
added(id) {
|
|
749
|
+
versions.set(id, ++counter);
|
|
750
|
+
notify();
|
|
751
|
+
},
|
|
752
|
+
removed(id, layersAbove) {
|
|
753
|
+
stacking.set(id, layersAbove ?? /* @__PURE__ */ new Map());
|
|
754
|
+
if (versions.delete(id)) notify();
|
|
755
|
+
},
|
|
756
|
+
layersAbove: (sourceId, layerId) => stacking.get(sourceId)?.get(layerId) ?? [],
|
|
757
|
+
subscribe(listener) {
|
|
758
|
+
listeners.add(listener);
|
|
759
|
+
return () => {
|
|
760
|
+
listeners.delete(listener);
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
var registries = /* @__PURE__ */ new WeakMap();
|
|
766
|
+
function getSourceRegistry(map) {
|
|
767
|
+
let registry = registries.get(map);
|
|
768
|
+
if (!registry) {
|
|
769
|
+
registry = createSourceRegistry();
|
|
770
|
+
registries.set(map, registry);
|
|
771
|
+
}
|
|
772
|
+
return registry;
|
|
773
|
+
}
|
|
774
|
+
var noopSubscribe = () => () => {
|
|
775
|
+
};
|
|
776
|
+
var zero = () => 0;
|
|
777
|
+
function useSourceVersion(map, sourceId) {
|
|
778
|
+
const registry = map ? getSourceRegistry(map) : null;
|
|
779
|
+
const getSnapshot = React6.useCallback(
|
|
780
|
+
() => registry ? registry.version(sourceId) : 0,
|
|
781
|
+
[registry, sourceId]
|
|
782
|
+
);
|
|
783
|
+
return React6.useSyncExternalStore(registry?.subscribe ?? noopSubscribe, getSnapshot, zero);
|
|
784
|
+
}
|
|
739
785
|
var Source = ({
|
|
740
786
|
id,
|
|
741
787
|
type,
|
|
@@ -758,7 +804,6 @@ var Source = ({
|
|
|
758
804
|
const { map, loaded, styleVersion } = useMap();
|
|
759
805
|
const initialFitDone = React6.useRef(false);
|
|
760
806
|
const appliedDataRef = React6.useRef(void 0);
|
|
761
|
-
const [sourceVersion, setSourceVersion] = React6.useState(0);
|
|
762
807
|
const fitBoundsParamsRef = React6.useRef({
|
|
763
808
|
shouldFitBounds,
|
|
764
809
|
data,
|
|
@@ -909,7 +954,8 @@ var Source = ({
|
|
|
909
954
|
map.once("idle", handleIdle);
|
|
910
955
|
map.addSource(id, sourceConfig);
|
|
911
956
|
appliedDataRef.current = type === "geojson" ? data : void 0;
|
|
912
|
-
|
|
957
|
+
const registry = getSourceRegistry(map);
|
|
958
|
+
registry.added(id);
|
|
913
959
|
const source = map.getSource(id);
|
|
914
960
|
if (source && map.isSourceLoaded(id)) {
|
|
915
961
|
map.off("sourcedata", handleSourceData);
|
|
@@ -928,11 +974,14 @@ var Source = ({
|
|
|
928
974
|
return () => {
|
|
929
975
|
cleanupListeners();
|
|
930
976
|
if (map) {
|
|
977
|
+
const layersAbove = /* @__PURE__ */ new Map();
|
|
931
978
|
try {
|
|
932
979
|
const style = map.getStyle();
|
|
933
980
|
if (style?.layers) {
|
|
934
|
-
style.layers.
|
|
981
|
+
const ids = style.layers.map((layer) => layer.id);
|
|
982
|
+
style.layers.forEach((layer, index) => {
|
|
935
983
|
if ("source" in layer && layer.source === id) {
|
|
984
|
+
layersAbove.set(layer.id, ids.slice(index + 1));
|
|
936
985
|
if (map.getLayer(layer.id)) {
|
|
937
986
|
map.removeLayer(layer.id);
|
|
938
987
|
}
|
|
@@ -944,6 +993,7 @@ var Source = ({
|
|
|
944
993
|
}
|
|
945
994
|
} catch {
|
|
946
995
|
}
|
|
996
|
+
registry.removed(id, layersAbove);
|
|
947
997
|
}
|
|
948
998
|
};
|
|
949
999
|
} catch (err) {
|
|
@@ -999,8 +1049,7 @@ var Source = ({
|
|
|
999
1049
|
console.error(`[maps-react] Failed to update source "${id}" data:`, err);
|
|
1000
1050
|
}
|
|
1001
1051
|
}, [map, loaded, id, type, data, cluster]);
|
|
1002
|
-
|
|
1003
|
-
return /* @__PURE__ */ jsx(SourceContext.Provider, { value: sourceContext, children });
|
|
1052
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1004
1053
|
};
|
|
1005
1054
|
Source.displayName = "Source";
|
|
1006
1055
|
var Marker = React6.forwardRef(
|
|
@@ -1433,14 +1482,16 @@ function useLayer({
|
|
|
1433
1482
|
hoverThrottleMs = 0
|
|
1434
1483
|
}) {
|
|
1435
1484
|
const { map, loaded, styleVersion } = useMap();
|
|
1436
|
-
const
|
|
1437
|
-
const sourceVersion = sourceContext?.id === source ? sourceContext.version : 0;
|
|
1485
|
+
const sourceVersion = useSourceVersion(map, source);
|
|
1438
1486
|
const [layerAdded, setLayerAdded] = React6.useState(false);
|
|
1439
1487
|
const hoveredFeatureId = React6.useRef(null);
|
|
1440
1488
|
const lastHoverCallTime = React6.useRef(0);
|
|
1441
1489
|
const lastMousePosition = React6.useRef(null);
|
|
1442
1490
|
const lastAppliedPaintRef = React6.useRef(void 0);
|
|
1443
1491
|
const lastAppliedLayoutRef = React6.useRef(void 0);
|
|
1492
|
+
const latestRef = React6.useRef({ visible, minZoom, maxZoom, filter, paint, layout });
|
|
1493
|
+
latestRef.current = { visible, minZoom, maxZoom, filter, paint, layout };
|
|
1494
|
+
const restoreLayerRef = React6.useRef(null);
|
|
1444
1495
|
React6.useEffect(() => {
|
|
1445
1496
|
hoveredFeatureId.current = null;
|
|
1446
1497
|
}, [styleVersion]);
|
|
@@ -1448,52 +1499,63 @@ function useLayer({
|
|
|
1448
1499
|
if (!map || !loaded) return;
|
|
1449
1500
|
let added = false;
|
|
1450
1501
|
let timeoutId = null;
|
|
1451
|
-
const
|
|
1502
|
+
const stopWaiting = () => {
|
|
1503
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1504
|
+
timeoutId = null;
|
|
1505
|
+
map.off("sourcedata", checkSource);
|
|
1506
|
+
};
|
|
1507
|
+
function checkSource() {
|
|
1452
1508
|
if (map.getSource(source)) {
|
|
1453
|
-
|
|
1454
|
-
timeoutId = null;
|
|
1455
|
-
map.off("sourcedata", checkSource);
|
|
1509
|
+
stopWaiting();
|
|
1456
1510
|
addLayer();
|
|
1457
1511
|
}
|
|
1458
|
-
}
|
|
1459
|
-
function addLayer() {
|
|
1512
|
+
}
|
|
1513
|
+
function addLayer(insertBefore = beforeId) {
|
|
1460
1514
|
if (map.getLayer(id)) {
|
|
1461
1515
|
added = true;
|
|
1462
1516
|
setLayerAdded(true);
|
|
1463
1517
|
return;
|
|
1464
1518
|
}
|
|
1519
|
+
const { visible: visible2, minZoom: minZoom2, maxZoom: maxZoom2, filter: filter2, paint: paint2, layout: layout2 } = latestRef.current;
|
|
1465
1520
|
try {
|
|
1466
1521
|
const layerConfig = {
|
|
1467
1522
|
id,
|
|
1468
1523
|
type,
|
|
1469
1524
|
source,
|
|
1470
|
-
paint,
|
|
1525
|
+
paint: paint2,
|
|
1471
1526
|
layout: {
|
|
1472
|
-
visibility:
|
|
1473
|
-
...
|
|
1527
|
+
visibility: visible2 ? "visible" : "none",
|
|
1528
|
+
...layout2
|
|
1474
1529
|
}
|
|
1475
1530
|
};
|
|
1476
1531
|
if (sourceLayer) {
|
|
1477
1532
|
layerConfig["source-layer"] = sourceLayer;
|
|
1478
1533
|
}
|
|
1479
|
-
if (
|
|
1480
|
-
layerConfig.minzoom =
|
|
1534
|
+
if (minZoom2 !== void 0) {
|
|
1535
|
+
layerConfig.minzoom = minZoom2;
|
|
1481
1536
|
}
|
|
1482
|
-
if (
|
|
1483
|
-
layerConfig.maxzoom =
|
|
1537
|
+
if (maxZoom2 !== void 0) {
|
|
1538
|
+
layerConfig.maxzoom = maxZoom2;
|
|
1484
1539
|
}
|
|
1485
|
-
if (
|
|
1486
|
-
layerConfig.filter =
|
|
1540
|
+
if (filter2) {
|
|
1541
|
+
layerConfig.filter = filter2;
|
|
1487
1542
|
}
|
|
1488
|
-
map.addLayer(layerConfig,
|
|
1543
|
+
map.addLayer(layerConfig, insertBefore);
|
|
1489
1544
|
added = true;
|
|
1490
|
-
lastAppliedPaintRef.current = { ...
|
|
1491
|
-
lastAppliedLayoutRef.current = withoutVisibility(
|
|
1545
|
+
lastAppliedPaintRef.current = { ...paint2 };
|
|
1546
|
+
lastAppliedLayoutRef.current = withoutVisibility(layout2);
|
|
1492
1547
|
setLayerAdded(true);
|
|
1493
1548
|
} catch (err) {
|
|
1494
1549
|
console.error(`[maps-react] Failed to add layer "${id}":`, err);
|
|
1495
1550
|
}
|
|
1496
1551
|
}
|
|
1552
|
+
restoreLayerRef.current = () => {
|
|
1553
|
+
if (map.getLayer(id) || !map.getSource(source)) return;
|
|
1554
|
+
hoveredFeatureId.current = null;
|
|
1555
|
+
stopWaiting();
|
|
1556
|
+
const above = beforeId ? void 0 : getSourceRegistry(map).layersAbove(source, id).find((layerId) => map.getLayer(layerId));
|
|
1557
|
+
addLayer(beforeId ?? above);
|
|
1558
|
+
};
|
|
1497
1559
|
if (map.getSource(source)) {
|
|
1498
1560
|
addLayer();
|
|
1499
1561
|
} else {
|
|
@@ -1507,8 +1569,8 @@ function useLayer({
|
|
|
1507
1569
|
map.on("sourcedata", checkSource);
|
|
1508
1570
|
}
|
|
1509
1571
|
return () => {
|
|
1510
|
-
|
|
1511
|
-
|
|
1572
|
+
restoreLayerRef.current = null;
|
|
1573
|
+
stopWaiting();
|
|
1512
1574
|
if (added) {
|
|
1513
1575
|
try {
|
|
1514
1576
|
if (map.getLayer(id)) {
|
|
@@ -1519,7 +1581,10 @@ function useLayer({
|
|
|
1519
1581
|
}
|
|
1520
1582
|
setLayerAdded(false);
|
|
1521
1583
|
};
|
|
1522
|
-
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion
|
|
1584
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1585
|
+
React6.useEffect(() => {
|
|
1586
|
+
if (sourceVersion) restoreLayerRef.current?.();
|
|
1587
|
+
}, [sourceVersion]);
|
|
1523
1588
|
React6.useEffect(() => {
|
|
1524
1589
|
if (!map || !layerAdded) return;
|
|
1525
1590
|
if (!map.getLayer(id)) return;
|