@classic-homes/maps-react 0.7.5 → 0.9.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/dist/index.cjs +178 -19
- package/dist/index.d.cts +0 -28
- package/dist/index.d.ts +0 -28
- package/dist/index.js +179 -20
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -312,6 +312,7 @@ function getStyleKey(style) {
|
|
|
312
312
|
if (!style) return "";
|
|
313
313
|
return typeof style === "string" ? style : JSON.stringify(style);
|
|
314
314
|
}
|
|
315
|
+
var angleDelta = (a, b) => Math.abs(((a - b) % 360 + 540) % 360 - 180);
|
|
315
316
|
var Map3 = React6__namespace.forwardRef(
|
|
316
317
|
({
|
|
317
318
|
// Base props
|
|
@@ -369,6 +370,7 @@ var Map3 = React6__namespace.forwardRef(
|
|
|
369
370
|
}, ref) => {
|
|
370
371
|
const containerRef = React6__namespace.useRef(null);
|
|
371
372
|
const mapRef = React6__namespace.useRef(null);
|
|
373
|
+
const appliedViewRef = React6__namespace.useRef(null);
|
|
372
374
|
const [mapLoaded, setMapLoaded] = React6__namespace.useState(false);
|
|
373
375
|
const [mapError, setMapError] = React6__namespace.useState(null);
|
|
374
376
|
const [initAttempt, setInitAttempt] = React6__namespace.useState(0);
|
|
@@ -473,6 +475,7 @@ var Map3 = React6__namespace.forwardRef(
|
|
|
473
475
|
} : {}
|
|
474
476
|
});
|
|
475
477
|
mapRef.current = map;
|
|
478
|
+
appliedViewRef.current = { center: [center[0], center[1]], zoom, bearing, pitch };
|
|
476
479
|
if (navigationControl) {
|
|
477
480
|
map.addControl(
|
|
478
481
|
new maplibregl__namespace.NavigationControl({
|
|
@@ -622,6 +625,32 @@ var Map3 = React6__namespace.forwardRef(
|
|
|
622
625
|
activeStyleOverrideRef.current = null;
|
|
623
626
|
}
|
|
624
627
|
}, [customStyleKey]);
|
|
628
|
+
const [centerLng, centerLat] = center;
|
|
629
|
+
React6__namespace.useEffect(() => {
|
|
630
|
+
const map = mapRef.current;
|
|
631
|
+
if (!map || !mapLoaded) return;
|
|
632
|
+
const next = { center: [centerLng, centerLat], zoom, bearing, pitch };
|
|
633
|
+
const prev = appliedViewRef.current;
|
|
634
|
+
appliedViewRef.current = next;
|
|
635
|
+
if (!prev) return;
|
|
636
|
+
const view = {};
|
|
637
|
+
const shown = map.getCenter();
|
|
638
|
+
if ((next.center[0] !== prev.center[0] || next.center[1] !== prev.center[1]) && (Math.abs(shown.lng - next.center[0]) > 1e-9 || Math.abs(shown.lat - next.center[1]) > 1e-9)) {
|
|
639
|
+
view.center = next.center;
|
|
640
|
+
}
|
|
641
|
+
if (next.zoom !== prev.zoom && Math.abs(map.getZoom() - next.zoom) > 1e-6) {
|
|
642
|
+
view.zoom = next.zoom;
|
|
643
|
+
}
|
|
644
|
+
if (next.bearing !== prev.bearing && angleDelta(map.getBearing(), next.bearing) > 1e-6) {
|
|
645
|
+
view.bearing = next.bearing;
|
|
646
|
+
}
|
|
647
|
+
if (next.pitch !== prev.pitch && Math.abs(map.getPitch() - next.pitch) > 1e-6) {
|
|
648
|
+
view.pitch = next.pitch;
|
|
649
|
+
}
|
|
650
|
+
if (Object.keys(view).length === 0) return;
|
|
651
|
+
if (animation && !prefersReducedMotion) map.easeTo(view);
|
|
652
|
+
else map.jumpTo(view);
|
|
653
|
+
}, [mapLoaded, centerLng, centerLat, zoom, bearing, pitch]);
|
|
625
654
|
React6__namespace.useEffect(() => {
|
|
626
655
|
const map = mapRef.current;
|
|
627
656
|
if (!map || !mapLoaded) return;
|
|
@@ -745,7 +774,13 @@ var Map3 = React6__namespace.forwardRef(
|
|
|
745
774
|
emptyMessage,
|
|
746
775
|
className,
|
|
747
776
|
children: /* @__PURE__ */ jsxRuntime.jsxs(MapContext.Provider, { value: contextValue, children: [
|
|
748
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
777
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
778
|
+
"div",
|
|
779
|
+
{
|
|
780
|
+
ref: containerRef,
|
|
781
|
+
style: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 }
|
|
782
|
+
}
|
|
783
|
+
),
|
|
749
784
|
mapLoaded && children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 pointer-events-none [&>*]:pointer-events-auto", children })
|
|
750
785
|
] })
|
|
751
786
|
}
|
|
@@ -1074,6 +1109,7 @@ var Marker2 = React6__namespace.forwardRef(
|
|
|
1074
1109
|
({
|
|
1075
1110
|
id,
|
|
1076
1111
|
coordinates,
|
|
1112
|
+
label,
|
|
1077
1113
|
// Heritage Teal, as in Svelte (MapLibre's own default is a light blue)
|
|
1078
1114
|
color = mapsCore.markerColor,
|
|
1079
1115
|
anchor = "bottom",
|
|
@@ -1128,7 +1164,14 @@ var Marker2 = React6__namespace.forwardRef(
|
|
|
1128
1164
|
if (children && elementRef.current) {
|
|
1129
1165
|
markerOptions.element = elementRef.current;
|
|
1130
1166
|
}
|
|
1131
|
-
const marker = new maplibregl__namespace.Marker(markerOptions)
|
|
1167
|
+
const marker = new maplibregl__namespace.Marker(markerOptions);
|
|
1168
|
+
mapsCore.applyMarkerAccessibility(marker.getElement(), {
|
|
1169
|
+
label,
|
|
1170
|
+
clickable: Boolean(onClickRef.current),
|
|
1171
|
+
draggable,
|
|
1172
|
+
custom: Boolean(children)
|
|
1173
|
+
});
|
|
1174
|
+
marker.setLngLat(coordinates).addTo(map);
|
|
1132
1175
|
const el = marker.getElement();
|
|
1133
1176
|
mapsCore.applyMarkerProtection(el);
|
|
1134
1177
|
if (children && elementRef.current) {
|
|
@@ -1214,6 +1257,17 @@ var Marker2 = React6__namespace.forwardRef(
|
|
|
1214
1257
|
}
|
|
1215
1258
|
};
|
|
1216
1259
|
}, [map, loaded, mounted]);
|
|
1260
|
+
const clickable = Boolean(onClick);
|
|
1261
|
+
const custom = Boolean(children);
|
|
1262
|
+
React6__namespace.useEffect(() => {
|
|
1263
|
+
const marker = markerRef.current;
|
|
1264
|
+
if (!marker) return;
|
|
1265
|
+
const element = marker.getElement();
|
|
1266
|
+
mapsCore.applyMarkerAccessibility(element, { label, clickable, draggable, custom });
|
|
1267
|
+
if (!clickable) return;
|
|
1268
|
+
element.addEventListener("keydown", mapsCore.handleMarkerKeydown);
|
|
1269
|
+
return () => element.removeEventListener("keydown", mapsCore.handleMarkerKeydown);
|
|
1270
|
+
}, [label, clickable, draggable, custom, map, loaded, mounted]);
|
|
1217
1271
|
React6__namespace.useEffect(() => {
|
|
1218
1272
|
if (markerRef.current) {
|
|
1219
1273
|
markerRef.current.setLngLat(coordinates);
|
|
@@ -1319,6 +1373,9 @@ var Popup2 = React6__namespace.forwardRef(
|
|
|
1319
1373
|
onCloseRef.current = onClose;
|
|
1320
1374
|
const coordinatesRef = React6__namespace.useRef(coordinates);
|
|
1321
1375
|
coordinatesRef.current = coordinates;
|
|
1376
|
+
const closeOnClickRef = React6__namespace.useRef(closeOnClick);
|
|
1377
|
+
closeOnClickRef.current = closeOnClick;
|
|
1378
|
+
const rebuildingOpenRef = React6__namespace.useRef(false);
|
|
1322
1379
|
const containerRef = React6__namespace.useRef(null);
|
|
1323
1380
|
if (!containerRef.current && typeof document !== "undefined") {
|
|
1324
1381
|
containerRef.current = document.createElement("div");
|
|
@@ -1335,7 +1392,9 @@ var Popup2 = React6__namespace.forwardRef(
|
|
|
1335
1392
|
if (!map || !loaded || !containerRef.current) return;
|
|
1336
1393
|
const popup = new maplibregl__namespace.Popup({
|
|
1337
1394
|
closeButton,
|
|
1338
|
-
|
|
1395
|
+
// Map clicks are handled below, so a click that moves the popup to
|
|
1396
|
+
// another feature does not also close it
|
|
1397
|
+
closeOnClick: false,
|
|
1339
1398
|
closeOnMove,
|
|
1340
1399
|
anchor,
|
|
1341
1400
|
offset,
|
|
@@ -1345,33 +1404,51 @@ var Popup2 = React6__namespace.forwardRef(
|
|
|
1345
1404
|
popup.setDOMContent(containerRef.current);
|
|
1346
1405
|
popupRef.current = popup;
|
|
1347
1406
|
setPopupVersion((v) => v + 1);
|
|
1407
|
+
let silent = rebuildingOpenRef.current;
|
|
1408
|
+
rebuildingOpenRef.current = false;
|
|
1409
|
+
let tearingDown = false;
|
|
1348
1410
|
popup.on("open", () => {
|
|
1411
|
+
if (silent) {
|
|
1412
|
+
silent = false;
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1349
1415
|
onOpenRef.current?.({
|
|
1350
1416
|
type: "open",
|
|
1351
1417
|
lngLat: coordinatesRef.current
|
|
1352
1418
|
});
|
|
1353
1419
|
});
|
|
1354
1420
|
popup.on("close", () => {
|
|
1421
|
+
if (tearingDown) return;
|
|
1355
1422
|
onCloseRef.current?.({
|
|
1356
1423
|
type: "close",
|
|
1357
1424
|
lngLat: coordinatesRef.current
|
|
1358
1425
|
});
|
|
1359
1426
|
});
|
|
1360
1427
|
return () => {
|
|
1428
|
+
tearingDown = true;
|
|
1429
|
+
rebuildingOpenRef.current = popup.isOpen();
|
|
1361
1430
|
popup.remove();
|
|
1362
1431
|
popupRef.current = null;
|
|
1363
1432
|
};
|
|
1364
|
-
}, [
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1433
|
+
}, [map, loaded, closeButton, closeOnMove, anchor, offset, maxWidth, focusAfterOpen]);
|
|
1434
|
+
React6__namespace.useEffect(() => {
|
|
1435
|
+
const popup = popupRef.current;
|
|
1436
|
+
if (!map || !popup || typeof map.on !== "function") return;
|
|
1437
|
+
const keyOf = (c) => JSON.stringify(c);
|
|
1438
|
+
const onMapClick = () => {
|
|
1439
|
+
if (!closeOnClickRef.current || !popup.isOpen()) return;
|
|
1440
|
+
const before = keyOf(coordinatesRef.current);
|
|
1441
|
+
setTimeout(() => {
|
|
1442
|
+
if (popupRef.current !== popup || !popup.isOpen()) return;
|
|
1443
|
+
if (keyOf(coordinatesRef.current) !== before) return;
|
|
1444
|
+
popup.remove();
|
|
1445
|
+
}, 0);
|
|
1446
|
+
};
|
|
1447
|
+
map.on("click", onMapClick);
|
|
1448
|
+
return () => {
|
|
1449
|
+
map.off("click", onMapClick);
|
|
1450
|
+
};
|
|
1451
|
+
}, [map, popupVersion]);
|
|
1375
1452
|
React6__namespace.useEffect(() => {
|
|
1376
1453
|
if (!popupRef.current || !ref) return;
|
|
1377
1454
|
if (typeof ref === "function") {
|
|
@@ -1388,13 +1465,24 @@ var Popup2 = React6__namespace.forwardRef(
|
|
|
1388
1465
|
React6__namespace.useEffect(() => {
|
|
1389
1466
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1390
1467
|
let rafHandle;
|
|
1468
|
+
let cancelPending;
|
|
1391
1469
|
if (open) {
|
|
1392
1470
|
popupRef.current.setLngLat(coordinates);
|
|
1393
1471
|
if (!popupRef.current.isOpen()) popupRef.current.addTo(map);
|
|
1394
1472
|
if (autoPan) {
|
|
1395
1473
|
rafHandle = requestAnimationFrame(() => {
|
|
1396
|
-
|
|
1397
|
-
|
|
1474
|
+
const target = popupRef.current;
|
|
1475
|
+
if (!target) return;
|
|
1476
|
+
const pan = () => {
|
|
1477
|
+
if (popupRef.current === target && target.isOpen()) {
|
|
1478
|
+
utils.panToFitPopup(map, target, utils.normalizePadding(autoPanPadding));
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
if (typeof map.isMoving === "function" && map.isMoving()) {
|
|
1482
|
+
map.once("moveend", pan);
|
|
1483
|
+
cancelPending = () => map.off("moveend", pan);
|
|
1484
|
+
} else {
|
|
1485
|
+
pan();
|
|
1398
1486
|
}
|
|
1399
1487
|
});
|
|
1400
1488
|
}
|
|
@@ -1405,6 +1493,7 @@ var Popup2 = React6__namespace.forwardRef(
|
|
|
1405
1493
|
if (rafHandle !== void 0) {
|
|
1406
1494
|
cancelAnimationFrame(rafHandle);
|
|
1407
1495
|
}
|
|
1496
|
+
cancelPending?.();
|
|
1408
1497
|
};
|
|
1409
1498
|
}, [map, open, coordinates, autoPan, autoPanPadding, contentReady, popupVersion]);
|
|
1410
1499
|
if (!containerRef.current) return null;
|
|
@@ -1791,6 +1880,17 @@ function useLayer({
|
|
|
1791
1880
|
map.on("mousemove", id, handleMouseMove);
|
|
1792
1881
|
map.on("mouseleave", id, handleMouseLeave);
|
|
1793
1882
|
}
|
|
1883
|
+
const pointerOn = () => {
|
|
1884
|
+
map.getCanvas().style.cursor = "pointer";
|
|
1885
|
+
};
|
|
1886
|
+
const pointerOff = () => {
|
|
1887
|
+
map.getCanvas().style.cursor = "";
|
|
1888
|
+
};
|
|
1889
|
+
const clickOnly = Boolean(onClick) && !onHover;
|
|
1890
|
+
if (clickOnly) {
|
|
1891
|
+
map.on("mouseenter", id, pointerOn);
|
|
1892
|
+
map.on("mouseleave", id, pointerOff);
|
|
1893
|
+
}
|
|
1794
1894
|
return () => {
|
|
1795
1895
|
if (onClick) {
|
|
1796
1896
|
map.off("click", id, handleClick);
|
|
@@ -1800,6 +1900,10 @@ function useLayer({
|
|
|
1800
1900
|
map.off("mousemove", id, handleMouseMove);
|
|
1801
1901
|
map.off("mouseleave", id, handleMouseLeave);
|
|
1802
1902
|
}
|
|
1903
|
+
if (clickOnly) {
|
|
1904
|
+
map.off("mouseenter", id, pointerOn);
|
|
1905
|
+
map.off("mouseleave", id, pointerOff);
|
|
1906
|
+
}
|
|
1803
1907
|
};
|
|
1804
1908
|
}, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
|
|
1805
1909
|
return { layerAdded };
|
|
@@ -2670,7 +2774,6 @@ var LegendGroup = ({
|
|
|
2670
2774
|
);
|
|
2671
2775
|
};
|
|
2672
2776
|
LegendGroup.displayName = "LegendGroup";
|
|
2673
|
-
var NAV_CONTROL_WIDTH = 29;
|
|
2674
2777
|
var CoordinateDisplay = ({
|
|
2675
2778
|
position = "bottom-right",
|
|
2676
2779
|
format = "decimal",
|
|
@@ -2684,6 +2787,7 @@ var CoordinateDisplay = ({
|
|
|
2684
2787
|
const [currentZoom, setCurrentZoom] = React6__namespace.useState(0);
|
|
2685
2788
|
const [currentBearing, setCurrentBearing] = React6__namespace.useState(0);
|
|
2686
2789
|
const controlRef = React6__namespace.useRef(null);
|
|
2790
|
+
const [topRightInset, setTopRightInset] = React6__namespace.useState(0);
|
|
2687
2791
|
const uniqueId = React6__namespace.useId();
|
|
2688
2792
|
const controlId = `coord-display${uniqueId}`;
|
|
2689
2793
|
const { style, visible } = useControlPosition(controlRef, {
|
|
@@ -2696,7 +2800,7 @@ var CoordinateDisplay = ({
|
|
|
2696
2800
|
const adjustedStyle = React6__namespace.useMemo(() => {
|
|
2697
2801
|
if (!style) return style;
|
|
2698
2802
|
if (position === "top-right") {
|
|
2699
|
-
const rightOffset =
|
|
2803
|
+
const rightOffset = topRightInset ? topRightInset + mapsCore.STACK_GAP : mapsCore.EDGE_MARGIN;
|
|
2700
2804
|
return {
|
|
2701
2805
|
...style,
|
|
2702
2806
|
top: mapsCore.EDGE_MARGIN,
|
|
@@ -2712,7 +2816,31 @@ var CoordinateDisplay = ({
|
|
|
2712
2816
|
};
|
|
2713
2817
|
}
|
|
2714
2818
|
return style;
|
|
2715
|
-
}, [position, style]);
|
|
2819
|
+
}, [position, style, topRightInset]);
|
|
2820
|
+
React6__namespace.useEffect(() => {
|
|
2821
|
+
if (!map || !loaded || position !== "top-right") return;
|
|
2822
|
+
const container = map.getContainer();
|
|
2823
|
+
const corner = container.querySelector(".maplibregl-ctrl-top-right");
|
|
2824
|
+
if (!corner) return;
|
|
2825
|
+
const measure = () => {
|
|
2826
|
+
const controls = [...corner.children].filter((el) => el !== controlRef.current);
|
|
2827
|
+
if (controls.length === 0) {
|
|
2828
|
+
setTopRightInset(0);
|
|
2829
|
+
return;
|
|
2830
|
+
}
|
|
2831
|
+
const left = Math.min(...controls.map((el) => el.getBoundingClientRect().left));
|
|
2832
|
+
setTopRightInset(Math.max(0, Math.round(container.getBoundingClientRect().right - left)));
|
|
2833
|
+
};
|
|
2834
|
+
measure();
|
|
2835
|
+
const resize = new ResizeObserver(measure);
|
|
2836
|
+
resize.observe(corner);
|
|
2837
|
+
const added = new MutationObserver(measure);
|
|
2838
|
+
added.observe(corner, { childList: true });
|
|
2839
|
+
return () => {
|
|
2840
|
+
resize.disconnect();
|
|
2841
|
+
added.disconnect();
|
|
2842
|
+
};
|
|
2843
|
+
}, [map, loaded, position]);
|
|
2716
2844
|
const formatCoord = React6__namespace.useCallback(
|
|
2717
2845
|
(lngLat) => {
|
|
2718
2846
|
return mapsCore.formatCoordinates(lngLat, precision, format);
|
|
@@ -3027,6 +3155,25 @@ var BasemapSwitcher = ({
|
|
|
3027
3155
|
);
|
|
3028
3156
|
};
|
|
3029
3157
|
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
3158
|
+
function applyDrawOrder(map, states) {
|
|
3159
|
+
if (typeof map.getLayersOrder !== "function") return;
|
|
3160
|
+
const desired = [];
|
|
3161
|
+
for (const state of mapsCore.getLayerStatesArray(states).reverse()) {
|
|
3162
|
+
const id = `lm-layer-${state.id}`;
|
|
3163
|
+
if (map.getLayer(id)) desired.push(id);
|
|
3164
|
+
if (map.getLayer(`${id}${mapsCore.OUTLINE_LAYER_SUFFIX}`)) desired.push(`${id}${mapsCore.OUTLINE_LAYER_SUFFIX}`);
|
|
3165
|
+
}
|
|
3166
|
+
if (desired.length < 2) return;
|
|
3167
|
+
const all = map.getLayersOrder();
|
|
3168
|
+
const managed = new Set(desired);
|
|
3169
|
+
if (all.filter((id) => managed.has(id)).join("\n") === desired.join("\n")) return;
|
|
3170
|
+
const top = Math.max(...desired.map((id) => all.indexOf(id)));
|
|
3171
|
+
const before = all.slice(top + 1).find((id) => !managed.has(id));
|
|
3172
|
+
try {
|
|
3173
|
+
for (const id of desired) map.moveLayer(id, before);
|
|
3174
|
+
} catch {
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3030
3177
|
var LayerManager = ({
|
|
3031
3178
|
layers,
|
|
3032
3179
|
apiKeys,
|
|
@@ -3121,6 +3268,18 @@ var LayerManager = ({
|
|
|
3121
3268
|
() => showCategories ? mapsCore.groupLayersByCategory(filteredLayers) : null,
|
|
3122
3269
|
[filteredLayers, showCategories]
|
|
3123
3270
|
);
|
|
3271
|
+
const { map } = useMap();
|
|
3272
|
+
const layerStatesRef = React6__namespace.useRef(layerStates);
|
|
3273
|
+
layerStatesRef.current = layerStates;
|
|
3274
|
+
React6__namespace.useEffect(() => {
|
|
3275
|
+
if (!map) return;
|
|
3276
|
+
const apply = () => applyDrawOrder(map, layerStatesRef.current);
|
|
3277
|
+
apply();
|
|
3278
|
+
map.on("styledata", apply);
|
|
3279
|
+
return () => {
|
|
3280
|
+
map.off("styledata", apply);
|
|
3281
|
+
};
|
|
3282
|
+
}, [map, layerStates]);
|
|
3124
3283
|
React6__namespace.useEffect(() => {
|
|
3125
3284
|
if (!isOpen) return;
|
|
3126
3285
|
const handleMouseDown = (e) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -74,31 +74,6 @@ interface MapComponentProps extends Omit<MapProps, 'class'> {
|
|
|
74
74
|
/** Children to render inside the map (layers, markers, etc.) */
|
|
75
75
|
children?: React.ReactNode;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Main Map component wrapping MapLibre GL
|
|
79
|
-
*
|
|
80
|
-
* @remarks
|
|
81
|
-
* **Callback Memoization**: Event callbacks (onClick, onHover, onMove, etc.) should be
|
|
82
|
-
* memoized with `useCallback` to prevent unnecessary effect re-runs. Unmemoized callbacks
|
|
83
|
-
* will cause event handlers to be detached and reattached on every render.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```tsx
|
|
87
|
-
* import { useCallback } from 'react';
|
|
88
|
-
*
|
|
89
|
-
* function MyMap() {
|
|
90
|
-
* // GOOD: Memoized callback
|
|
91
|
-
* const handleClick = useCallback((e: MapClickEventParams) => {
|
|
92
|
-
* console.log('Clicked:', e.lngLat);
|
|
93
|
-
* }, []);
|
|
94
|
-
*
|
|
95
|
-
* return <Map onClick={handleClick}>...</Map>;
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* // BAD: Inline callback (creates new function every render)
|
|
99
|
-
* <Map onClick={(e) => console.log(e)} />
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
77
|
declare const Map: React.ForwardRefExoticComponent<MapComponentProps & React.RefAttributes<HTMLDivElement>>;
|
|
103
78
|
|
|
104
79
|
/**
|
|
@@ -336,9 +311,6 @@ declare const BasemapSwitcher: React.FC<BasemapSwitcherComponentProps>;
|
|
|
336
311
|
|
|
337
312
|
interface LayerManagerComponentProps extends LayerManagerProps {
|
|
338
313
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Layer Manager control for overlay GIS layers
|
|
341
|
-
*/
|
|
342
314
|
declare const LayerManager: React.FC<LayerManagerComponentProps>;
|
|
343
315
|
|
|
344
316
|
interface CustomControlProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -74,31 +74,6 @@ interface MapComponentProps extends Omit<MapProps, 'class'> {
|
|
|
74
74
|
/** Children to render inside the map (layers, markers, etc.) */
|
|
75
75
|
children?: React.ReactNode;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Main Map component wrapping MapLibre GL
|
|
79
|
-
*
|
|
80
|
-
* @remarks
|
|
81
|
-
* **Callback Memoization**: Event callbacks (onClick, onHover, onMove, etc.) should be
|
|
82
|
-
* memoized with `useCallback` to prevent unnecessary effect re-runs. Unmemoized callbacks
|
|
83
|
-
* will cause event handlers to be detached and reattached on every render.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```tsx
|
|
87
|
-
* import { useCallback } from 'react';
|
|
88
|
-
*
|
|
89
|
-
* function MyMap() {
|
|
90
|
-
* // GOOD: Memoized callback
|
|
91
|
-
* const handleClick = useCallback((e: MapClickEventParams) => {
|
|
92
|
-
* console.log('Clicked:', e.lngLat);
|
|
93
|
-
* }, []);
|
|
94
|
-
*
|
|
95
|
-
* return <Map onClick={handleClick}>...</Map>;
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* // BAD: Inline callback (creates new function every render)
|
|
99
|
-
* <Map onClick={(e) => console.log(e)} />
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
77
|
declare const Map: React.ForwardRefExoticComponent<MapComponentProps & React.RefAttributes<HTMLDivElement>>;
|
|
103
78
|
|
|
104
79
|
/**
|
|
@@ -336,9 +311,6 @@ declare const BasemapSwitcher: React.FC<BasemapSwitcherComponentProps>;
|
|
|
336
311
|
|
|
337
312
|
interface LayerManagerComponentProps extends LayerManagerProps {
|
|
338
313
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Layer Manager control for overlay GIS layers
|
|
341
|
-
*/
|
|
342
314
|
declare const LayerManager: React.FC<LayerManagerComponentProps>;
|
|
343
315
|
|
|
344
316
|
interface CustomControlProps {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as maplibregl from 'maplibre-gl';
|
|
|
7
7
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
8
8
|
import '@classic-homes/maps-core/styles/controls.css';
|
|
9
9
|
import '@classic-homes/maps-core/styles/marker.css';
|
|
10
|
-
import { createPositioningCoordinator, generateMapDescription, warnIfWorkerUrlMissing, markerColor, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, DEFAULT_BASEMAP, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, getChangedPaintProps, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, getGridNavigationIndex, STACK_GAP, resolveDeckInterleaved, getLayerStyleForTheme, resolveLayerSourceUrl, getOutlineStyleForTheme, OUTLINE_LAYER_SUFFIX } from '@classic-homes/maps-core';
|
|
10
|
+
import { createPositioningCoordinator, generateMapDescription, warnIfWorkerUrlMissing, markerColor, applyMarkerAccessibility, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, handleMarkerKeydown, DEFAULT_BASEMAP, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, getChangedPaintProps, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, getGridNavigationIndex, STACK_GAP, resolveDeckInterleaved, getLayerStyleForTheme, resolveLayerSourceUrl, getOutlineStyleForTheme, OUTLINE_LAYER_SUFFIX } from '@classic-homes/maps-core';
|
|
11
11
|
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, DEFAULT_BASEMAP, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createHoverExpression, createInitialLayerStates, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getLayerCategories, getLayerStyleForTheme, getLayersByCategory, getSelectionStyle, groupLayersByCategory, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, resolveLayerSourceUrl, searchLayers, setLayerOpacity, toggleLayerVisibility, validateGeoJSON } from '@classic-homes/maps-core';
|
|
12
12
|
import * as ReactDOM from 'react-dom';
|
|
13
13
|
import { panToFitPopup, normalizePadding } from '@classic-homes/maps-core/utils';
|
|
@@ -295,6 +295,7 @@ function getStyleKey(style) {
|
|
|
295
295
|
if (!style) return "";
|
|
296
296
|
return typeof style === "string" ? style : JSON.stringify(style);
|
|
297
297
|
}
|
|
298
|
+
var angleDelta = (a, b) => Math.abs(((a - b) % 360 + 540) % 360 - 180);
|
|
298
299
|
var Map3 = React6.forwardRef(
|
|
299
300
|
({
|
|
300
301
|
// Base props
|
|
@@ -352,6 +353,7 @@ var Map3 = React6.forwardRef(
|
|
|
352
353
|
}, ref) => {
|
|
353
354
|
const containerRef = React6.useRef(null);
|
|
354
355
|
const mapRef = React6.useRef(null);
|
|
356
|
+
const appliedViewRef = React6.useRef(null);
|
|
355
357
|
const [mapLoaded, setMapLoaded] = React6.useState(false);
|
|
356
358
|
const [mapError, setMapError] = React6.useState(null);
|
|
357
359
|
const [initAttempt, setInitAttempt] = React6.useState(0);
|
|
@@ -456,6 +458,7 @@ var Map3 = React6.forwardRef(
|
|
|
456
458
|
} : {}
|
|
457
459
|
});
|
|
458
460
|
mapRef.current = map;
|
|
461
|
+
appliedViewRef.current = { center: [center[0], center[1]], zoom, bearing, pitch };
|
|
459
462
|
if (navigationControl) {
|
|
460
463
|
map.addControl(
|
|
461
464
|
new maplibregl.NavigationControl({
|
|
@@ -605,6 +608,32 @@ var Map3 = React6.forwardRef(
|
|
|
605
608
|
activeStyleOverrideRef.current = null;
|
|
606
609
|
}
|
|
607
610
|
}, [customStyleKey]);
|
|
611
|
+
const [centerLng, centerLat] = center;
|
|
612
|
+
React6.useEffect(() => {
|
|
613
|
+
const map = mapRef.current;
|
|
614
|
+
if (!map || !mapLoaded) return;
|
|
615
|
+
const next = { center: [centerLng, centerLat], zoom, bearing, pitch };
|
|
616
|
+
const prev = appliedViewRef.current;
|
|
617
|
+
appliedViewRef.current = next;
|
|
618
|
+
if (!prev) return;
|
|
619
|
+
const view = {};
|
|
620
|
+
const shown = map.getCenter();
|
|
621
|
+
if ((next.center[0] !== prev.center[0] || next.center[1] !== prev.center[1]) && (Math.abs(shown.lng - next.center[0]) > 1e-9 || Math.abs(shown.lat - next.center[1]) > 1e-9)) {
|
|
622
|
+
view.center = next.center;
|
|
623
|
+
}
|
|
624
|
+
if (next.zoom !== prev.zoom && Math.abs(map.getZoom() - next.zoom) > 1e-6) {
|
|
625
|
+
view.zoom = next.zoom;
|
|
626
|
+
}
|
|
627
|
+
if (next.bearing !== prev.bearing && angleDelta(map.getBearing(), next.bearing) > 1e-6) {
|
|
628
|
+
view.bearing = next.bearing;
|
|
629
|
+
}
|
|
630
|
+
if (next.pitch !== prev.pitch && Math.abs(map.getPitch() - next.pitch) > 1e-6) {
|
|
631
|
+
view.pitch = next.pitch;
|
|
632
|
+
}
|
|
633
|
+
if (Object.keys(view).length === 0) return;
|
|
634
|
+
if (animation && !prefersReducedMotion) map.easeTo(view);
|
|
635
|
+
else map.jumpTo(view);
|
|
636
|
+
}, [mapLoaded, centerLng, centerLat, zoom, bearing, pitch]);
|
|
608
637
|
React6.useEffect(() => {
|
|
609
638
|
const map = mapRef.current;
|
|
610
639
|
if (!map || !mapLoaded) return;
|
|
@@ -728,7 +757,13 @@ var Map3 = React6.forwardRef(
|
|
|
728
757
|
emptyMessage,
|
|
729
758
|
className,
|
|
730
759
|
children: /* @__PURE__ */ jsxs(MapContext.Provider, { value: contextValue, children: [
|
|
731
|
-
/* @__PURE__ */ jsx(
|
|
760
|
+
/* @__PURE__ */ jsx(
|
|
761
|
+
"div",
|
|
762
|
+
{
|
|
763
|
+
ref: containerRef,
|
|
764
|
+
style: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 }
|
|
765
|
+
}
|
|
766
|
+
),
|
|
732
767
|
mapLoaded && children && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 pointer-events-none [&>*]:pointer-events-auto", children })
|
|
733
768
|
] })
|
|
734
769
|
}
|
|
@@ -1057,6 +1092,7 @@ var Marker2 = React6.forwardRef(
|
|
|
1057
1092
|
({
|
|
1058
1093
|
id,
|
|
1059
1094
|
coordinates,
|
|
1095
|
+
label,
|
|
1060
1096
|
// Heritage Teal, as in Svelte (MapLibre's own default is a light blue)
|
|
1061
1097
|
color = markerColor,
|
|
1062
1098
|
anchor = "bottom",
|
|
@@ -1111,7 +1147,14 @@ var Marker2 = React6.forwardRef(
|
|
|
1111
1147
|
if (children && elementRef.current) {
|
|
1112
1148
|
markerOptions.element = elementRef.current;
|
|
1113
1149
|
}
|
|
1114
|
-
const marker = new maplibregl.Marker(markerOptions)
|
|
1150
|
+
const marker = new maplibregl.Marker(markerOptions);
|
|
1151
|
+
applyMarkerAccessibility(marker.getElement(), {
|
|
1152
|
+
label,
|
|
1153
|
+
clickable: Boolean(onClickRef.current),
|
|
1154
|
+
draggable,
|
|
1155
|
+
custom: Boolean(children)
|
|
1156
|
+
});
|
|
1157
|
+
marker.setLngLat(coordinates).addTo(map);
|
|
1115
1158
|
const el = marker.getElement();
|
|
1116
1159
|
applyMarkerProtection(el);
|
|
1117
1160
|
if (children && elementRef.current) {
|
|
@@ -1197,6 +1240,17 @@ var Marker2 = React6.forwardRef(
|
|
|
1197
1240
|
}
|
|
1198
1241
|
};
|
|
1199
1242
|
}, [map, loaded, mounted]);
|
|
1243
|
+
const clickable = Boolean(onClick);
|
|
1244
|
+
const custom = Boolean(children);
|
|
1245
|
+
React6.useEffect(() => {
|
|
1246
|
+
const marker = markerRef.current;
|
|
1247
|
+
if (!marker) return;
|
|
1248
|
+
const element = marker.getElement();
|
|
1249
|
+
applyMarkerAccessibility(element, { label, clickable, draggable, custom });
|
|
1250
|
+
if (!clickable) return;
|
|
1251
|
+
element.addEventListener("keydown", handleMarkerKeydown);
|
|
1252
|
+
return () => element.removeEventListener("keydown", handleMarkerKeydown);
|
|
1253
|
+
}, [label, clickable, draggable, custom, map, loaded, mounted]);
|
|
1200
1254
|
React6.useEffect(() => {
|
|
1201
1255
|
if (markerRef.current) {
|
|
1202
1256
|
markerRef.current.setLngLat(coordinates);
|
|
@@ -1302,6 +1356,9 @@ var Popup2 = React6.forwardRef(
|
|
|
1302
1356
|
onCloseRef.current = onClose;
|
|
1303
1357
|
const coordinatesRef = React6.useRef(coordinates);
|
|
1304
1358
|
coordinatesRef.current = coordinates;
|
|
1359
|
+
const closeOnClickRef = React6.useRef(closeOnClick);
|
|
1360
|
+
closeOnClickRef.current = closeOnClick;
|
|
1361
|
+
const rebuildingOpenRef = React6.useRef(false);
|
|
1305
1362
|
const containerRef = React6.useRef(null);
|
|
1306
1363
|
if (!containerRef.current && typeof document !== "undefined") {
|
|
1307
1364
|
containerRef.current = document.createElement("div");
|
|
@@ -1318,7 +1375,9 @@ var Popup2 = React6.forwardRef(
|
|
|
1318
1375
|
if (!map || !loaded || !containerRef.current) return;
|
|
1319
1376
|
const popup = new maplibregl.Popup({
|
|
1320
1377
|
closeButton,
|
|
1321
|
-
|
|
1378
|
+
// Map clicks are handled below, so a click that moves the popup to
|
|
1379
|
+
// another feature does not also close it
|
|
1380
|
+
closeOnClick: false,
|
|
1322
1381
|
closeOnMove,
|
|
1323
1382
|
anchor,
|
|
1324
1383
|
offset,
|
|
@@ -1328,33 +1387,51 @@ var Popup2 = React6.forwardRef(
|
|
|
1328
1387
|
popup.setDOMContent(containerRef.current);
|
|
1329
1388
|
popupRef.current = popup;
|
|
1330
1389
|
setPopupVersion((v) => v + 1);
|
|
1390
|
+
let silent = rebuildingOpenRef.current;
|
|
1391
|
+
rebuildingOpenRef.current = false;
|
|
1392
|
+
let tearingDown = false;
|
|
1331
1393
|
popup.on("open", () => {
|
|
1394
|
+
if (silent) {
|
|
1395
|
+
silent = false;
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1332
1398
|
onOpenRef.current?.({
|
|
1333
1399
|
type: "open",
|
|
1334
1400
|
lngLat: coordinatesRef.current
|
|
1335
1401
|
});
|
|
1336
1402
|
});
|
|
1337
1403
|
popup.on("close", () => {
|
|
1404
|
+
if (tearingDown) return;
|
|
1338
1405
|
onCloseRef.current?.({
|
|
1339
1406
|
type: "close",
|
|
1340
1407
|
lngLat: coordinatesRef.current
|
|
1341
1408
|
});
|
|
1342
1409
|
});
|
|
1343
1410
|
return () => {
|
|
1411
|
+
tearingDown = true;
|
|
1412
|
+
rebuildingOpenRef.current = popup.isOpen();
|
|
1344
1413
|
popup.remove();
|
|
1345
1414
|
popupRef.current = null;
|
|
1346
1415
|
};
|
|
1347
|
-
}, [
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1416
|
+
}, [map, loaded, closeButton, closeOnMove, anchor, offset, maxWidth, focusAfterOpen]);
|
|
1417
|
+
React6.useEffect(() => {
|
|
1418
|
+
const popup = popupRef.current;
|
|
1419
|
+
if (!map || !popup || typeof map.on !== "function") return;
|
|
1420
|
+
const keyOf = (c) => JSON.stringify(c);
|
|
1421
|
+
const onMapClick = () => {
|
|
1422
|
+
if (!closeOnClickRef.current || !popup.isOpen()) return;
|
|
1423
|
+
const before = keyOf(coordinatesRef.current);
|
|
1424
|
+
setTimeout(() => {
|
|
1425
|
+
if (popupRef.current !== popup || !popup.isOpen()) return;
|
|
1426
|
+
if (keyOf(coordinatesRef.current) !== before) return;
|
|
1427
|
+
popup.remove();
|
|
1428
|
+
}, 0);
|
|
1429
|
+
};
|
|
1430
|
+
map.on("click", onMapClick);
|
|
1431
|
+
return () => {
|
|
1432
|
+
map.off("click", onMapClick);
|
|
1433
|
+
};
|
|
1434
|
+
}, [map, popupVersion]);
|
|
1358
1435
|
React6.useEffect(() => {
|
|
1359
1436
|
if (!popupRef.current || !ref) return;
|
|
1360
1437
|
if (typeof ref === "function") {
|
|
@@ -1371,13 +1448,24 @@ var Popup2 = React6.forwardRef(
|
|
|
1371
1448
|
React6.useEffect(() => {
|
|
1372
1449
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1373
1450
|
let rafHandle;
|
|
1451
|
+
let cancelPending;
|
|
1374
1452
|
if (open) {
|
|
1375
1453
|
popupRef.current.setLngLat(coordinates);
|
|
1376
1454
|
if (!popupRef.current.isOpen()) popupRef.current.addTo(map);
|
|
1377
1455
|
if (autoPan) {
|
|
1378
1456
|
rafHandle = requestAnimationFrame(() => {
|
|
1379
|
-
|
|
1380
|
-
|
|
1457
|
+
const target = popupRef.current;
|
|
1458
|
+
if (!target) return;
|
|
1459
|
+
const pan = () => {
|
|
1460
|
+
if (popupRef.current === target && target.isOpen()) {
|
|
1461
|
+
panToFitPopup(map, target, normalizePadding(autoPanPadding));
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
if (typeof map.isMoving === "function" && map.isMoving()) {
|
|
1465
|
+
map.once("moveend", pan);
|
|
1466
|
+
cancelPending = () => map.off("moveend", pan);
|
|
1467
|
+
} else {
|
|
1468
|
+
pan();
|
|
1381
1469
|
}
|
|
1382
1470
|
});
|
|
1383
1471
|
}
|
|
@@ -1388,6 +1476,7 @@ var Popup2 = React6.forwardRef(
|
|
|
1388
1476
|
if (rafHandle !== void 0) {
|
|
1389
1477
|
cancelAnimationFrame(rafHandle);
|
|
1390
1478
|
}
|
|
1479
|
+
cancelPending?.();
|
|
1391
1480
|
};
|
|
1392
1481
|
}, [map, open, coordinates, autoPan, autoPanPadding, contentReady, popupVersion]);
|
|
1393
1482
|
if (!containerRef.current) return null;
|
|
@@ -1774,6 +1863,17 @@ function useLayer({
|
|
|
1774
1863
|
map.on("mousemove", id, handleMouseMove);
|
|
1775
1864
|
map.on("mouseleave", id, handleMouseLeave);
|
|
1776
1865
|
}
|
|
1866
|
+
const pointerOn = () => {
|
|
1867
|
+
map.getCanvas().style.cursor = "pointer";
|
|
1868
|
+
};
|
|
1869
|
+
const pointerOff = () => {
|
|
1870
|
+
map.getCanvas().style.cursor = "";
|
|
1871
|
+
};
|
|
1872
|
+
const clickOnly = Boolean(onClick) && !onHover;
|
|
1873
|
+
if (clickOnly) {
|
|
1874
|
+
map.on("mouseenter", id, pointerOn);
|
|
1875
|
+
map.on("mouseleave", id, pointerOff);
|
|
1876
|
+
}
|
|
1777
1877
|
return () => {
|
|
1778
1878
|
if (onClick) {
|
|
1779
1879
|
map.off("click", id, handleClick);
|
|
@@ -1783,6 +1883,10 @@ function useLayer({
|
|
|
1783
1883
|
map.off("mousemove", id, handleMouseMove);
|
|
1784
1884
|
map.off("mouseleave", id, handleMouseLeave);
|
|
1785
1885
|
}
|
|
1886
|
+
if (clickOnly) {
|
|
1887
|
+
map.off("mouseenter", id, pointerOn);
|
|
1888
|
+
map.off("mouseleave", id, pointerOff);
|
|
1889
|
+
}
|
|
1786
1890
|
};
|
|
1787
1891
|
}, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
|
|
1788
1892
|
return { layerAdded };
|
|
@@ -2653,7 +2757,6 @@ var LegendGroup = ({
|
|
|
2653
2757
|
);
|
|
2654
2758
|
};
|
|
2655
2759
|
LegendGroup.displayName = "LegendGroup";
|
|
2656
|
-
var NAV_CONTROL_WIDTH = 29;
|
|
2657
2760
|
var CoordinateDisplay = ({
|
|
2658
2761
|
position = "bottom-right",
|
|
2659
2762
|
format = "decimal",
|
|
@@ -2667,6 +2770,7 @@ var CoordinateDisplay = ({
|
|
|
2667
2770
|
const [currentZoom, setCurrentZoom] = React6.useState(0);
|
|
2668
2771
|
const [currentBearing, setCurrentBearing] = React6.useState(0);
|
|
2669
2772
|
const controlRef = React6.useRef(null);
|
|
2773
|
+
const [topRightInset, setTopRightInset] = React6.useState(0);
|
|
2670
2774
|
const uniqueId = React6.useId();
|
|
2671
2775
|
const controlId = `coord-display${uniqueId}`;
|
|
2672
2776
|
const { style, visible } = useControlPosition(controlRef, {
|
|
@@ -2679,7 +2783,7 @@ var CoordinateDisplay = ({
|
|
|
2679
2783
|
const adjustedStyle = React6.useMemo(() => {
|
|
2680
2784
|
if (!style) return style;
|
|
2681
2785
|
if (position === "top-right") {
|
|
2682
|
-
const rightOffset =
|
|
2786
|
+
const rightOffset = topRightInset ? topRightInset + STACK_GAP : EDGE_MARGIN;
|
|
2683
2787
|
return {
|
|
2684
2788
|
...style,
|
|
2685
2789
|
top: EDGE_MARGIN,
|
|
@@ -2695,7 +2799,31 @@ var CoordinateDisplay = ({
|
|
|
2695
2799
|
};
|
|
2696
2800
|
}
|
|
2697
2801
|
return style;
|
|
2698
|
-
}, [position, style]);
|
|
2802
|
+
}, [position, style, topRightInset]);
|
|
2803
|
+
React6.useEffect(() => {
|
|
2804
|
+
if (!map || !loaded || position !== "top-right") return;
|
|
2805
|
+
const container = map.getContainer();
|
|
2806
|
+
const corner = container.querySelector(".maplibregl-ctrl-top-right");
|
|
2807
|
+
if (!corner) return;
|
|
2808
|
+
const measure = () => {
|
|
2809
|
+
const controls = [...corner.children].filter((el) => el !== controlRef.current);
|
|
2810
|
+
if (controls.length === 0) {
|
|
2811
|
+
setTopRightInset(0);
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
const left = Math.min(...controls.map((el) => el.getBoundingClientRect().left));
|
|
2815
|
+
setTopRightInset(Math.max(0, Math.round(container.getBoundingClientRect().right - left)));
|
|
2816
|
+
};
|
|
2817
|
+
measure();
|
|
2818
|
+
const resize = new ResizeObserver(measure);
|
|
2819
|
+
resize.observe(corner);
|
|
2820
|
+
const added = new MutationObserver(measure);
|
|
2821
|
+
added.observe(corner, { childList: true });
|
|
2822
|
+
return () => {
|
|
2823
|
+
resize.disconnect();
|
|
2824
|
+
added.disconnect();
|
|
2825
|
+
};
|
|
2826
|
+
}, [map, loaded, position]);
|
|
2699
2827
|
const formatCoord = React6.useCallback(
|
|
2700
2828
|
(lngLat) => {
|
|
2701
2829
|
return formatCoordinates(lngLat, precision, format);
|
|
@@ -3010,6 +3138,25 @@ var BasemapSwitcher = ({
|
|
|
3010
3138
|
);
|
|
3011
3139
|
};
|
|
3012
3140
|
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
3141
|
+
function applyDrawOrder(map, states) {
|
|
3142
|
+
if (typeof map.getLayersOrder !== "function") return;
|
|
3143
|
+
const desired = [];
|
|
3144
|
+
for (const state of getLayerStatesArray(states).reverse()) {
|
|
3145
|
+
const id = `lm-layer-${state.id}`;
|
|
3146
|
+
if (map.getLayer(id)) desired.push(id);
|
|
3147
|
+
if (map.getLayer(`${id}${OUTLINE_LAYER_SUFFIX}`)) desired.push(`${id}${OUTLINE_LAYER_SUFFIX}`);
|
|
3148
|
+
}
|
|
3149
|
+
if (desired.length < 2) return;
|
|
3150
|
+
const all = map.getLayersOrder();
|
|
3151
|
+
const managed = new Set(desired);
|
|
3152
|
+
if (all.filter((id) => managed.has(id)).join("\n") === desired.join("\n")) return;
|
|
3153
|
+
const top = Math.max(...desired.map((id) => all.indexOf(id)));
|
|
3154
|
+
const before = all.slice(top + 1).find((id) => !managed.has(id));
|
|
3155
|
+
try {
|
|
3156
|
+
for (const id of desired) map.moveLayer(id, before);
|
|
3157
|
+
} catch {
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3013
3160
|
var LayerManager = ({
|
|
3014
3161
|
layers,
|
|
3015
3162
|
apiKeys,
|
|
@@ -3104,6 +3251,18 @@ var LayerManager = ({
|
|
|
3104
3251
|
() => showCategories ? groupLayersByCategory(filteredLayers) : null,
|
|
3105
3252
|
[filteredLayers, showCategories]
|
|
3106
3253
|
);
|
|
3254
|
+
const { map } = useMap();
|
|
3255
|
+
const layerStatesRef = React6.useRef(layerStates);
|
|
3256
|
+
layerStatesRef.current = layerStates;
|
|
3257
|
+
React6.useEffect(() => {
|
|
3258
|
+
if (!map) return;
|
|
3259
|
+
const apply = () => applyDrawOrder(map, layerStatesRef.current);
|
|
3260
|
+
apply();
|
|
3261
|
+
map.on("styledata", apply);
|
|
3262
|
+
return () => {
|
|
3263
|
+
map.off("styledata", apply);
|
|
3264
|
+
};
|
|
3265
|
+
}, [map, layerStates]);
|
|
3107
3266
|
React6.useEffect(() => {
|
|
3108
3267
|
if (!isOpen) return;
|
|
3109
3268
|
const handleMouseDown = (e) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/maps-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "React MapLibre components for Classic Theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maps",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"test": "vitest run"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@classic-homes/maps-core": "^0.
|
|
49
|
+
"@classic-homes/maps-core": "^0.9.0",
|
|
50
50
|
"@classic-homes/theme-react": "*",
|
|
51
51
|
"class-variance-authority": "^0.7.0",
|
|
52
52
|
"clsx": "^2.1.0",
|