@octostar/map-component 0.2.22 → 0.3.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 +241 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +241 -156
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/drawing-toolbar.d.ts +4 -6
- package/dist/types/components/drawing-toolbar.d.ts.map +1 -1
- package/dist/types/components/layers-panel.d.ts +1 -1
- package/dist/types/components/layers-panel.d.ts.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/basemap-list.d.ts +15 -6
- package/dist/types/lib/basemap-list.d.ts.map +1 -1
- package/dist/types/lib/map-editor-api.d.ts +80 -47
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/dist/types/lib/map-endpoints.d.ts +71 -0
- package/dist/types/lib/map-endpoints.d.ts.map +1 -0
- package/package.json +1 -1
- package/vite-plugin.d.mts +2 -0
- package/vite-plugin.mjs +42 -8
package/dist/index.cjs
CHANGED
|
@@ -2657,6 +2657,148 @@ function useToast() {
|
|
|
2657
2657
|
};
|
|
2658
2658
|
return { toast };
|
|
2659
2659
|
}
|
|
2660
|
+
const DEFAULT_ENDPOINTS = {
|
|
2661
|
+
streetsStyle: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
|
|
2662
|
+
darkStyle: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",
|
|
2663
|
+
satelliteTiles: ["https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"],
|
|
2664
|
+
satelliteAttribution: "Esri, Maxar, Earthstar Geographics",
|
|
2665
|
+
terrainTiles: ["https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"],
|
|
2666
|
+
geocodingUrl: "https://nominatim.openstreetmap.org/search",
|
|
2667
|
+
glyphsUrl: "/fonts/{fontstack}/{range}.pbf"
|
|
2668
|
+
};
|
|
2669
|
+
const BUILT_IN_NAMES = {
|
|
2670
|
+
streets: "Streets",
|
|
2671
|
+
satellite: "Satellite",
|
|
2672
|
+
dark: "Dark"
|
|
2673
|
+
};
|
|
2674
|
+
const isOff = (value) => value === false || value === null;
|
|
2675
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
2676
|
+
const nonEmptyTiles = (tiles) => Array.isArray(tiles) ? tiles.filter((tile) => nonEmpty(tile) !== void 0) : [];
|
|
2677
|
+
function resolveVectorStyle(endpoint, defaultStyle) {
|
|
2678
|
+
if (isOff(endpoint)) return null;
|
|
2679
|
+
if (endpoint === void 0) return { style: defaultStyle };
|
|
2680
|
+
const style = nonEmpty(endpoint.style);
|
|
2681
|
+
return style ? { style, name: endpoint.name } : null;
|
|
2682
|
+
}
|
|
2683
|
+
function resolveGeocoder(endpoint) {
|
|
2684
|
+
if (isOff(endpoint)) return null;
|
|
2685
|
+
if (endpoint === void 0) return { url: DEFAULT_ENDPOINTS.geocodingUrl };
|
|
2686
|
+
if ("provider" in endpoint) return typeof endpoint.provider === "function" ? { provider: endpoint.provider } : null;
|
|
2687
|
+
const url = nonEmpty(endpoint.url);
|
|
2688
|
+
return url ? { url } : null;
|
|
2689
|
+
}
|
|
2690
|
+
function resolveEndpoints(endpoints) {
|
|
2691
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2692
|
+
const e = endpoints ?? {};
|
|
2693
|
+
const streets = resolveVectorStyle(e.streets, DEFAULT_ENDPOINTS.streetsStyle);
|
|
2694
|
+
const dark = resolveVectorStyle(e.dark, DEFAULT_ENDPOINTS.darkStyle);
|
|
2695
|
+
let satellite = null;
|
|
2696
|
+
let satelliteName;
|
|
2697
|
+
if (!isOff(e.satellite)) {
|
|
2698
|
+
const tiles = e.satellite === void 0 ? [...DEFAULT_ENDPOINTS.satelliteTiles] : nonEmptyTiles(e.satellite.tiles);
|
|
2699
|
+
if (tiles.length > 0) {
|
|
2700
|
+
satellite = {
|
|
2701
|
+
tiles,
|
|
2702
|
+
tileSize: ((_a = e.satellite) == null ? void 0 : _a.tileSize) ?? 256,
|
|
2703
|
+
minzoom: ((_b = e.satellite) == null ? void 0 : _b.minzoom) ?? 0,
|
|
2704
|
+
maxzoom: ((_c = e.satellite) == null ? void 0 : _c.maxzoom) ?? 22,
|
|
2705
|
+
attribution: e.satellite === void 0 ? DEFAULT_ENDPOINTS.satelliteAttribution : e.satellite.attribution ?? ""
|
|
2706
|
+
};
|
|
2707
|
+
satelliteName = (_d = e.satellite) == null ? void 0 : _d.name;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
let terrain = null;
|
|
2711
|
+
if (!isOff(e.terrain)) {
|
|
2712
|
+
const tiles = e.terrain === void 0 ? [...DEFAULT_ENDPOINTS.terrainTiles] : nonEmptyTiles(e.terrain.tiles);
|
|
2713
|
+
if (tiles.length > 0) {
|
|
2714
|
+
terrain = {
|
|
2715
|
+
tiles,
|
|
2716
|
+
encoding: ((_e = e.terrain) == null ? void 0 : _e.encoding) ?? "terrarium",
|
|
2717
|
+
tileSize: ((_f = e.terrain) == null ? void 0 : _f.tileSize) ?? 256,
|
|
2718
|
+
minzoom: ((_g = e.terrain) == null ? void 0 : _g.minzoom) ?? 0,
|
|
2719
|
+
maxzoom: ((_h = e.terrain) == null ? void 0 : _h.maxzoom) ?? 15,
|
|
2720
|
+
attribution: ((_i = e.terrain) == null ? void 0 : _i.attribution) ?? ""
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
const glyphs = e.glyphs;
|
|
2725
|
+
const adoptStyleGlyphs = glyphs === "from-style";
|
|
2726
|
+
const glyphsUrl = typeof glyphs === "object" && glyphs !== null && nonEmpty(glyphs.url) || DEFAULT_ENDPOINTS.glyphsUrl;
|
|
2727
|
+
const builtInBasemaps = [];
|
|
2728
|
+
if (streets) builtInBasemaps.push({ id: "streets", name: streets.name ?? BUILT_IN_NAMES.streets });
|
|
2729
|
+
if (satellite) builtInBasemaps.push({ id: "satellite", name: satelliteName ?? BUILT_IN_NAMES.satellite });
|
|
2730
|
+
if (dark) builtInBasemaps.push({ id: "dark", name: dark.name ?? BUILT_IN_NAMES.dark });
|
|
2731
|
+
return {
|
|
2732
|
+
vectorStyles: {
|
|
2733
|
+
...streets ? { streets: streets.style } : {},
|
|
2734
|
+
...dark ? { dark: dark.style } : {}
|
|
2735
|
+
},
|
|
2736
|
+
satellite,
|
|
2737
|
+
terrain,
|
|
2738
|
+
glyphsUrl,
|
|
2739
|
+
adoptStyleGlyphs,
|
|
2740
|
+
builtInBasemaps
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2743
|
+
function builtInStyleUrl(resolved, id) {
|
|
2744
|
+
if (id === "streets") return resolved.vectorStyles.streets;
|
|
2745
|
+
if (id === "dark") return resolved.vectorStyles.dark;
|
|
2746
|
+
return void 0;
|
|
2747
|
+
}
|
|
2748
|
+
function isBuiltInBasemapEnabled(resolved, id) {
|
|
2749
|
+
return resolved.builtInBasemaps.some((basemap) => basemap.id === id);
|
|
2750
|
+
}
|
|
2751
|
+
const BUILT_IN_IDS = ["streets", "satellite", "dark"];
|
|
2752
|
+
function initialBasemapId(resolved, requested) {
|
|
2753
|
+
var _a;
|
|
2754
|
+
if (!BUILT_IN_IDS.includes(requested) || isBuiltInBasemapEnabled(resolved, requested)) return requested;
|
|
2755
|
+
return ((_a = resolved.builtInBasemaps[0]) == null ? void 0 : _a.id) ?? requested;
|
|
2756
|
+
}
|
|
2757
|
+
function createBaseStyle(resolved) {
|
|
2758
|
+
const sources = {};
|
|
2759
|
+
const layers = [
|
|
2760
|
+
{ id: "background", type: "background", paint: { "background-color": "#f0f0f0" } }
|
|
2761
|
+
];
|
|
2762
|
+
if (resolved.satellite) {
|
|
2763
|
+
sources["satellite-tiles"] = {
|
|
2764
|
+
type: "raster",
|
|
2765
|
+
tiles: resolved.satellite.tiles,
|
|
2766
|
+
tileSize: resolved.satellite.tileSize,
|
|
2767
|
+
minzoom: resolved.satellite.minzoom,
|
|
2768
|
+
maxzoom: resolved.satellite.maxzoom,
|
|
2769
|
+
attribution: resolved.satellite.attribution
|
|
2770
|
+
};
|
|
2771
|
+
layers.push({
|
|
2772
|
+
id: "satellite-layer",
|
|
2773
|
+
type: "raster",
|
|
2774
|
+
source: "satellite-tiles",
|
|
2775
|
+
minzoom: 0,
|
|
2776
|
+
maxzoom: 22,
|
|
2777
|
+
layout: { visibility: "none" }
|
|
2778
|
+
});
|
|
2779
|
+
}
|
|
2780
|
+
if (resolved.terrain) {
|
|
2781
|
+
sources["terrain-dem"] = {
|
|
2782
|
+
type: "raster-dem",
|
|
2783
|
+
tiles: resolved.terrain.tiles,
|
|
2784
|
+
tileSize: resolved.terrain.tileSize,
|
|
2785
|
+
minzoom: resolved.terrain.minzoom,
|
|
2786
|
+
maxzoom: resolved.terrain.maxzoom,
|
|
2787
|
+
encoding: resolved.terrain.encoding,
|
|
2788
|
+
attribution: resolved.terrain.attribution
|
|
2789
|
+
};
|
|
2790
|
+
}
|
|
2791
|
+
return { version: 8, sources, layers, glyphs: resolved.glyphsUrl };
|
|
2792
|
+
}
|
|
2793
|
+
async function geocodeAddress(geocoder, query, fetchImpl = fetch) {
|
|
2794
|
+
if ("provider" in geocoder) return geocoder.provider(query);
|
|
2795
|
+
const response = await fetchImpl(`${geocoder.url}?format=json&q=${encodeURIComponent(query)}&limit=1`);
|
|
2796
|
+
if (!response.ok) throw new Error("Search failed");
|
|
2797
|
+
const results = await response.json();
|
|
2798
|
+
if (!Array.isArray(results) || results.length === 0) return null;
|
|
2799
|
+
const { lon, lat, display_name } = results[0];
|
|
2800
|
+
return { lon: parseFloat(lon), lat: parseFloat(lat), displayName: display_name };
|
|
2801
|
+
}
|
|
2660
2802
|
function ToolButton({ mode, activeMode, onModeChange, icon, label, shortcut, disabled, showShortcutHint = true }) {
|
|
2661
2803
|
const isActive = activeMode === mode;
|
|
2662
2804
|
const handleClick = () => {
|
|
@@ -2734,8 +2876,7 @@ function DrawingToolbar({
|
|
|
2734
2876
|
onClearFilter,
|
|
2735
2877
|
onFilterActiveChange,
|
|
2736
2878
|
onSearchEngineRequest,
|
|
2737
|
-
|
|
2738
|
-
geocoderProvider,
|
|
2879
|
+
geocoder,
|
|
2739
2880
|
showShortcutHints = true,
|
|
2740
2881
|
expandSelectionTools = false,
|
|
2741
2882
|
showFilterTool = false,
|
|
@@ -2749,6 +2890,7 @@ function DrawingToolbar({
|
|
|
2749
2890
|
const [goToLng, setGoToLng] = react.useState("");
|
|
2750
2891
|
const [goToAddress, setGoToAddress] = react.useState("");
|
|
2751
2892
|
const [isSearching, setIsSearching] = react.useState(false);
|
|
2893
|
+
const resolvedGeocoder = react.useMemo(() => resolveGeocoder(geocoder), [geocoder]);
|
|
2752
2894
|
const [filterActive, setFilterActive] = react.useState(false);
|
|
2753
2895
|
const [isCompact, setIsCompact] = react.useState(false);
|
|
2754
2896
|
const [featureSearchOpen, setFeatureSearchOpen] = react.useState(false);
|
|
@@ -2881,27 +3023,10 @@ function DrawingToolbar({
|
|
|
2881
3023
|
setGoToLng("");
|
|
2882
3024
|
};
|
|
2883
3025
|
const handleAddressSearch = async () => {
|
|
2884
|
-
if (!goToAddress.trim()) return;
|
|
3026
|
+
if (!resolvedGeocoder || !goToAddress.trim()) return;
|
|
2885
3027
|
setIsSearching(true);
|
|
2886
3028
|
try {
|
|
2887
|
-
|
|
2888
|
-
if (geocoderProvider) {
|
|
2889
|
-
result = await geocoderProvider(goToAddress.trim());
|
|
2890
|
-
} else {
|
|
2891
|
-
const response = await fetch(
|
|
2892
|
-
`${geocodingUrl}?format=json&q=${encodeURIComponent(goToAddress)}&limit=1`
|
|
2893
|
-
);
|
|
2894
|
-
if (!response.ok) throw new Error("Search failed");
|
|
2895
|
-
const results = await response.json();
|
|
2896
|
-
if (results.length > 0) {
|
|
2897
|
-
const { lon, lat, display_name } = results[0];
|
|
2898
|
-
result = {
|
|
2899
|
-
lon: parseFloat(lon),
|
|
2900
|
-
lat: parseFloat(lat),
|
|
2901
|
-
displayName: display_name
|
|
2902
|
-
};
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
3029
|
+
const result = await geocodeAddress(resolvedGeocoder, goToAddress.trim());
|
|
2905
3030
|
if (!result) {
|
|
2906
3031
|
toast({
|
|
2907
3032
|
title: "Location not found",
|
|
@@ -3672,41 +3797,43 @@ function DrawingToolbar({
|
|
|
3672
3797
|
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Navigation, { className: "w-3 h-3 text-muted-foreground" }),
|
|
3673
3798
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Navigate To" })
|
|
3674
3799
|
] }),
|
|
3675
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3676
|
-
/* @__PURE__ */ jsxRuntime.
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
/* @__PURE__ */ jsxRuntime.
|
|
3708
|
-
|
|
3709
|
-
|
|
3800
|
+
resolvedGeocoder && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3801
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
3802
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3803
|
+
antd.Input,
|
|
3804
|
+
{
|
|
3805
|
+
placeholder: "Search address...",
|
|
3806
|
+
value: goToAddress,
|
|
3807
|
+
onChange: (e) => setGoToAddress(e.target.value),
|
|
3808
|
+
onKeyDown: (e) => {
|
|
3809
|
+
if (e.key === "Enter") handleAddressSearch();
|
|
3810
|
+
},
|
|
3811
|
+
disabled: isSearching,
|
|
3812
|
+
size: "small",
|
|
3813
|
+
prefix: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { className: "w-3.5 h-3.5 opacity-50" }),
|
|
3814
|
+
allowClear: true,
|
|
3815
|
+
"data-testid": "input-goto-address"
|
|
3816
|
+
}
|
|
3817
|
+
),
|
|
3818
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3819
|
+
antd.Button,
|
|
3820
|
+
{
|
|
3821
|
+
type: "primary",
|
|
3822
|
+
size: "small",
|
|
3823
|
+
onClick: handleAddressSearch,
|
|
3824
|
+
disabled: isSearching || !goToAddress.trim(),
|
|
3825
|
+
className: "shrink-0",
|
|
3826
|
+
"data-testid": "button-search-address",
|
|
3827
|
+
icon: isSearching ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }) : void 0,
|
|
3828
|
+
children: isSearching ? "" : "Go"
|
|
3829
|
+
}
|
|
3830
|
+
)
|
|
3831
|
+
] }),
|
|
3832
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3833
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 h-px bg-border" }),
|
|
3834
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] text-muted-foreground shrink-0", children: "or coordinates" }),
|
|
3835
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 h-px bg-border" })
|
|
3836
|
+
] })
|
|
3710
3837
|
] }),
|
|
3711
3838
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 items-end", children: [
|
|
3712
3839
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
@@ -3767,16 +3894,21 @@ function DrawingToolbar({
|
|
|
3767
3894
|
);
|
|
3768
3895
|
}
|
|
3769
3896
|
const BUILT_IN_BASEMAP_IDS = ["streets", "satellite", "dark"];
|
|
3770
|
-
const
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3897
|
+
const isBuiltInId = (id) => BUILT_IN_BASEMAP_IDS.includes(id);
|
|
3898
|
+
function customBasemapsWithoutBuiltIns(customBasemaps) {
|
|
3899
|
+
if (!customBasemaps) return void 0;
|
|
3900
|
+
const ignored = Object.keys(customBasemaps).filter(isBuiltInId);
|
|
3901
|
+
if (ignored.length === 0) return customBasemaps;
|
|
3902
|
+
console.warn(
|
|
3903
|
+
`[map-component] customBasemaps entries for built-in ids are ignored (${ignored.join(", ")}); configure them through the endpoints prop.`
|
|
3904
|
+
);
|
|
3905
|
+
return Object.fromEntries(Object.entries(customBasemaps).filter(([id]) => !isBuiltInId(id)));
|
|
3906
|
+
}
|
|
3907
|
+
function resolveBasemapChoices(order, customBasemaps, builtIns) {
|
|
3776
3908
|
const describe = (id) => {
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3909
|
+
const builtIn = builtIns.find((entry) => entry.id === id);
|
|
3910
|
+
if (builtIn) return { id, name: builtIn.name, builtIn: true };
|
|
3911
|
+
if (isBuiltInId(id)) return void 0;
|
|
3780
3912
|
const custom = customBasemaps == null ? void 0 : customBasemaps[id];
|
|
3781
3913
|
if (!custom) return void 0;
|
|
3782
3914
|
return { id, name: custom.name || id, builtIn: false };
|
|
@@ -3784,13 +3916,8 @@ function resolveBasemapChoices(order, customBasemaps) {
|
|
|
3784
3916
|
if (order) {
|
|
3785
3917
|
return order.map(describe).filter((choice) => !!choice);
|
|
3786
3918
|
}
|
|
3787
|
-
const customIds = Object.keys(customBasemaps ?? {}).filter(
|
|
3788
|
-
|
|
3789
|
-
);
|
|
3790
|
-
return [
|
|
3791
|
-
...BUILT_IN_BASEMAP_IDS.map((id) => describe(id)),
|
|
3792
|
-
...customIds.map(describe).filter((choice) => !!choice)
|
|
3793
|
-
];
|
|
3919
|
+
const customIds = Object.keys(customBasemaps ?? {}).filter((id) => !isBuiltInId(id));
|
|
3920
|
+
return [...builtIns.map((entry) => entry.id), ...customIds].map(describe).filter((choice) => !!choice);
|
|
3794
3921
|
}
|
|
3795
3922
|
const PRESET_COLORS$1 = [
|
|
3796
3923
|
"#3b82f6",
|
|
@@ -8812,64 +8939,16 @@ function extract3DFlightPaths(features) {
|
|
|
8812
8939
|
return paths;
|
|
8813
8940
|
}
|
|
8814
8941
|
const CAP_NOTICE_INTERVAL_MS = 5e3;
|
|
8815
|
-
const DEFAULT_LOCAL_GLYPHS_URL = "/fonts/{fontstack}/{range}.pbf";
|
|
8816
8942
|
function basemapInsertAnchor(map) {
|
|
8817
8943
|
if (map.getLayer("satellite-layer")) return "satellite-layer";
|
|
8818
8944
|
if (map.getLayer("custom-polygon-fill")) return "custom-polygon-fill";
|
|
8819
8945
|
return void 0;
|
|
8820
8946
|
}
|
|
8821
|
-
function createBaseStyle(options) {
|
|
8822
|
-
const sources = {};
|
|
8823
|
-
const layers = [
|
|
8824
|
-
{
|
|
8825
|
-
id: "background",
|
|
8826
|
-
type: "background",
|
|
8827
|
-
paint: {
|
|
8828
|
-
"background-color": "#f0f0f0"
|
|
8829
|
-
}
|
|
8830
|
-
}
|
|
8831
|
-
];
|
|
8832
|
-
if (options.enableSatellite !== false) {
|
|
8833
|
-
sources["satellite-tiles"] = {
|
|
8834
|
-
type: "raster",
|
|
8835
|
-
tiles: ["https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"],
|
|
8836
|
-
tileSize: 256,
|
|
8837
|
-
attribution: "Esri, Maxar, Earthstar Geographics"
|
|
8838
|
-
};
|
|
8839
|
-
layers.push({
|
|
8840
|
-
id: "satellite-layer",
|
|
8841
|
-
type: "raster",
|
|
8842
|
-
source: "satellite-tiles",
|
|
8843
|
-
minzoom: 0,
|
|
8844
|
-
maxzoom: 22,
|
|
8845
|
-
layout: { visibility: "none" }
|
|
8846
|
-
});
|
|
8847
|
-
}
|
|
8848
|
-
if (options.enableTerrain !== false) {
|
|
8849
|
-
sources["terrain-dem"] = {
|
|
8850
|
-
type: "raster-dem",
|
|
8851
|
-
tiles: ["https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"],
|
|
8852
|
-
tileSize: 256,
|
|
8853
|
-
maxzoom: 15,
|
|
8854
|
-
encoding: "terrarium"
|
|
8855
|
-
};
|
|
8856
|
-
}
|
|
8857
|
-
return {
|
|
8858
|
-
version: 8,
|
|
8859
|
-
sources,
|
|
8860
|
-
layers,
|
|
8861
|
-
glyphs: options.glyphsUrl || DEFAULT_LOCAL_GLYPHS_URL
|
|
8862
|
-
};
|
|
8863
|
-
}
|
|
8864
8947
|
const BASEMAP_LAYER_PREFIXES = {
|
|
8865
8948
|
streets: "streets-",
|
|
8866
8949
|
satellite: "satellite-",
|
|
8867
8950
|
dark: "dark-"
|
|
8868
8951
|
};
|
|
8869
|
-
const EXTERNAL_STYLE_URLS = {
|
|
8870
|
-
streets: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
|
|
8871
|
-
dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
8872
|
-
};
|
|
8873
8952
|
const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
8874
8953
|
className,
|
|
8875
8954
|
enableDrawing = true,
|
|
@@ -8889,8 +8968,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8889
8968
|
showDebugSidebar = false,
|
|
8890
8969
|
initialCenter = [-74.006, 40.7128],
|
|
8891
8970
|
initialZoom = 12,
|
|
8892
|
-
baseMapStyle = "streets",
|
|
8893
|
-
|
|
8971
|
+
baseMapStyle: requestedBaseMapStyle = "streets",
|
|
8972
|
+
endpoints,
|
|
8973
|
+
customBasemaps: customBasemapsProp,
|
|
8894
8974
|
basemapOrder,
|
|
8895
8975
|
initialDrawingMode,
|
|
8896
8976
|
onFeatureSelect,
|
|
@@ -8907,8 +8987,6 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8907
8987
|
onClearFilter,
|
|
8908
8988
|
showGoToButton = false,
|
|
8909
8989
|
onDropPoint,
|
|
8910
|
-
geocodingUrl,
|
|
8911
|
-
geocoderProvider,
|
|
8912
8990
|
onSearchEngineRequest,
|
|
8913
8991
|
onWorkspaceLoad,
|
|
8914
8992
|
onWorkspaceSave,
|
|
@@ -8923,12 +9001,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8923
9001
|
featureSaveProvider,
|
|
8924
9002
|
featureRefreshProvider,
|
|
8925
9003
|
tooltipProvider,
|
|
8926
|
-
glyphsUrl,
|
|
8927
9004
|
filterGeometry,
|
|
8928
|
-
enableSatellite = true,
|
|
8929
|
-
enableTerrain = true,
|
|
8930
|
-
enableDark = true,
|
|
8931
|
-
enable3D = true,
|
|
8932
9005
|
hideBasemapSwitcher = false,
|
|
8933
9006
|
externalPersistence = false,
|
|
8934
9007
|
enableKeyboardShortcuts = true,
|
|
@@ -8949,6 +9022,18 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8949
9022
|
onEntityContextMenu
|
|
8950
9023
|
}, ref) {
|
|
8951
9024
|
const mapContainer = react.useRef(null);
|
|
9025
|
+
const [resolvedEndpoints] = react.useState(() => resolveEndpoints(endpoints));
|
|
9026
|
+
const [baseMapStyle] = react.useState(() => {
|
|
9027
|
+
if (!resolvedEndpoints.vectorStyles.streets) {
|
|
9028
|
+
console.warn("[map-component] streets is turned off in endpoints.");
|
|
9029
|
+
}
|
|
9030
|
+
const id = initialBasemapId(resolvedEndpoints, requestedBaseMapStyle);
|
|
9031
|
+
if (id !== requestedBaseMapStyle) {
|
|
9032
|
+
console.warn(`[map-component] basemap "${requestedBaseMapStyle}" is turned off in endpoints; opening on "${id}".`);
|
|
9033
|
+
}
|
|
9034
|
+
return id;
|
|
9035
|
+
});
|
|
9036
|
+
const customBasemaps = react.useMemo(() => customBasemapsWithoutBuiltIns(customBasemapsProp), [customBasemapsProp]);
|
|
8952
9037
|
const map = react.useRef(null);
|
|
8953
9038
|
const draw = react.useRef(null);
|
|
8954
9039
|
const fileInputRef = react.useRef(null);
|
|
@@ -8965,19 +9050,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
8965
9050
|
const readOnlyFeatures = react.useRef(/* @__PURE__ */ new Map());
|
|
8966
9051
|
const layerTemporalCacheRef = react.useRef(/* @__PURE__ */ new Map());
|
|
8967
9052
|
const timelineUpdateTimerRef = react.useRef(null);
|
|
8968
|
-
const loadedBasemaps = react.useRef(new Set(
|
|
8969
|
-
const basemapLayerIds = react.useRef(new Map(
|
|
9053
|
+
const loadedBasemaps = react.useRef(new Set(resolvedEndpoints.satellite ? ["satellite"] : []));
|
|
9054
|
+
const basemapLayerIds = react.useRef(new Map(resolvedEndpoints.satellite ? [["satellite", ["satellite-layer"]]] : []));
|
|
8970
9055
|
const availableBasemaps = react.useMemo(() => {
|
|
8971
9056
|
const iconFor = (id) => {
|
|
8972
9057
|
var _a;
|
|
8973
9058
|
return ((_a = MAP_STYLES.find((style) => style.id === id)) == null ? void 0 : _a.icon) ?? lucideReact.Map;
|
|
8974
9059
|
};
|
|
8975
|
-
return resolveBasemapChoices(basemapOrder, customBasemaps).map((choice) => ({
|
|
9060
|
+
return resolveBasemapChoices(basemapOrder, customBasemaps, resolvedEndpoints.builtInBasemaps).map((choice) => ({
|
|
8976
9061
|
id: choice.id,
|
|
8977
9062
|
name: choice.name,
|
|
8978
9063
|
icon: iconFor(choice.id)
|
|
8979
9064
|
}));
|
|
8980
|
-
}, [basemapOrder, customBasemaps]);
|
|
9065
|
+
}, [basemapOrder, customBasemaps, resolvedEndpoints]);
|
|
8981
9066
|
const loadingBasemaps = react.useRef(/* @__PURE__ */ new Set());
|
|
8982
9067
|
const customBasemapRegistry = react.useRef(/* @__PURE__ */ new Map());
|
|
8983
9068
|
const clusterPieManagers = react.useRef(/* @__PURE__ */ new Map());
|
|
@@ -10220,11 +10305,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10220
10305
|
if (!mapContainer.current || map.current) return;
|
|
10221
10306
|
let removeDrawGateListeners;
|
|
10222
10307
|
try {
|
|
10223
|
-
const baseStyle = createBaseStyle(
|
|
10224
|
-
glyphsUrl,
|
|
10225
|
-
enableSatellite,
|
|
10226
|
-
enableTerrain
|
|
10227
|
-
});
|
|
10308
|
+
const baseStyle = createBaseStyle(resolvedEndpoints);
|
|
10228
10309
|
const mapInstance = new maplibregl.Map({
|
|
10229
10310
|
container: mapContainer.current,
|
|
10230
10311
|
style: baseStyle,
|
|
@@ -10797,7 +10878,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10797
10878
|
onMapLoad == null ? void 0 : onMapLoad(mapInstance);
|
|
10798
10879
|
if (baseMapStyle !== "satellite") {
|
|
10799
10880
|
const customDef = customBasemaps == null ? void 0 : customBasemaps[baseMapStyle];
|
|
10800
|
-
const styleUrl = (customDef == null ? void 0 : customDef.type) === "vector" && typeof customDef.style === "string" ? customDef.style :
|
|
10881
|
+
const styleUrl = (customDef == null ? void 0 : customDef.type) === "vector" && typeof customDef.style === "string" ? customDef.style : builtInStyleUrl(resolvedEndpoints, baseMapStyle);
|
|
10801
10882
|
if (styleUrl) {
|
|
10802
10883
|
const prefix = BASEMAP_LAYER_PREFIXES[baseMapStyle] || `${baseMapStyle}-`;
|
|
10803
10884
|
fetch(styleUrl).then((res) => res.json()).then((externalStyle) => {
|
|
@@ -10811,8 +10892,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
10811
10892
|
return url;
|
|
10812
10893
|
}
|
|
10813
10894
|
};
|
|
10814
|
-
|
|
10815
|
-
if (externalStyle.glyphs && !usingLocalGlyphs) {
|
|
10895
|
+
if (externalStyle.glyphs && resolvedEndpoints.adoptStyleGlyphs) {
|
|
10816
10896
|
mapInstance.setGlyphs(resolveUrl(externalStyle.glyphs));
|
|
10817
10897
|
}
|
|
10818
10898
|
if (externalStyle.sprite) {
|
|
@@ -11869,6 +11949,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
11869
11949
|
// Basemap management methods
|
|
11870
11950
|
registerBasemap: (id, definition) => {
|
|
11871
11951
|
if (!map.current) return;
|
|
11952
|
+
if (BUILT_IN_BASEMAP_IDS.includes(id)) {
|
|
11953
|
+
console.warn(`[map-component] registerBasemap("${id}") ignored: built-in basemaps are configured through the endpoints prop.`);
|
|
11954
|
+
return;
|
|
11955
|
+
}
|
|
11872
11956
|
customBasemapRegistry.current.set(id, definition);
|
|
11873
11957
|
if (definition.type === "raster") {
|
|
11874
11958
|
const sourceId = `custom-basemap-${id}`;
|
|
@@ -11895,8 +11979,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
11895
11979
|
},
|
|
11896
11980
|
unregisterBasemap: (id) => {
|
|
11897
11981
|
if (!map.current) return false;
|
|
11898
|
-
|
|
11899
|
-
if (builtIn.includes(id)) return false;
|
|
11982
|
+
if (BUILT_IN_BASEMAP_IDS.includes(id)) return false;
|
|
11900
11983
|
customBasemapRegistry.current.delete(id);
|
|
11901
11984
|
const layerIds = basemapLayerIds.current.get(id) || [];
|
|
11902
11985
|
for (const layerId of layerIds) {
|
|
@@ -11920,7 +12003,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
11920
12003
|
return currentMapStyle;
|
|
11921
12004
|
},
|
|
11922
12005
|
listBasemaps: () => {
|
|
11923
|
-
const builtIn =
|
|
12006
|
+
const builtIn = resolvedEndpoints.builtInBasemaps.map((basemap) => basemap.id);
|
|
11924
12007
|
const custom = Array.from(customBasemapRegistry.current.keys());
|
|
11925
12008
|
return [...builtIn, ...custom];
|
|
11926
12009
|
},
|
|
@@ -13046,7 +13129,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13046
13129
|
if (!map.current) return [];
|
|
13047
13130
|
const mapInstance = map.current;
|
|
13048
13131
|
const prefix = BASEMAP_LAYER_PREFIXES[styleName] || `${styleName}-`;
|
|
13049
|
-
const styleUrl = overrideStyleUrl ||
|
|
13132
|
+
const styleUrl = overrideStyleUrl || builtInStyleUrl(resolvedEndpoints, styleName);
|
|
13050
13133
|
if (!styleUrl) {
|
|
13051
13134
|
console.warn(`No external style URL for: ${styleName}`);
|
|
13052
13135
|
return [];
|
|
@@ -13063,8 +13146,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13063
13146
|
return url;
|
|
13064
13147
|
}
|
|
13065
13148
|
};
|
|
13066
|
-
|
|
13067
|
-
if (externalStyle.glyphs && !usingLocalGlyphs) {
|
|
13149
|
+
if (externalStyle.glyphs && resolvedEndpoints.adoptStyleGlyphs) {
|
|
13068
13150
|
mapInstance.setGlyphs(resolveUrl(externalStyle.glyphs));
|
|
13069
13151
|
}
|
|
13070
13152
|
if (externalStyle.sprite) {
|
|
@@ -13111,7 +13193,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13111
13193
|
console.error(`Failed to load basemap style ${styleName}:`, e);
|
|
13112
13194
|
return [];
|
|
13113
13195
|
}
|
|
13114
|
-
}, [moveLabelsBeforeBasemapSymbols]);
|
|
13196
|
+
}, [moveLabelsBeforeBasemapSymbols, resolvedEndpoints]);
|
|
13115
13197
|
const setBasemapVisibility = react.useCallback((styleName, visible) => {
|
|
13116
13198
|
if (!map.current) return;
|
|
13117
13199
|
const mapInstance = map.current;
|
|
@@ -13125,6 +13207,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13125
13207
|
const handleMapStyleChange = react.useCallback(async (style) => {
|
|
13126
13208
|
if (!map.current) return;
|
|
13127
13209
|
const mapInstance = map.current;
|
|
13210
|
+
if (BUILT_IN_BASEMAP_IDS.includes(style) && !isBuiltInBasemapEnabled(resolvedEndpoints, style)) {
|
|
13211
|
+
console.warn(`[map-component] basemap "${style}" is turned off in endpoints; ignoring the switch.`);
|
|
13212
|
+
return;
|
|
13213
|
+
}
|
|
13128
13214
|
basemapLayerIds.current.forEach((_, basemapName) => {
|
|
13129
13215
|
setBasemapVisibility(basemapName, false);
|
|
13130
13216
|
});
|
|
@@ -13170,7 +13256,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13170
13256
|
setBasemapVisibility(style, true);
|
|
13171
13257
|
setCurrentMapStyle(style);
|
|
13172
13258
|
moveLabelsBeforeBasemapSymbols();
|
|
13173
|
-
}, [loadBasemapStyle, setBasemapVisibility, moveLabelsBeforeBasemapSymbols]);
|
|
13259
|
+
}, [loadBasemapStyle, setBasemapVisibility, moveLabelsBeforeBasemapSymbols, resolvedEndpoints]);
|
|
13174
13260
|
handleMapStyleChangeRef.current = handleMapStyleChange;
|
|
13175
13261
|
const handleUpdateTraceConfig = react.useCallback((layerId, config) => {
|
|
13176
13262
|
saveStateForUndo("trace config", { coalesceKey: `traceConfig:${layerId}` });
|
|
@@ -13520,7 +13606,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13520
13606
|
}, [isEditMode]);
|
|
13521
13607
|
const handleToggle3DTerrain = react.useCallback(() => {
|
|
13522
13608
|
if (!map.current) return;
|
|
13523
|
-
if (!
|
|
13609
|
+
if (!resolvedEndpoints.terrain) {
|
|
13524
13610
|
toast({
|
|
13525
13611
|
title: "3D Terrain Unavailable",
|
|
13526
13612
|
description: "Terrain features are disabled for this configuration.",
|
|
@@ -13565,7 +13651,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13565
13651
|
mapInstance.setLayoutProperty("terrain-hillshade", "visibility", "none");
|
|
13566
13652
|
}
|
|
13567
13653
|
}
|
|
13568
|
-
}, [is3DTerrainEnabled,
|
|
13654
|
+
}, [is3DTerrainEnabled, resolvedEndpoints, toast]);
|
|
13569
13655
|
const handleSelectionModeChange = react.useCallback((mode) => {
|
|
13570
13656
|
setSelectionMode(mode);
|
|
13571
13657
|
setSelectionPoints([]);
|
|
@@ -15889,8 +15975,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
15889
15975
|
showGoToButton,
|
|
15890
15976
|
onFitToFeatures: handleFitToFeatures,
|
|
15891
15977
|
onDropPoint,
|
|
15892
|
-
|
|
15893
|
-
geocoderProvider,
|
|
15978
|
+
geocoder: endpoints == null ? void 0 : endpoints.geocoder,
|
|
15894
15979
|
onSearchEngineRequest: onSearchEngineRequest ? handleSearchAndAddToNewLayer : void 0,
|
|
15895
15980
|
getAllFeatures,
|
|
15896
15981
|
onFlyToFeature: (feature) => {
|
|
@@ -16010,9 +16095,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
16010
16095
|
onToggle3DTerrain: handleToggle3DTerrain,
|
|
16011
16096
|
onUpdateAltitudeDisplayMode: handleUpdateAltitudeDisplayMode,
|
|
16012
16097
|
availableBasemaps,
|
|
16013
|
-
hideSatellite: !
|
|
16014
|
-
hideDark: !
|
|
16015
|
-
hideTerrain: !
|
|
16098
|
+
hideSatellite: !resolvedEndpoints.satellite,
|
|
16099
|
+
hideDark: !resolvedEndpoints.vectorStyles.dark,
|
|
16100
|
+
hideTerrain: !resolvedEndpoints.terrain,
|
|
16016
16101
|
hideBasemapSwitcher,
|
|
16017
16102
|
externalPersistence,
|
|
16018
16103
|
customGlobalMenuItems,
|