@classic-homes/maps-react 0.1.3 → 0.1.4
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 +245 -6
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +227 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ require('@classic-homes/maps-core/styles/marker.css');
|
|
|
11
11
|
var mapsCore = require('@classic-homes/maps-core');
|
|
12
12
|
var ReactDOM = require('react-dom');
|
|
13
13
|
var classVarianceAuthority = require('class-variance-authority');
|
|
14
|
+
require('@classic-homes/maps-core/styles/basemap-switcher.css');
|
|
14
15
|
|
|
15
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
17
|
|
|
@@ -366,6 +367,14 @@ var Map = React6__namespace.forwardRef(
|
|
|
366
367
|
const mapRef = React6__namespace.useRef(null);
|
|
367
368
|
const [mapLoaded, setMapLoaded] = React6__namespace.useState(false);
|
|
368
369
|
const [mapError, setMapError] = React6__namespace.useState(null);
|
|
370
|
+
const [styleVersion, setStyleVersion] = React6__namespace.useState(0);
|
|
371
|
+
const activeStyleOverrideRef = React6__namespace.useRef(
|
|
372
|
+
null
|
|
373
|
+
);
|
|
374
|
+
const setMapStyle = React6__namespace.useCallback((style) => {
|
|
375
|
+
activeStyleOverrideRef.current = style;
|
|
376
|
+
mapRef.current?.setStyle(style);
|
|
377
|
+
}, []);
|
|
369
378
|
const customControlRegistryRef = React6__namespace.useRef({
|
|
370
379
|
"top-left": [],
|
|
371
380
|
"top-right": [],
|
|
@@ -474,6 +483,9 @@ var Map = React6__namespace.forwardRef(
|
|
|
474
483
|
attributionControl: attributionControl ? { customAttribution } : false
|
|
475
484
|
});
|
|
476
485
|
mapRef.current = map;
|
|
486
|
+
map.on("style.load", () => {
|
|
487
|
+
setStyleVersion((v) => v + 1);
|
|
488
|
+
});
|
|
477
489
|
if (navigationControl) {
|
|
478
490
|
map.addControl(
|
|
479
491
|
new maplibregl__default.default.NavigationControl({
|
|
@@ -535,8 +547,14 @@ var Map = React6__namespace.forwardRef(
|
|
|
535
547
|
styleInitialized.current = true;
|
|
536
548
|
return;
|
|
537
549
|
}
|
|
550
|
+
if (activeStyleOverrideRef.current) return;
|
|
538
551
|
mapRef.current.setStyle(mapStyle);
|
|
539
552
|
}, [mapStyle, mapLoaded]);
|
|
553
|
+
React6__namespace.useEffect(() => {
|
|
554
|
+
if (customStyle) {
|
|
555
|
+
activeStyleOverrideRef.current = null;
|
|
556
|
+
}
|
|
557
|
+
}, [customStyle]);
|
|
540
558
|
React6__namespace.useEffect(() => {
|
|
541
559
|
const map = mapRef.current;
|
|
542
560
|
if (!map || !mapLoaded) return;
|
|
@@ -657,7 +675,9 @@ var Map = React6__namespace.forwardRef(
|
|
|
657
675
|
controlOffsets,
|
|
658
676
|
registerControl,
|
|
659
677
|
unregisterControl,
|
|
660
|
-
getCustomControlOffset
|
|
678
|
+
getCustomControlOffset,
|
|
679
|
+
styleVersion,
|
|
680
|
+
setMapStyle
|
|
661
681
|
},
|
|
662
682
|
children: [
|
|
663
683
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "absolute inset-0" }),
|
|
@@ -689,7 +709,7 @@ var Source = ({
|
|
|
689
709
|
fitBoundsAnimate = true,
|
|
690
710
|
children
|
|
691
711
|
}) => {
|
|
692
|
-
const { map, loaded } = useMap();
|
|
712
|
+
const { map, loaded, styleVersion } = useMap();
|
|
693
713
|
const sourceAdded = React6__namespace.useRef(false);
|
|
694
714
|
const initialFitDone = React6__namespace.useRef(false);
|
|
695
715
|
const fitBoundsParamsRef = React6__namespace.useRef({
|
|
@@ -878,7 +898,6 @@ var Source = ({
|
|
|
878
898
|
} catch {
|
|
879
899
|
}
|
|
880
900
|
sourceAdded.current = false;
|
|
881
|
-
initialFitDone.current = false;
|
|
882
901
|
}
|
|
883
902
|
};
|
|
884
903
|
} catch (err) {
|
|
@@ -898,8 +917,10 @@ var Source = ({
|
|
|
898
917
|
clusterMaxZoom,
|
|
899
918
|
generateId,
|
|
900
919
|
promoteId,
|
|
901
|
-
performFitBounds
|
|
920
|
+
performFitBounds,
|
|
902
921
|
// stable due to using ref for params
|
|
922
|
+
styleVersion
|
|
923
|
+
// re-add source after basemap style changes
|
|
903
924
|
]);
|
|
904
925
|
React6__namespace.useEffect(() => {
|
|
905
926
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
@@ -1292,11 +1313,14 @@ function useLayer({
|
|
|
1292
1313
|
onHover,
|
|
1293
1314
|
hoverThrottleMs = 0
|
|
1294
1315
|
}) {
|
|
1295
|
-
const { map, loaded } = useMap();
|
|
1316
|
+
const { map, loaded, styleVersion } = useMap();
|
|
1296
1317
|
const [layerAdded, setLayerAdded] = React6__namespace.useState(false);
|
|
1297
1318
|
const hoveredFeatureId = React6__namespace.useRef(null);
|
|
1298
1319
|
const lastHoverCallTime = React6__namespace.useRef(0);
|
|
1299
1320
|
const lastMousePosition = React6__namespace.useRef(null);
|
|
1321
|
+
React6__namespace.useEffect(() => {
|
|
1322
|
+
hoveredFeatureId.current = null;
|
|
1323
|
+
}, [styleVersion]);
|
|
1300
1324
|
React6__namespace.useEffect(() => {
|
|
1301
1325
|
if (!map || !loaded) return;
|
|
1302
1326
|
if (!map.getSource(source)) {
|
|
@@ -1367,7 +1391,7 @@ function useLayer({
|
|
|
1367
1391
|
setLayerAdded(false);
|
|
1368
1392
|
}
|
|
1369
1393
|
};
|
|
1370
|
-
}, [map, loaded, id, source, sourceLayer, type, beforeId]);
|
|
1394
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1371
1395
|
React6__namespace.useEffect(() => {
|
|
1372
1396
|
if (!map || !layerAdded) return;
|
|
1373
1397
|
if (!map.getLayer(id)) return;
|
|
@@ -2362,6 +2386,200 @@ var CoordinateDisplay = ({
|
|
|
2362
2386
|
);
|
|
2363
2387
|
};
|
|
2364
2388
|
CoordinateDisplay.displayName = "CoordinateDisplay";
|
|
2389
|
+
var switcherIdCounter = 0;
|
|
2390
|
+
var BasemapSwitcher = ({
|
|
2391
|
+
basemaps,
|
|
2392
|
+
extraBasemaps,
|
|
2393
|
+
apiKeys,
|
|
2394
|
+
defaultBasemapId,
|
|
2395
|
+
activeBasemapId,
|
|
2396
|
+
onBasemapChange,
|
|
2397
|
+
columns = 3,
|
|
2398
|
+
thumbnailSize = 64,
|
|
2399
|
+
position = "bottom-right",
|
|
2400
|
+
class: className
|
|
2401
|
+
}) => {
|
|
2402
|
+
const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
|
|
2403
|
+
const [isOpen, setIsOpen] = React6__namespace.useState(false);
|
|
2404
|
+
const [internalActiveId, setInternalActiveId] = React6__namespace.useState(
|
|
2405
|
+
defaultBasemapId
|
|
2406
|
+
);
|
|
2407
|
+
const [customControlOffset, setCustomControlOffset] = React6__namespace.useState(0);
|
|
2408
|
+
const containerRef = React6__namespace.useRef(null);
|
|
2409
|
+
const panelRef = React6__namespace.useRef(null);
|
|
2410
|
+
const switcherIdRef = React6__namespace.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2411
|
+
const sourceBasemaps = basemaps ?? mapsCore.FREE_BASEMAPS;
|
|
2412
|
+
const availableBasemaps = React6__namespace.useMemo(() => {
|
|
2413
|
+
const available = mapsCore.getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2414
|
+
if (extraBasemaps?.length) {
|
|
2415
|
+
return [...available, ...mapsCore.getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
2416
|
+
}
|
|
2417
|
+
return available;
|
|
2418
|
+
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2419
|
+
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2420
|
+
React6__namespace.useEffect(() => {
|
|
2421
|
+
if (!containerRef.current || !registerControl) return;
|
|
2422
|
+
const updatePosition = () => {
|
|
2423
|
+
if (!containerRef.current) return;
|
|
2424
|
+
const height = containerRef.current.offsetHeight;
|
|
2425
|
+
const offset = registerControl(switcherIdRef.current, position, height);
|
|
2426
|
+
setCustomControlOffset(offset);
|
|
2427
|
+
};
|
|
2428
|
+
updatePosition();
|
|
2429
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2430
|
+
observer.observe(containerRef.current);
|
|
2431
|
+
return () => {
|
|
2432
|
+
observer.disconnect();
|
|
2433
|
+
unregisterControl?.(switcherIdRef.current, position);
|
|
2434
|
+
};
|
|
2435
|
+
}, [position, registerControl, unregisterControl]);
|
|
2436
|
+
React6__namespace.useEffect(() => {
|
|
2437
|
+
if (!isOpen) return;
|
|
2438
|
+
const handleMouseDown = (e) => {
|
|
2439
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2440
|
+
setIsOpen(false);
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
2444
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2445
|
+
}, [isOpen]);
|
|
2446
|
+
React6__namespace.useEffect(() => {
|
|
2447
|
+
if (!isOpen) return;
|
|
2448
|
+
const handleKeyDown = (e) => {
|
|
2449
|
+
if (e.key === "Escape") {
|
|
2450
|
+
setIsOpen(false);
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2454
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2455
|
+
}, [isOpen]);
|
|
2456
|
+
const handleSelect = (basemap) => {
|
|
2457
|
+
const style = mapsCore.resolveBasemapStyle(basemap, apiKeys);
|
|
2458
|
+
if (!style) return;
|
|
2459
|
+
if (!activeBasemapId) {
|
|
2460
|
+
setInternalActiveId(basemap.id);
|
|
2461
|
+
}
|
|
2462
|
+
setMapStyle?.(style);
|
|
2463
|
+
onBasemapChange?.(basemap);
|
|
2464
|
+
setIsOpen(false);
|
|
2465
|
+
};
|
|
2466
|
+
const verticalOffsetStyle = React6__namespace.useMemo(() => {
|
|
2467
|
+
return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
|
|
2468
|
+
}, [customControlOffset, position]);
|
|
2469
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2470
|
+
const computedPositionClasses = React6__namespace.useMemo(() => {
|
|
2471
|
+
return mapsCore.computePositionClasses(position, hasControlsAtPosition);
|
|
2472
|
+
}, [position, hasControlsAtPosition]);
|
|
2473
|
+
const isTop = position.startsWith("top");
|
|
2474
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2475
|
+
"div",
|
|
2476
|
+
{
|
|
2477
|
+
ref: containerRef,
|
|
2478
|
+
className: cn("absolute z-10", computedPositionClasses, className),
|
|
2479
|
+
style: verticalOffsetStyle,
|
|
2480
|
+
children: [
|
|
2481
|
+
isOpen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2482
|
+
"div",
|
|
2483
|
+
{
|
|
2484
|
+
ref: panelRef,
|
|
2485
|
+
className: cn(
|
|
2486
|
+
"absolute classic-basemap-panel-enter",
|
|
2487
|
+
"bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2488
|
+
"p-2",
|
|
2489
|
+
isTop ? "top-full mt-1" : "bottom-full mb-1",
|
|
2490
|
+
position.includes("right") ? "right-0" : "left-0"
|
|
2491
|
+
),
|
|
2492
|
+
style: {
|
|
2493
|
+
width: columns * (thumbnailSize + 12) + 16
|
|
2494
|
+
},
|
|
2495
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2496
|
+
"div",
|
|
2497
|
+
{
|
|
2498
|
+
role: "listbox",
|
|
2499
|
+
"aria-label": "Select basemap",
|
|
2500
|
+
className: "grid gap-1.5",
|
|
2501
|
+
style: {
|
|
2502
|
+
gridTemplateColumns: `repeat(${columns}, 1fr)`
|
|
2503
|
+
},
|
|
2504
|
+
children: availableBasemaps.map((basemap) => {
|
|
2505
|
+
const isActive = basemap.id === currentActiveId;
|
|
2506
|
+
const thumbUrl = mapsCore.resolveBasemapThumbnail(basemap, apiKeys);
|
|
2507
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2508
|
+
"button",
|
|
2509
|
+
{
|
|
2510
|
+
type: "button",
|
|
2511
|
+
role: "option",
|
|
2512
|
+
"aria-selected": isActive,
|
|
2513
|
+
className: cn(
|
|
2514
|
+
"flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
|
|
2515
|
+
"hover:bg-muted transition-colors",
|
|
2516
|
+
isActive && "ring-2 ring-primary"
|
|
2517
|
+
),
|
|
2518
|
+
onClick: () => handleSelect(basemap),
|
|
2519
|
+
title: basemap.name,
|
|
2520
|
+
children: [
|
|
2521
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2522
|
+
"img",
|
|
2523
|
+
{
|
|
2524
|
+
src: thumbUrl,
|
|
2525
|
+
alt: basemap.name,
|
|
2526
|
+
loading: "lazy",
|
|
2527
|
+
className: "rounded object-cover",
|
|
2528
|
+
style: {
|
|
2529
|
+
width: thumbnailSize,
|
|
2530
|
+
height: thumbnailSize
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
),
|
|
2534
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] text-foreground truncate w-full text-center leading-tight", children: basemap.label ?? basemap.name })
|
|
2535
|
+
]
|
|
2536
|
+
},
|
|
2537
|
+
basemap.id
|
|
2538
|
+
);
|
|
2539
|
+
})
|
|
2540
|
+
}
|
|
2541
|
+
)
|
|
2542
|
+
}
|
|
2543
|
+
),
|
|
2544
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2545
|
+
"button",
|
|
2546
|
+
{
|
|
2547
|
+
type: "button",
|
|
2548
|
+
className: cn(
|
|
2549
|
+
"w-[40px] h-[40px] flex items-center justify-center",
|
|
2550
|
+
"bg-card rounded shadow-lg border border-black dark:border-gray-400",
|
|
2551
|
+
"hover:bg-muted transition-colors cursor-pointer",
|
|
2552
|
+
"text-foreground"
|
|
2553
|
+
),
|
|
2554
|
+
onClick: () => setIsOpen(!isOpen),
|
|
2555
|
+
"aria-label": "Switch basemap",
|
|
2556
|
+
"aria-expanded": isOpen,
|
|
2557
|
+
"aria-haspopup": "true",
|
|
2558
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2559
|
+
"svg",
|
|
2560
|
+
{
|
|
2561
|
+
width: "20",
|
|
2562
|
+
height: "20",
|
|
2563
|
+
viewBox: "0 0 24 24",
|
|
2564
|
+
fill: "none",
|
|
2565
|
+
stroke: "currentColor",
|
|
2566
|
+
strokeWidth: "2",
|
|
2567
|
+
strokeLinecap: "round",
|
|
2568
|
+
strokeLinejoin: "round",
|
|
2569
|
+
children: [
|
|
2570
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 2L2 7l10 5 10-5-10-5z" }),
|
|
2571
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 17l10 5 10-5" }),
|
|
2572
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 12l10 5 10-5" })
|
|
2573
|
+
]
|
|
2574
|
+
}
|
|
2575
|
+
)
|
|
2576
|
+
}
|
|
2577
|
+
)
|
|
2578
|
+
]
|
|
2579
|
+
}
|
|
2580
|
+
);
|
|
2581
|
+
};
|
|
2582
|
+
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
2365
2583
|
var DeckOverlay = ({
|
|
2366
2584
|
layers = [],
|
|
2367
2585
|
onHover,
|
|
@@ -2436,6 +2654,18 @@ var DeckOverlay = ({
|
|
|
2436
2654
|
};
|
|
2437
2655
|
DeckOverlay.displayName = "DeckOverlay";
|
|
2438
2656
|
|
|
2657
|
+
Object.defineProperty(exports, "BUILTIN_BASEMAPS", {
|
|
2658
|
+
enumerable: true,
|
|
2659
|
+
get: function () { return mapsCore.BUILTIN_BASEMAPS; }
|
|
2660
|
+
});
|
|
2661
|
+
Object.defineProperty(exports, "FREE_BASEMAPS", {
|
|
2662
|
+
enumerable: true,
|
|
2663
|
+
get: function () { return mapsCore.FREE_BASEMAPS; }
|
|
2664
|
+
});
|
|
2665
|
+
Object.defineProperty(exports, "OSM_STANDARD", {
|
|
2666
|
+
enumerable: true,
|
|
2667
|
+
get: function () { return mapsCore.OSM_STANDARD; }
|
|
2668
|
+
});
|
|
2439
2669
|
Object.defineProperty(exports, "THEME_DARK", {
|
|
2440
2670
|
enumerable: true,
|
|
2441
2671
|
get: function () { return mapsCore.THEME_DARK; }
|
|
@@ -2508,6 +2738,10 @@ Object.defineProperty(exports, "generateMapDescription", {
|
|
|
2508
2738
|
enumerable: true,
|
|
2509
2739
|
get: function () { return mapsCore.generateMapDescription; }
|
|
2510
2740
|
});
|
|
2741
|
+
Object.defineProperty(exports, "getAvailableBasemaps", {
|
|
2742
|
+
enumerable: true,
|
|
2743
|
+
get: function () { return mapsCore.getAvailableBasemaps; }
|
|
2744
|
+
});
|
|
2511
2745
|
Object.defineProperty(exports, "getClusterBounds", {
|
|
2512
2746
|
enumerable: true,
|
|
2513
2747
|
get: function () { return mapsCore.getClusterBounds; }
|
|
@@ -2552,10 +2786,15 @@ Object.defineProperty(exports, "loadGeoJSON", {
|
|
|
2552
2786
|
enumerable: true,
|
|
2553
2787
|
get: function () { return mapsCore.loadGeoJSON; }
|
|
2554
2788
|
});
|
|
2789
|
+
Object.defineProperty(exports, "resolveBasemapStyle", {
|
|
2790
|
+
enumerable: true,
|
|
2791
|
+
get: function () { return mapsCore.resolveBasemapStyle; }
|
|
2792
|
+
});
|
|
2555
2793
|
Object.defineProperty(exports, "validateGeoJSON", {
|
|
2556
2794
|
enumerable: true,
|
|
2557
2795
|
get: function () { return mapsCore.validateGeoJSON; }
|
|
2558
2796
|
});
|
|
2797
|
+
exports.BasemapSwitcher = BasemapSwitcher;
|
|
2559
2798
|
exports.CircleLayer = CircleLayer;
|
|
2560
2799
|
exports.CoordinateDisplay = CoordinateDisplay;
|
|
2561
2800
|
exports.DeckOverlay = DeckOverlay;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MapProps, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
-
export { BaseMapProps, BoundsArray, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, PopupProps, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, ValidationResult, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
|
|
4
|
-
import maplibregl, { Map as Map$1 } from 'maplibre-gl';
|
|
2
|
+
import { MapProps, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
+
export { BUILTIN_BASEMAPS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, PopupProps, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, ValidationResult, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, validateGeoJSON } from '@classic-homes/maps-core';
|
|
4
|
+
import maplibregl, { Map as Map$1, StyleSpecification } from 'maplibre-gl';
|
|
5
5
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
6
6
|
import { VariantProps } from 'class-variance-authority';
|
|
7
7
|
import { ClassValue } from 'clsx';
|
|
@@ -120,6 +120,10 @@ interface MapContextValue {
|
|
|
120
120
|
unregisterControl?: (id: string, position: string) => void;
|
|
121
121
|
/** Get the vertical offset for a control */
|
|
122
122
|
getCustomControlOffset?: (id: string, position: string) => number;
|
|
123
|
+
/** Counter incremented on each style.load event, used to re-initialize sources/layers */
|
|
124
|
+
styleVersion: number;
|
|
125
|
+
/** Set the map style programmatically (e.g. basemap switching) */
|
|
126
|
+
setMapStyle?: (style: string | StyleSpecification) => void;
|
|
123
127
|
}
|
|
124
128
|
declare const MapContext: React.Context<MapContextValue | null>;
|
|
125
129
|
/**
|
|
@@ -332,6 +336,13 @@ interface CoordinateDisplayComponentProps extends CoordinateDisplayProps {
|
|
|
332
336
|
*/
|
|
333
337
|
declare const CoordinateDisplay: React.FC<CoordinateDisplayComponentProps>;
|
|
334
338
|
|
|
339
|
+
interface BasemapSwitcherComponentProps extends BasemapSwitcherProps {
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Basemap switcher control with thumbnail grid flyout
|
|
343
|
+
*/
|
|
344
|
+
declare const BasemapSwitcher: React.FC<BasemapSwitcherComponentProps>;
|
|
345
|
+
|
|
335
346
|
/**
|
|
336
347
|
* Props for the DeckOverlay component
|
|
337
348
|
*/
|
|
@@ -420,4 +431,4 @@ declare function useReducedMotion(): boolean;
|
|
|
420
431
|
*/
|
|
421
432
|
declare function cn(...inputs: ClassValue[]): string;
|
|
422
433
|
|
|
423
|
-
export { CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
|
434
|
+
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MapProps, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
-
export { BaseMapProps, BoundsArray, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, PopupProps, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, ValidationResult, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
|
|
4
|
-
import maplibregl, { Map as Map$1 } from 'maplibre-gl';
|
|
2
|
+
import { MapProps, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
+
export { BUILTIN_BASEMAPS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, PopupProps, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, ValidationResult, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, validateGeoJSON } from '@classic-homes/maps-core';
|
|
4
|
+
import maplibregl, { Map as Map$1, StyleSpecification } from 'maplibre-gl';
|
|
5
5
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
6
6
|
import { VariantProps } from 'class-variance-authority';
|
|
7
7
|
import { ClassValue } from 'clsx';
|
|
@@ -120,6 +120,10 @@ interface MapContextValue {
|
|
|
120
120
|
unregisterControl?: (id: string, position: string) => void;
|
|
121
121
|
/** Get the vertical offset for a control */
|
|
122
122
|
getCustomControlOffset?: (id: string, position: string) => number;
|
|
123
|
+
/** Counter incremented on each style.load event, used to re-initialize sources/layers */
|
|
124
|
+
styleVersion: number;
|
|
125
|
+
/** Set the map style programmatically (e.g. basemap switching) */
|
|
126
|
+
setMapStyle?: (style: string | StyleSpecification) => void;
|
|
123
127
|
}
|
|
124
128
|
declare const MapContext: React.Context<MapContextValue | null>;
|
|
125
129
|
/**
|
|
@@ -332,6 +336,13 @@ interface CoordinateDisplayComponentProps extends CoordinateDisplayProps {
|
|
|
332
336
|
*/
|
|
333
337
|
declare const CoordinateDisplay: React.FC<CoordinateDisplayComponentProps>;
|
|
334
338
|
|
|
339
|
+
interface BasemapSwitcherComponentProps extends BasemapSwitcherProps {
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Basemap switcher control with thumbnail grid flyout
|
|
343
|
+
*/
|
|
344
|
+
declare const BasemapSwitcher: React.FC<BasemapSwitcherComponentProps>;
|
|
345
|
+
|
|
335
346
|
/**
|
|
336
347
|
* Props for the DeckOverlay component
|
|
337
348
|
*/
|
|
@@ -420,4 +431,4 @@ declare function useReducedMotion(): boolean;
|
|
|
420
431
|
*/
|
|
421
432
|
declare function cn(...inputs: ClassValue[]): string;
|
|
422
433
|
|
|
423
|
-
export { CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
|
434
|
+
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,11 @@ import 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 { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates } from '@classic-homes/maps-core';
|
|
11
|
-
export { THEME_DARK, THEME_LIGHT, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
|
|
10
|
+
import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, resolveBasemapStyle } from '@classic-homes/maps-core';
|
|
11
|
+
export { BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, THEME_DARK, THEME_LIGHT, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, validateGeoJSON } from '@classic-homes/maps-core';
|
|
12
12
|
import * as ReactDOM from 'react-dom';
|
|
13
13
|
import { cva } from 'class-variance-authority';
|
|
14
|
+
import '@classic-homes/maps-core/styles/basemap-switcher.css';
|
|
14
15
|
|
|
15
16
|
// src/components/base/MapContainer.tsx
|
|
16
17
|
function cn(...inputs) {
|
|
@@ -342,6 +343,14 @@ var Map = React6.forwardRef(
|
|
|
342
343
|
const mapRef = React6.useRef(null);
|
|
343
344
|
const [mapLoaded, setMapLoaded] = React6.useState(false);
|
|
344
345
|
const [mapError, setMapError] = React6.useState(null);
|
|
346
|
+
const [styleVersion, setStyleVersion] = React6.useState(0);
|
|
347
|
+
const activeStyleOverrideRef = React6.useRef(
|
|
348
|
+
null
|
|
349
|
+
);
|
|
350
|
+
const setMapStyle = React6.useCallback((style) => {
|
|
351
|
+
activeStyleOverrideRef.current = style;
|
|
352
|
+
mapRef.current?.setStyle(style);
|
|
353
|
+
}, []);
|
|
345
354
|
const customControlRegistryRef = React6.useRef({
|
|
346
355
|
"top-left": [],
|
|
347
356
|
"top-right": [],
|
|
@@ -450,6 +459,9 @@ var Map = React6.forwardRef(
|
|
|
450
459
|
attributionControl: attributionControl ? { customAttribution } : false
|
|
451
460
|
});
|
|
452
461
|
mapRef.current = map;
|
|
462
|
+
map.on("style.load", () => {
|
|
463
|
+
setStyleVersion((v) => v + 1);
|
|
464
|
+
});
|
|
453
465
|
if (navigationControl) {
|
|
454
466
|
map.addControl(
|
|
455
467
|
new maplibregl.NavigationControl({
|
|
@@ -511,8 +523,14 @@ var Map = React6.forwardRef(
|
|
|
511
523
|
styleInitialized.current = true;
|
|
512
524
|
return;
|
|
513
525
|
}
|
|
526
|
+
if (activeStyleOverrideRef.current) return;
|
|
514
527
|
mapRef.current.setStyle(mapStyle);
|
|
515
528
|
}, [mapStyle, mapLoaded]);
|
|
529
|
+
React6.useEffect(() => {
|
|
530
|
+
if (customStyle) {
|
|
531
|
+
activeStyleOverrideRef.current = null;
|
|
532
|
+
}
|
|
533
|
+
}, [customStyle]);
|
|
516
534
|
React6.useEffect(() => {
|
|
517
535
|
const map = mapRef.current;
|
|
518
536
|
if (!map || !mapLoaded) return;
|
|
@@ -633,7 +651,9 @@ var Map = React6.forwardRef(
|
|
|
633
651
|
controlOffsets,
|
|
634
652
|
registerControl,
|
|
635
653
|
unregisterControl,
|
|
636
|
-
getCustomControlOffset
|
|
654
|
+
getCustomControlOffset,
|
|
655
|
+
styleVersion,
|
|
656
|
+
setMapStyle
|
|
637
657
|
},
|
|
638
658
|
children: [
|
|
639
659
|
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "absolute inset-0" }),
|
|
@@ -665,7 +685,7 @@ var Source = ({
|
|
|
665
685
|
fitBoundsAnimate = true,
|
|
666
686
|
children
|
|
667
687
|
}) => {
|
|
668
|
-
const { map, loaded } = useMap();
|
|
688
|
+
const { map, loaded, styleVersion } = useMap();
|
|
669
689
|
const sourceAdded = React6.useRef(false);
|
|
670
690
|
const initialFitDone = React6.useRef(false);
|
|
671
691
|
const fitBoundsParamsRef = React6.useRef({
|
|
@@ -854,7 +874,6 @@ var Source = ({
|
|
|
854
874
|
} catch {
|
|
855
875
|
}
|
|
856
876
|
sourceAdded.current = false;
|
|
857
|
-
initialFitDone.current = false;
|
|
858
877
|
}
|
|
859
878
|
};
|
|
860
879
|
} catch (err) {
|
|
@@ -874,8 +893,10 @@ var Source = ({
|
|
|
874
893
|
clusterMaxZoom,
|
|
875
894
|
generateId,
|
|
876
895
|
promoteId,
|
|
877
|
-
performFitBounds
|
|
896
|
+
performFitBounds,
|
|
878
897
|
// stable due to using ref for params
|
|
898
|
+
styleVersion
|
|
899
|
+
// re-add source after basemap style changes
|
|
879
900
|
]);
|
|
880
901
|
React6.useEffect(() => {
|
|
881
902
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
@@ -1268,11 +1289,14 @@ function useLayer({
|
|
|
1268
1289
|
onHover,
|
|
1269
1290
|
hoverThrottleMs = 0
|
|
1270
1291
|
}) {
|
|
1271
|
-
const { map, loaded } = useMap();
|
|
1292
|
+
const { map, loaded, styleVersion } = useMap();
|
|
1272
1293
|
const [layerAdded, setLayerAdded] = React6.useState(false);
|
|
1273
1294
|
const hoveredFeatureId = React6.useRef(null);
|
|
1274
1295
|
const lastHoverCallTime = React6.useRef(0);
|
|
1275
1296
|
const lastMousePosition = React6.useRef(null);
|
|
1297
|
+
React6.useEffect(() => {
|
|
1298
|
+
hoveredFeatureId.current = null;
|
|
1299
|
+
}, [styleVersion]);
|
|
1276
1300
|
React6.useEffect(() => {
|
|
1277
1301
|
if (!map || !loaded) return;
|
|
1278
1302
|
if (!map.getSource(source)) {
|
|
@@ -1343,7 +1367,7 @@ function useLayer({
|
|
|
1343
1367
|
setLayerAdded(false);
|
|
1344
1368
|
}
|
|
1345
1369
|
};
|
|
1346
|
-
}, [map, loaded, id, source, sourceLayer, type, beforeId]);
|
|
1370
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1347
1371
|
React6.useEffect(() => {
|
|
1348
1372
|
if (!map || !layerAdded) return;
|
|
1349
1373
|
if (!map.getLayer(id)) return;
|
|
@@ -2338,6 +2362,200 @@ var CoordinateDisplay = ({
|
|
|
2338
2362
|
);
|
|
2339
2363
|
};
|
|
2340
2364
|
CoordinateDisplay.displayName = "CoordinateDisplay";
|
|
2365
|
+
var switcherIdCounter = 0;
|
|
2366
|
+
var BasemapSwitcher = ({
|
|
2367
|
+
basemaps,
|
|
2368
|
+
extraBasemaps,
|
|
2369
|
+
apiKeys,
|
|
2370
|
+
defaultBasemapId,
|
|
2371
|
+
activeBasemapId,
|
|
2372
|
+
onBasemapChange,
|
|
2373
|
+
columns = 3,
|
|
2374
|
+
thumbnailSize = 64,
|
|
2375
|
+
position = "bottom-right",
|
|
2376
|
+
class: className
|
|
2377
|
+
}) => {
|
|
2378
|
+
const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
|
|
2379
|
+
const [isOpen, setIsOpen] = React6.useState(false);
|
|
2380
|
+
const [internalActiveId, setInternalActiveId] = React6.useState(
|
|
2381
|
+
defaultBasemapId
|
|
2382
|
+
);
|
|
2383
|
+
const [customControlOffset, setCustomControlOffset] = React6.useState(0);
|
|
2384
|
+
const containerRef = React6.useRef(null);
|
|
2385
|
+
const panelRef = React6.useRef(null);
|
|
2386
|
+
const switcherIdRef = React6.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2387
|
+
const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
|
|
2388
|
+
const availableBasemaps = React6.useMemo(() => {
|
|
2389
|
+
const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2390
|
+
if (extraBasemaps?.length) {
|
|
2391
|
+
return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
2392
|
+
}
|
|
2393
|
+
return available;
|
|
2394
|
+
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2395
|
+
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2396
|
+
React6.useEffect(() => {
|
|
2397
|
+
if (!containerRef.current || !registerControl) return;
|
|
2398
|
+
const updatePosition = () => {
|
|
2399
|
+
if (!containerRef.current) return;
|
|
2400
|
+
const height = containerRef.current.offsetHeight;
|
|
2401
|
+
const offset = registerControl(switcherIdRef.current, position, height);
|
|
2402
|
+
setCustomControlOffset(offset);
|
|
2403
|
+
};
|
|
2404
|
+
updatePosition();
|
|
2405
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2406
|
+
observer.observe(containerRef.current);
|
|
2407
|
+
return () => {
|
|
2408
|
+
observer.disconnect();
|
|
2409
|
+
unregisterControl?.(switcherIdRef.current, position);
|
|
2410
|
+
};
|
|
2411
|
+
}, [position, registerControl, unregisterControl]);
|
|
2412
|
+
React6.useEffect(() => {
|
|
2413
|
+
if (!isOpen) return;
|
|
2414
|
+
const handleMouseDown = (e) => {
|
|
2415
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2416
|
+
setIsOpen(false);
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
2420
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2421
|
+
}, [isOpen]);
|
|
2422
|
+
React6.useEffect(() => {
|
|
2423
|
+
if (!isOpen) return;
|
|
2424
|
+
const handleKeyDown = (e) => {
|
|
2425
|
+
if (e.key === "Escape") {
|
|
2426
|
+
setIsOpen(false);
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2430
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2431
|
+
}, [isOpen]);
|
|
2432
|
+
const handleSelect = (basemap) => {
|
|
2433
|
+
const style = resolveBasemapStyle(basemap, apiKeys);
|
|
2434
|
+
if (!style) return;
|
|
2435
|
+
if (!activeBasemapId) {
|
|
2436
|
+
setInternalActiveId(basemap.id);
|
|
2437
|
+
}
|
|
2438
|
+
setMapStyle?.(style);
|
|
2439
|
+
onBasemapChange?.(basemap);
|
|
2440
|
+
setIsOpen(false);
|
|
2441
|
+
};
|
|
2442
|
+
const verticalOffsetStyle = React6.useMemo(() => {
|
|
2443
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2444
|
+
}, [customControlOffset, position]);
|
|
2445
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2446
|
+
const computedPositionClasses = React6.useMemo(() => {
|
|
2447
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
2448
|
+
}, [position, hasControlsAtPosition]);
|
|
2449
|
+
const isTop = position.startsWith("top");
|
|
2450
|
+
return /* @__PURE__ */ jsxs(
|
|
2451
|
+
"div",
|
|
2452
|
+
{
|
|
2453
|
+
ref: containerRef,
|
|
2454
|
+
className: cn("absolute z-10", computedPositionClasses, className),
|
|
2455
|
+
style: verticalOffsetStyle,
|
|
2456
|
+
children: [
|
|
2457
|
+
isOpen && /* @__PURE__ */ jsx(
|
|
2458
|
+
"div",
|
|
2459
|
+
{
|
|
2460
|
+
ref: panelRef,
|
|
2461
|
+
className: cn(
|
|
2462
|
+
"absolute classic-basemap-panel-enter",
|
|
2463
|
+
"bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2464
|
+
"p-2",
|
|
2465
|
+
isTop ? "top-full mt-1" : "bottom-full mb-1",
|
|
2466
|
+
position.includes("right") ? "right-0" : "left-0"
|
|
2467
|
+
),
|
|
2468
|
+
style: {
|
|
2469
|
+
width: columns * (thumbnailSize + 12) + 16
|
|
2470
|
+
},
|
|
2471
|
+
children: /* @__PURE__ */ jsx(
|
|
2472
|
+
"div",
|
|
2473
|
+
{
|
|
2474
|
+
role: "listbox",
|
|
2475
|
+
"aria-label": "Select basemap",
|
|
2476
|
+
className: "grid gap-1.5",
|
|
2477
|
+
style: {
|
|
2478
|
+
gridTemplateColumns: `repeat(${columns}, 1fr)`
|
|
2479
|
+
},
|
|
2480
|
+
children: availableBasemaps.map((basemap) => {
|
|
2481
|
+
const isActive = basemap.id === currentActiveId;
|
|
2482
|
+
const thumbUrl = resolveBasemapThumbnail(basemap, apiKeys);
|
|
2483
|
+
return /* @__PURE__ */ jsxs(
|
|
2484
|
+
"button",
|
|
2485
|
+
{
|
|
2486
|
+
type: "button",
|
|
2487
|
+
role: "option",
|
|
2488
|
+
"aria-selected": isActive,
|
|
2489
|
+
className: cn(
|
|
2490
|
+
"flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
|
|
2491
|
+
"hover:bg-muted transition-colors",
|
|
2492
|
+
isActive && "ring-2 ring-primary"
|
|
2493
|
+
),
|
|
2494
|
+
onClick: () => handleSelect(basemap),
|
|
2495
|
+
title: basemap.name,
|
|
2496
|
+
children: [
|
|
2497
|
+
/* @__PURE__ */ jsx(
|
|
2498
|
+
"img",
|
|
2499
|
+
{
|
|
2500
|
+
src: thumbUrl,
|
|
2501
|
+
alt: basemap.name,
|
|
2502
|
+
loading: "lazy",
|
|
2503
|
+
className: "rounded object-cover",
|
|
2504
|
+
style: {
|
|
2505
|
+
width: thumbnailSize,
|
|
2506
|
+
height: thumbnailSize
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
),
|
|
2510
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-foreground truncate w-full text-center leading-tight", children: basemap.label ?? basemap.name })
|
|
2511
|
+
]
|
|
2512
|
+
},
|
|
2513
|
+
basemap.id
|
|
2514
|
+
);
|
|
2515
|
+
})
|
|
2516
|
+
}
|
|
2517
|
+
)
|
|
2518
|
+
}
|
|
2519
|
+
),
|
|
2520
|
+
/* @__PURE__ */ jsx(
|
|
2521
|
+
"button",
|
|
2522
|
+
{
|
|
2523
|
+
type: "button",
|
|
2524
|
+
className: cn(
|
|
2525
|
+
"w-[40px] h-[40px] flex items-center justify-center",
|
|
2526
|
+
"bg-card rounded shadow-lg border border-black dark:border-gray-400",
|
|
2527
|
+
"hover:bg-muted transition-colors cursor-pointer",
|
|
2528
|
+
"text-foreground"
|
|
2529
|
+
),
|
|
2530
|
+
onClick: () => setIsOpen(!isOpen),
|
|
2531
|
+
"aria-label": "Switch basemap",
|
|
2532
|
+
"aria-expanded": isOpen,
|
|
2533
|
+
"aria-haspopup": "true",
|
|
2534
|
+
children: /* @__PURE__ */ jsxs(
|
|
2535
|
+
"svg",
|
|
2536
|
+
{
|
|
2537
|
+
width: "20",
|
|
2538
|
+
height: "20",
|
|
2539
|
+
viewBox: "0 0 24 24",
|
|
2540
|
+
fill: "none",
|
|
2541
|
+
stroke: "currentColor",
|
|
2542
|
+
strokeWidth: "2",
|
|
2543
|
+
strokeLinecap: "round",
|
|
2544
|
+
strokeLinejoin: "round",
|
|
2545
|
+
children: [
|
|
2546
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2L2 7l10 5 10-5-10-5z" }),
|
|
2547
|
+
/* @__PURE__ */ jsx("path", { d: "M2 17l10 5 10-5" }),
|
|
2548
|
+
/* @__PURE__ */ jsx("path", { d: "M2 12l10 5 10-5" })
|
|
2549
|
+
]
|
|
2550
|
+
}
|
|
2551
|
+
)
|
|
2552
|
+
}
|
|
2553
|
+
)
|
|
2554
|
+
]
|
|
2555
|
+
}
|
|
2556
|
+
);
|
|
2557
|
+
};
|
|
2558
|
+
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
2341
2559
|
var DeckOverlay = ({
|
|
2342
2560
|
layers = [],
|
|
2343
2561
|
onHover,
|
|
@@ -2412,4 +2630,4 @@ var DeckOverlay = ({
|
|
|
2412
2630
|
};
|
|
2413
2631
|
DeckOverlay.displayName = "DeckOverlay";
|
|
2414
2632
|
|
|
2415
|
-
export { CircleLayer, CoordinateDisplay, DeckOverlay, FillExtrusionLayer, FillLayer, HeatmapLayer, Legend, LegendGroup, LineLayer, Map, MapContainer, MapContext, MapEmpty, MapError, MapSkeleton, Marker, Popup, PopupCard, PopupContent, PopupFooter, PopupHeader, Source, SymbolLayer, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
|
2633
|
+
export { BasemapSwitcher, CircleLayer, CoordinateDisplay, DeckOverlay, FillExtrusionLayer, FillLayer, HeatmapLayer, Legend, LegendGroup, LineLayer, Map, MapContainer, MapContext, MapEmpty, MapError, MapSkeleton, Marker, Popup, PopupCard, PopupContent, PopupFooter, PopupHeader, Source, SymbolLayer, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|