@classic-homes/maps-react 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +443 -0
- package/dist/index.cjs +2466 -0
- package/dist/index.d.cts +423 -0
- package/dist/index.d.ts +423 -0
- package/dist/index.js +2294 -0
- package/package.json +79 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2294 @@
|
|
|
1
|
+
import * as React6 from 'react';
|
|
2
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
import maplibregl from 'maplibre-gl';
|
|
7
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
8
|
+
import '@classic-homes/maps-core/styles/controls.css';
|
|
9
|
+
import { generateMapDescription, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates } from '@classic-homes/maps-core';
|
|
10
|
+
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';
|
|
11
|
+
import * as ReactDOM from 'react-dom';
|
|
12
|
+
import { cva } from 'class-variance-authority';
|
|
13
|
+
|
|
14
|
+
// src/components/base/MapContainer.tsx
|
|
15
|
+
function cn(...inputs) {
|
|
16
|
+
return twMerge(clsx(inputs));
|
|
17
|
+
}
|
|
18
|
+
var MapSkeleton = React6.forwardRef(
|
|
19
|
+
({ height = 400, className, ...props }, ref) => {
|
|
20
|
+
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
21
|
+
return /* @__PURE__ */ jsxs(
|
|
22
|
+
"div",
|
|
23
|
+
{
|
|
24
|
+
ref,
|
|
25
|
+
className: cn("relative animate-pulse rounded-lg border border-border bg-muted", className),
|
|
26
|
+
style: { height: heightStyle },
|
|
27
|
+
role: "progressbar",
|
|
28
|
+
"aria-label": "Loading map",
|
|
29
|
+
"aria-busy": "true",
|
|
30
|
+
...props,
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 text-muted-foreground", children: [
|
|
33
|
+
/* @__PURE__ */ jsxs(
|
|
34
|
+
"svg",
|
|
35
|
+
{
|
|
36
|
+
className: "h-8 w-8 animate-spin",
|
|
37
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
38
|
+
fill: "none",
|
|
39
|
+
viewBox: "0 0 24 24",
|
|
40
|
+
children: [
|
|
41
|
+
/* @__PURE__ */ jsx(
|
|
42
|
+
"circle",
|
|
43
|
+
{
|
|
44
|
+
className: "opacity-25",
|
|
45
|
+
cx: "12",
|
|
46
|
+
cy: "12",
|
|
47
|
+
r: "10",
|
|
48
|
+
stroke: "currentColor",
|
|
49
|
+
strokeWidth: "4"
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"path",
|
|
54
|
+
{
|
|
55
|
+
className: "opacity-75",
|
|
56
|
+
fill: "currentColor",
|
|
57
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm", children: "Loading map..." })
|
|
64
|
+
] }) }),
|
|
65
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-4 grid grid-cols-4 grid-rows-4 gap-1 opacity-20", children: Array.from({ length: 16 }).map((_, i) => /* @__PURE__ */ jsx("div", { className: "rounded bg-muted-foreground/20" }, i)) })
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
MapSkeleton.displayName = "MapSkeleton";
|
|
72
|
+
var MapError = React6.forwardRef(
|
|
73
|
+
({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
|
|
74
|
+
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
75
|
+
return /* @__PURE__ */ jsx(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
ref,
|
|
79
|
+
className: cn(
|
|
80
|
+
"flex flex-col items-center justify-center rounded-lg border border-destructive/50 bg-destructive/5",
|
|
81
|
+
className
|
|
82
|
+
),
|
|
83
|
+
style: { height: heightStyle },
|
|
84
|
+
role: "alert",
|
|
85
|
+
"aria-live": "polite",
|
|
86
|
+
...props,
|
|
87
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-3 text-center", children: [
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"svg",
|
|
90
|
+
{
|
|
91
|
+
className: "h-10 w-10 text-destructive",
|
|
92
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
93
|
+
fill: "none",
|
|
94
|
+
viewBox: "0 0 24 24",
|
|
95
|
+
stroke: "currentColor",
|
|
96
|
+
strokeWidth: 2,
|
|
97
|
+
"aria-hidden": "true",
|
|
98
|
+
children: /* @__PURE__ */ jsx(
|
|
99
|
+
"path",
|
|
100
|
+
{
|
|
101
|
+
strokeLinecap: "round",
|
|
102
|
+
strokeLinejoin: "round",
|
|
103
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
109
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-destructive", children: message }),
|
|
110
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Check your connection and try again" })
|
|
111
|
+
] }),
|
|
112
|
+
onRetry && /* @__PURE__ */ jsx(
|
|
113
|
+
"button",
|
|
114
|
+
{
|
|
115
|
+
onClick: onRetry,
|
|
116
|
+
className: "mt-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
117
|
+
children: "Retry"
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
] })
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
MapError.displayName = "MapError";
|
|
126
|
+
var MapEmpty = React6.forwardRef(
|
|
127
|
+
({ message = "No map data to display", height = 400, className, ...props }, ref) => {
|
|
128
|
+
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
129
|
+
return /* @__PURE__ */ jsx(
|
|
130
|
+
"div",
|
|
131
|
+
{
|
|
132
|
+
ref,
|
|
133
|
+
className: cn(
|
|
134
|
+
"flex flex-col items-center justify-center rounded-lg border border-border bg-muted/50",
|
|
135
|
+
className
|
|
136
|
+
),
|
|
137
|
+
style: { height: heightStyle },
|
|
138
|
+
role: "status",
|
|
139
|
+
"aria-label": message,
|
|
140
|
+
...props,
|
|
141
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-3 text-center", children: [
|
|
142
|
+
/* @__PURE__ */ jsx(
|
|
143
|
+
"svg",
|
|
144
|
+
{
|
|
145
|
+
className: "h-10 w-10 text-muted-foreground",
|
|
146
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
147
|
+
fill: "none",
|
|
148
|
+
viewBox: "0 0 24 24",
|
|
149
|
+
stroke: "currentColor",
|
|
150
|
+
strokeWidth: 1.5,
|
|
151
|
+
"aria-hidden": "true",
|
|
152
|
+
children: /* @__PURE__ */ jsx(
|
|
153
|
+
"path",
|
|
154
|
+
{
|
|
155
|
+
strokeLinecap: "round",
|
|
156
|
+
strokeLinejoin: "round",
|
|
157
|
+
d: "M9 6.75V15m6-6v8.25m.503 3.498l4.875-2.437c.381-.19.622-.58.622-1.006V4.82c0-.836-.88-1.38-1.628-1.006l-3.869 1.934c-.317.159-.69.159-1.006 0L9.503 3.252a1.125 1.125 0 00-1.006 0L3.622 5.689C3.24 5.88 3 6.27 3 6.695V19.18c0 .836.88 1.38 1.628 1.006l3.869-1.934c.317-.159.69-.159 1.006 0l4.994 2.497c.317.158.69.158 1.006 0z"
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: message })
|
|
163
|
+
] })
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
MapEmpty.displayName = "MapEmpty";
|
|
169
|
+
var MapContainer = React6.forwardRef(
|
|
170
|
+
({
|
|
171
|
+
title,
|
|
172
|
+
description,
|
|
173
|
+
height = 400,
|
|
174
|
+
width = "100%",
|
|
175
|
+
loading,
|
|
176
|
+
error,
|
|
177
|
+
empty,
|
|
178
|
+
emptyMessage,
|
|
179
|
+
onRetry,
|
|
180
|
+
className,
|
|
181
|
+
wrapperClassName,
|
|
182
|
+
children,
|
|
183
|
+
...props
|
|
184
|
+
}, ref) => {
|
|
185
|
+
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
186
|
+
const widthStyle = typeof width === "number" ? `${width}px` : width;
|
|
187
|
+
if (loading) {
|
|
188
|
+
return /* @__PURE__ */ jsx(MapSkeleton, { height, className: wrapperClassName });
|
|
189
|
+
}
|
|
190
|
+
if (error) {
|
|
191
|
+
return /* @__PURE__ */ jsx(MapError, { message: error, height, onRetry, className: wrapperClassName });
|
|
192
|
+
}
|
|
193
|
+
if (empty) {
|
|
194
|
+
return /* @__PURE__ */ jsx(MapEmpty, { message: emptyMessage, height, className: wrapperClassName });
|
|
195
|
+
}
|
|
196
|
+
const descriptionId = description ? `${title.replace(/\s+/g, "-")}-desc` : void 0;
|
|
197
|
+
return /* @__PURE__ */ jsxs(
|
|
198
|
+
"div",
|
|
199
|
+
{
|
|
200
|
+
ref,
|
|
201
|
+
role: "application",
|
|
202
|
+
"aria-label": title,
|
|
203
|
+
"aria-describedby": descriptionId,
|
|
204
|
+
"data-testid": "map-container",
|
|
205
|
+
className: cn("relative overflow-hidden rounded-lg border border-border", wrapperClassName),
|
|
206
|
+
style: { width: widthStyle, height: heightStyle },
|
|
207
|
+
...props,
|
|
208
|
+
children: [
|
|
209
|
+
description && /* @__PURE__ */ jsx("span", { id: descriptionId, className: "sr-only", children: description }),
|
|
210
|
+
/* @__PURE__ */ jsx("div", { className: cn("relative h-full w-full", className), children })
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
MapContainer.displayName = "MapContainer";
|
|
217
|
+
function useMapTheme(preference = "auto") {
|
|
218
|
+
const [isDark, setIsDark] = useState(false);
|
|
219
|
+
const updateTheme = useCallback(() => {
|
|
220
|
+
if (preference !== "auto") {
|
|
221
|
+
setIsDark(preference === "dark");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (typeof document !== "undefined") {
|
|
225
|
+
const hasDarkClass = document.documentElement.classList.contains("dark");
|
|
226
|
+
setIsDark(hasDarkClass);
|
|
227
|
+
}
|
|
228
|
+
}, [preference]);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
updateTheme();
|
|
231
|
+
if (preference !== "auto" || typeof document === "undefined") return;
|
|
232
|
+
const observer = new MutationObserver((mutations) => {
|
|
233
|
+
mutations.forEach((mutation) => {
|
|
234
|
+
if (mutation.type === "attributes" && mutation.attributeName === "class") {
|
|
235
|
+
updateTheme();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
observer.observe(document.documentElement, {
|
|
240
|
+
attributes: true,
|
|
241
|
+
attributeFilter: ["class"]
|
|
242
|
+
});
|
|
243
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
244
|
+
const handleMediaChange = () => updateTheme();
|
|
245
|
+
mediaQuery.addEventListener("change", handleMediaChange);
|
|
246
|
+
return () => {
|
|
247
|
+
observer.disconnect();
|
|
248
|
+
mediaQuery.removeEventListener("change", handleMediaChange);
|
|
249
|
+
};
|
|
250
|
+
}, [preference, updateTheme]);
|
|
251
|
+
return {
|
|
252
|
+
themeName: isDark ? THEME_DARK : THEME_LIGHT,
|
|
253
|
+
theme: isDark ? darkTheme : lightTheme,
|
|
254
|
+
style: isDark ? darkBasicStyle : lightBasicStyle,
|
|
255
|
+
isDark
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function useReducedMotion() {
|
|
259
|
+
const [prefersReducedMotion2, setPrefersReducedMotion] = useState(false);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
if (typeof window === "undefined") return;
|
|
262
|
+
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
263
|
+
setPrefersReducedMotion(mediaQuery.matches);
|
|
264
|
+
const handleChange = (event) => {
|
|
265
|
+
setPrefersReducedMotion(event.matches);
|
|
266
|
+
};
|
|
267
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
268
|
+
return () => {
|
|
269
|
+
mediaQuery.removeEventListener("change", handleChange);
|
|
270
|
+
};
|
|
271
|
+
}, []);
|
|
272
|
+
return prefersReducedMotion2;
|
|
273
|
+
}
|
|
274
|
+
var MapContext = React6.createContext({
|
|
275
|
+
map: null,
|
|
276
|
+
loaded: false,
|
|
277
|
+
controlOffsets: {}
|
|
278
|
+
});
|
|
279
|
+
function useMap() {
|
|
280
|
+
const context = React6.useContext(MapContext);
|
|
281
|
+
if (!context) {
|
|
282
|
+
throw new Error("useMap must be used within a Map component");
|
|
283
|
+
}
|
|
284
|
+
return context;
|
|
285
|
+
}
|
|
286
|
+
function useMapInstance() {
|
|
287
|
+
const { map, loaded } = useMap();
|
|
288
|
+
return loaded ? map : null;
|
|
289
|
+
}
|
|
290
|
+
var Map = React6.forwardRef(
|
|
291
|
+
({
|
|
292
|
+
// Base props
|
|
293
|
+
title,
|
|
294
|
+
description,
|
|
295
|
+
width,
|
|
296
|
+
height = 400,
|
|
297
|
+
loading,
|
|
298
|
+
error,
|
|
299
|
+
emptyMessage,
|
|
300
|
+
theme: themePref = "auto",
|
|
301
|
+
animation = true,
|
|
302
|
+
className,
|
|
303
|
+
children,
|
|
304
|
+
// Map props
|
|
305
|
+
style: customStyle,
|
|
306
|
+
center = [0, 0],
|
|
307
|
+
zoom = 2,
|
|
308
|
+
bearing = 0,
|
|
309
|
+
pitch = 0,
|
|
310
|
+
bounds,
|
|
311
|
+
boundsPadding,
|
|
312
|
+
minZoom,
|
|
313
|
+
maxZoom,
|
|
314
|
+
maxBounds,
|
|
315
|
+
interactive = true,
|
|
316
|
+
scrollZoom = true,
|
|
317
|
+
dragPan = true,
|
|
318
|
+
dragRotate = true,
|
|
319
|
+
doubleClickZoom = true,
|
|
320
|
+
touchZoomRotate = true,
|
|
321
|
+
keyboard = true,
|
|
322
|
+
attributionControl = true,
|
|
323
|
+
customAttribution,
|
|
324
|
+
navigationControl = true,
|
|
325
|
+
navigationControlPosition = "top-right",
|
|
326
|
+
scaleControl = false,
|
|
327
|
+
scaleControlPosition = "bottom-left",
|
|
328
|
+
fullscreenControl = false,
|
|
329
|
+
fullscreenControlPosition = "top-right",
|
|
330
|
+
geolocateControl = false,
|
|
331
|
+
geolocateControlPosition = "top-right",
|
|
332
|
+
// Callbacks
|
|
333
|
+
onLoad,
|
|
334
|
+
onClick,
|
|
335
|
+
onDblClick,
|
|
336
|
+
onContextMenu,
|
|
337
|
+
onMouseMove,
|
|
338
|
+
onMove,
|
|
339
|
+
onMoveStart,
|
|
340
|
+
onMoveEnd,
|
|
341
|
+
onZoom,
|
|
342
|
+
onError
|
|
343
|
+
}, ref) => {
|
|
344
|
+
const containerRef = React6.useRef(null);
|
|
345
|
+
const mapRef = React6.useRef(null);
|
|
346
|
+
const [mapLoaded, setMapLoaded] = React6.useState(false);
|
|
347
|
+
const [mapError, setMapError] = React6.useState(null);
|
|
348
|
+
const customControlRegistryRef = React6.useRef({
|
|
349
|
+
"top-left": [],
|
|
350
|
+
"top-right": [],
|
|
351
|
+
"bottom-left": [],
|
|
352
|
+
"bottom-right": []
|
|
353
|
+
});
|
|
354
|
+
const [, forceUpdate] = React6.useReducer((x) => x + 1, 0);
|
|
355
|
+
const prefersReducedMotion2 = useReducedMotion();
|
|
356
|
+
const { style: themeStyle } = useMapTheme(themePref);
|
|
357
|
+
const mapStyle = customStyle || themeStyle;
|
|
358
|
+
const controlOffsets = React6.useMemo(() => {
|
|
359
|
+
const offsets = {
|
|
360
|
+
"top-left": 0,
|
|
361
|
+
"top-right": 0,
|
|
362
|
+
"bottom-left": 0,
|
|
363
|
+
"bottom-right": 0
|
|
364
|
+
};
|
|
365
|
+
if (navigationControl) {
|
|
366
|
+
offsets[navigationControlPosition] += 100;
|
|
367
|
+
}
|
|
368
|
+
if (scaleControl) {
|
|
369
|
+
offsets[scaleControlPosition] += 28;
|
|
370
|
+
}
|
|
371
|
+
if (fullscreenControl) {
|
|
372
|
+
offsets[fullscreenControlPosition] += 38;
|
|
373
|
+
}
|
|
374
|
+
if (geolocateControl) {
|
|
375
|
+
offsets[geolocateControlPosition] += 38;
|
|
376
|
+
}
|
|
377
|
+
return offsets;
|
|
378
|
+
}, [
|
|
379
|
+
navigationControl,
|
|
380
|
+
navigationControlPosition,
|
|
381
|
+
scaleControl,
|
|
382
|
+
scaleControlPosition,
|
|
383
|
+
fullscreenControl,
|
|
384
|
+
fullscreenControlPosition,
|
|
385
|
+
geolocateControl,
|
|
386
|
+
geolocateControlPosition
|
|
387
|
+
]);
|
|
388
|
+
const registerControl = React6.useCallback(
|
|
389
|
+
(id, position, height2) => {
|
|
390
|
+
const registry = customControlRegistryRef.current;
|
|
391
|
+
const positionControls = registry[position] || [];
|
|
392
|
+
const existingIndex = positionControls.findIndex((c) => c.id === id);
|
|
393
|
+
if (existingIndex >= 0) {
|
|
394
|
+
positionControls[existingIndex].height = height2;
|
|
395
|
+
} else {
|
|
396
|
+
positionControls.push({ id, height: height2 });
|
|
397
|
+
forceUpdate();
|
|
398
|
+
}
|
|
399
|
+
registry[position] = positionControls;
|
|
400
|
+
let offset = 0;
|
|
401
|
+
for (const control of positionControls) {
|
|
402
|
+
if (control.id === id) break;
|
|
403
|
+
offset += control.height + 8;
|
|
404
|
+
}
|
|
405
|
+
return offset;
|
|
406
|
+
},
|
|
407
|
+
[]
|
|
408
|
+
);
|
|
409
|
+
const unregisterControl = React6.useCallback((id, position) => {
|
|
410
|
+
const registry = customControlRegistryRef.current;
|
|
411
|
+
const positionControls = registry[position] || [];
|
|
412
|
+
registry[position] = positionControls.filter((c) => c.id !== id);
|
|
413
|
+
forceUpdate();
|
|
414
|
+
}, []);
|
|
415
|
+
const getCustomControlOffset = React6.useCallback((id, position) => {
|
|
416
|
+
const registry = customControlRegistryRef.current;
|
|
417
|
+
const positionControls = registry[position] || [];
|
|
418
|
+
let offset = 0;
|
|
419
|
+
for (const control of positionControls) {
|
|
420
|
+
if (control.id === id) break;
|
|
421
|
+
offset += control.height + 8;
|
|
422
|
+
}
|
|
423
|
+
return offset;
|
|
424
|
+
}, []);
|
|
425
|
+
const accessibleDescription = description || generateMapDescription(title, {
|
|
426
|
+
center,
|
|
427
|
+
zoom
|
|
428
|
+
});
|
|
429
|
+
React6.useEffect(() => {
|
|
430
|
+
if (!containerRef.current || mapRef.current) return;
|
|
431
|
+
try {
|
|
432
|
+
const map = new maplibregl.Map({
|
|
433
|
+
container: containerRef.current,
|
|
434
|
+
style: mapStyle,
|
|
435
|
+
center,
|
|
436
|
+
zoom,
|
|
437
|
+
bearing,
|
|
438
|
+
pitch,
|
|
439
|
+
minZoom,
|
|
440
|
+
maxZoom,
|
|
441
|
+
maxBounds,
|
|
442
|
+
interactive,
|
|
443
|
+
scrollZoom,
|
|
444
|
+
dragPan,
|
|
445
|
+
dragRotate,
|
|
446
|
+
doubleClickZoom,
|
|
447
|
+
touchZoomRotate,
|
|
448
|
+
keyboard,
|
|
449
|
+
attributionControl: attributionControl ? { customAttribution } : false
|
|
450
|
+
});
|
|
451
|
+
mapRef.current = map;
|
|
452
|
+
if (navigationControl) {
|
|
453
|
+
map.addControl(
|
|
454
|
+
new maplibregl.NavigationControl({
|
|
455
|
+
showCompass: true,
|
|
456
|
+
showZoom: true,
|
|
457
|
+
visualizePitch: true
|
|
458
|
+
}),
|
|
459
|
+
navigationControlPosition
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (scaleControl) {
|
|
463
|
+
map.addControl(new maplibregl.ScaleControl({ unit: "metric" }), scaleControlPosition);
|
|
464
|
+
}
|
|
465
|
+
if (fullscreenControl) {
|
|
466
|
+
map.addControl(new maplibregl.FullscreenControl(), fullscreenControlPosition);
|
|
467
|
+
}
|
|
468
|
+
if (geolocateControl) {
|
|
469
|
+
map.addControl(
|
|
470
|
+
new maplibregl.GeolocateControl({
|
|
471
|
+
positionOptions: { enableHighAccuracy: true },
|
|
472
|
+
trackUserLocation: true
|
|
473
|
+
}),
|
|
474
|
+
geolocateControlPosition
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
map.on("load", () => {
|
|
478
|
+
setMapLoaded(true);
|
|
479
|
+
if (bounds) {
|
|
480
|
+
map.fitBounds(bounds, {
|
|
481
|
+
padding: boundsPadding,
|
|
482
|
+
animate: animation && !prefersReducedMotion2
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
onLoad?.({ type: "load", loaded: true });
|
|
486
|
+
});
|
|
487
|
+
map.on("error", (e) => {
|
|
488
|
+
const errorMessage = e.error?.message || "Map error";
|
|
489
|
+
setMapError(errorMessage);
|
|
490
|
+
onError?.({ type: "error", message: errorMessage, error: e.error });
|
|
491
|
+
});
|
|
492
|
+
return () => {
|
|
493
|
+
map.remove();
|
|
494
|
+
mapRef.current = null;
|
|
495
|
+
setMapLoaded(false);
|
|
496
|
+
};
|
|
497
|
+
} catch (err) {
|
|
498
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
|
|
499
|
+
setMapError(errorMessage);
|
|
500
|
+
onError?.({ type: "error", message: errorMessage, error: err });
|
|
501
|
+
}
|
|
502
|
+
}, []);
|
|
503
|
+
React6.useEffect(() => {
|
|
504
|
+
if (!mapRef.current || !mapLoaded) return;
|
|
505
|
+
mapRef.current.setStyle(mapStyle);
|
|
506
|
+
}, [mapStyle, mapLoaded]);
|
|
507
|
+
React6.useEffect(() => {
|
|
508
|
+
const map = mapRef.current;
|
|
509
|
+
if (!map || !mapLoaded) return;
|
|
510
|
+
const createEventParams = (e) => ({
|
|
511
|
+
lngLat: [e.lngLat.lng, e.lngLat.lat],
|
|
512
|
+
point: [e.point.x, e.point.y],
|
|
513
|
+
originalEvent: e.originalEvent
|
|
514
|
+
});
|
|
515
|
+
const createMoveParams = () => {
|
|
516
|
+
const mapBounds = map.getBounds();
|
|
517
|
+
return {
|
|
518
|
+
center: [map.getCenter().lng, map.getCenter().lat],
|
|
519
|
+
zoom: map.getZoom(),
|
|
520
|
+
bearing: map.getBearing(),
|
|
521
|
+
pitch: map.getPitch(),
|
|
522
|
+
bounds: {
|
|
523
|
+
southwest: [mapBounds.getSouthWest().lng, mapBounds.getSouthWest().lat],
|
|
524
|
+
northeast: [mapBounds.getNorthEast().lng, mapBounds.getNorthEast().lat]
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
const handleClick = (e) => {
|
|
529
|
+
onClick?.({
|
|
530
|
+
type: "click",
|
|
531
|
+
...createEventParams(e),
|
|
532
|
+
features: map.queryRenderedFeatures(
|
|
533
|
+
e.point
|
|
534
|
+
)
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
const handleDblClick = (e) => {
|
|
538
|
+
onDblClick?.({
|
|
539
|
+
type: "dblclick",
|
|
540
|
+
...createEventParams(e),
|
|
541
|
+
features: map.queryRenderedFeatures(
|
|
542
|
+
e.point
|
|
543
|
+
)
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
const handleContextMenu = (e) => {
|
|
547
|
+
onContextMenu?.({
|
|
548
|
+
type: "contextmenu",
|
|
549
|
+
...createEventParams(e),
|
|
550
|
+
features: map.queryRenderedFeatures(
|
|
551
|
+
e.point
|
|
552
|
+
)
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
const handleMouseMove = (e) => {
|
|
556
|
+
onMouseMove?.({
|
|
557
|
+
type: "mousemove",
|
|
558
|
+
...createEventParams(e),
|
|
559
|
+
features: map.queryRenderedFeatures(
|
|
560
|
+
e.point
|
|
561
|
+
)
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
const handleMove = () => {
|
|
565
|
+
onMove?.({ type: "move", ...createMoveParams() });
|
|
566
|
+
};
|
|
567
|
+
const handleMoveStart = () => {
|
|
568
|
+
onMoveStart?.({ type: "movestart", ...createMoveParams() });
|
|
569
|
+
};
|
|
570
|
+
const handleMoveEnd = () => {
|
|
571
|
+
onMoveEnd?.({ type: "moveend", ...createMoveParams() });
|
|
572
|
+
};
|
|
573
|
+
const handleZoom = () => {
|
|
574
|
+
onZoom?.({ type: "zoom", ...createMoveParams() });
|
|
575
|
+
};
|
|
576
|
+
if (onClick) map.on("click", handleClick);
|
|
577
|
+
if (onDblClick) map.on("dblclick", handleDblClick);
|
|
578
|
+
if (onContextMenu) map.on("contextmenu", handleContextMenu);
|
|
579
|
+
if (onMouseMove) map.on("mousemove", handleMouseMove);
|
|
580
|
+
if (onMove) map.on("move", handleMove);
|
|
581
|
+
if (onMoveStart) map.on("movestart", handleMoveStart);
|
|
582
|
+
if (onMoveEnd) map.on("moveend", handleMoveEnd);
|
|
583
|
+
if (onZoom) map.on("zoom", handleZoom);
|
|
584
|
+
return () => {
|
|
585
|
+
if (onClick) map.off("click", handleClick);
|
|
586
|
+
if (onDblClick) map.off("dblclick", handleDblClick);
|
|
587
|
+
if (onContextMenu) map.off("contextmenu", handleContextMenu);
|
|
588
|
+
if (onMouseMove) map.off("mousemove", handleMouseMove);
|
|
589
|
+
if (onMove) map.off("move", handleMove);
|
|
590
|
+
if (onMoveStart) map.off("movestart", handleMoveStart);
|
|
591
|
+
if (onMoveEnd) map.off("moveend", handleMoveEnd);
|
|
592
|
+
if (onZoom) map.off("zoom", handleZoom);
|
|
593
|
+
};
|
|
594
|
+
}, [
|
|
595
|
+
mapLoaded,
|
|
596
|
+
onClick,
|
|
597
|
+
onDblClick,
|
|
598
|
+
onContextMenu,
|
|
599
|
+
onMouseMove,
|
|
600
|
+
onMove,
|
|
601
|
+
onMoveStart,
|
|
602
|
+
onMoveEnd,
|
|
603
|
+
onZoom
|
|
604
|
+
]);
|
|
605
|
+
const combinedError = error || mapError;
|
|
606
|
+
return /* @__PURE__ */ jsx(
|
|
607
|
+
MapContainer,
|
|
608
|
+
{
|
|
609
|
+
ref,
|
|
610
|
+
title,
|
|
611
|
+
description: accessibleDescription,
|
|
612
|
+
height,
|
|
613
|
+
width,
|
|
614
|
+
loading,
|
|
615
|
+
error: combinedError,
|
|
616
|
+
emptyMessage,
|
|
617
|
+
className,
|
|
618
|
+
children: /* @__PURE__ */ jsxs(
|
|
619
|
+
MapContext.Provider,
|
|
620
|
+
{
|
|
621
|
+
value: {
|
|
622
|
+
map: mapRef.current,
|
|
623
|
+
loaded: mapLoaded,
|
|
624
|
+
controlOffsets,
|
|
625
|
+
registerControl,
|
|
626
|
+
unregisterControl,
|
|
627
|
+
getCustomControlOffset
|
|
628
|
+
},
|
|
629
|
+
children: [
|
|
630
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "absolute inset-0" }),
|
|
631
|
+
mapLoaded && children && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 pointer-events-none [&>*]:pointer-events-auto", children })
|
|
632
|
+
]
|
|
633
|
+
}
|
|
634
|
+
)
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
Map.displayName = "Map";
|
|
640
|
+
var Source = ({
|
|
641
|
+
id,
|
|
642
|
+
type,
|
|
643
|
+
data,
|
|
644
|
+
tiles,
|
|
645
|
+
url,
|
|
646
|
+
tileSize,
|
|
647
|
+
attribution,
|
|
648
|
+
cluster,
|
|
649
|
+
clusterRadius,
|
|
650
|
+
clusterMaxZoom,
|
|
651
|
+
generateId,
|
|
652
|
+
promoteId,
|
|
653
|
+
fitBounds: shouldFitBounds = false,
|
|
654
|
+
fitBoundsPadding = 50,
|
|
655
|
+
fitBoundsMaxZoom,
|
|
656
|
+
fitBoundsAnimate = true,
|
|
657
|
+
children
|
|
658
|
+
}) => {
|
|
659
|
+
const { map, loaded } = useMap();
|
|
660
|
+
const sourceAdded = React6.useRef(false);
|
|
661
|
+
const initialFitDone = React6.useRef(false);
|
|
662
|
+
const fitBoundsParamsRef = React6.useRef({
|
|
663
|
+
shouldFitBounds,
|
|
664
|
+
data,
|
|
665
|
+
fitBoundsPadding,
|
|
666
|
+
fitBoundsMaxZoom,
|
|
667
|
+
fitBoundsAnimate,
|
|
668
|
+
type
|
|
669
|
+
});
|
|
670
|
+
fitBoundsParamsRef.current = {
|
|
671
|
+
shouldFitBounds,
|
|
672
|
+
data,
|
|
673
|
+
fitBoundsPadding,
|
|
674
|
+
fitBoundsMaxZoom,
|
|
675
|
+
fitBoundsAnimate,
|
|
676
|
+
type
|
|
677
|
+
};
|
|
678
|
+
const performFitBounds = React6.useCallback(
|
|
679
|
+
(cancelledRef) => {
|
|
680
|
+
const params = fitBoundsParamsRef.current;
|
|
681
|
+
if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
|
|
682
|
+
if (params.type !== "geojson" || typeof params.data !== "object" || !params.data) return;
|
|
683
|
+
if (!map) return;
|
|
684
|
+
const calculatedBounds = calculateBounds(params.data);
|
|
685
|
+
if (!calculatedBounds) return;
|
|
686
|
+
const swLng = Number(calculatedBounds[0][0]);
|
|
687
|
+
const swLat = Number(calculatedBounds[0][1]);
|
|
688
|
+
const neLng = Number(calculatedBounds[1][0]);
|
|
689
|
+
const neLat = Number(calculatedBounds[1][1]);
|
|
690
|
+
if (!isFinite(swLng) || !isFinite(swLat) || !isFinite(neLng) || !isFinite(neLat)) {
|
|
691
|
+
console.warn("[maps-react] Source: Invalid bounds calculated, skipping fitBounds");
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const prefersReducedMotion2 = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
695
|
+
requestAnimationFrame(() => {
|
|
696
|
+
if (cancelledRef.current || initialFitDone.current) return;
|
|
697
|
+
try {
|
|
698
|
+
const centerLng = (swLng + neLng) / 2;
|
|
699
|
+
const centerLat = (swLat + neLat) / 2;
|
|
700
|
+
const lngSpan = Math.abs(neLng - swLng);
|
|
701
|
+
const latSpan = Math.abs(neLat - swLat);
|
|
702
|
+
const maxSpan = Math.max(lngSpan, latSpan);
|
|
703
|
+
const zoom = Math.min(
|
|
704
|
+
Math.floor(Math.log2(360 / maxSpan)) - 1,
|
|
705
|
+
params.fitBoundsMaxZoom ?? 18
|
|
706
|
+
);
|
|
707
|
+
map.flyTo({
|
|
708
|
+
center: [centerLng, centerLat],
|
|
709
|
+
zoom: Math.max(zoom, 1),
|
|
710
|
+
animate: params.fitBoundsAnimate && !prefersReducedMotion2,
|
|
711
|
+
padding: params.fitBoundsPadding
|
|
712
|
+
});
|
|
713
|
+
initialFitDone.current = true;
|
|
714
|
+
} catch (err) {
|
|
715
|
+
console.warn("[maps-react] Source: fitBounds failed", err);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
},
|
|
719
|
+
[map]
|
|
720
|
+
);
|
|
721
|
+
React6.useEffect(() => {
|
|
722
|
+
if (!map || !loaded || sourceAdded.current) return;
|
|
723
|
+
if (map.getSource(id)) {
|
|
724
|
+
sourceAdded.current = true;
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
let sourceConfig;
|
|
729
|
+
if (type === "geojson") {
|
|
730
|
+
let sourceData;
|
|
731
|
+
if (typeof data === "string") {
|
|
732
|
+
sourceData = data;
|
|
733
|
+
} else if (data && typeof data === "object") {
|
|
734
|
+
sourceData = data;
|
|
735
|
+
} else {
|
|
736
|
+
sourceData = { type: "FeatureCollection", features: [] };
|
|
737
|
+
}
|
|
738
|
+
const geojsonConfig = {
|
|
739
|
+
type: "geojson",
|
|
740
|
+
data: sourceData
|
|
741
|
+
};
|
|
742
|
+
if (cluster === true || typeof cluster === "object" && cluster.enabled) {
|
|
743
|
+
geojsonConfig.cluster = true;
|
|
744
|
+
geojsonConfig.clusterRadius = clusterRadius ?? (typeof cluster === "object" ? cluster.radius : void 0) ?? 50;
|
|
745
|
+
geojsonConfig.clusterMaxZoom = clusterMaxZoom ?? (typeof cluster === "object" ? cluster.maxZoom : void 0) ?? 14;
|
|
746
|
+
}
|
|
747
|
+
if (generateId !== void 0) {
|
|
748
|
+
geojsonConfig.generateId = generateId;
|
|
749
|
+
}
|
|
750
|
+
if (promoteId) {
|
|
751
|
+
geojsonConfig.promoteId = promoteId;
|
|
752
|
+
}
|
|
753
|
+
if (attribution) {
|
|
754
|
+
geojsonConfig.attribution = attribution;
|
|
755
|
+
}
|
|
756
|
+
sourceConfig = geojsonConfig;
|
|
757
|
+
} else if (type === "vector") {
|
|
758
|
+
const vectorConfig = {
|
|
759
|
+
type: "vector"
|
|
760
|
+
};
|
|
761
|
+
if (url) {
|
|
762
|
+
vectorConfig.url = url;
|
|
763
|
+
}
|
|
764
|
+
if (tiles) {
|
|
765
|
+
vectorConfig.tiles = tiles;
|
|
766
|
+
}
|
|
767
|
+
if (attribution) {
|
|
768
|
+
vectorConfig.attribution = attribution;
|
|
769
|
+
}
|
|
770
|
+
sourceConfig = vectorConfig;
|
|
771
|
+
} else if (type === "raster" || type === "raster-dem") {
|
|
772
|
+
const rasterConfig = {
|
|
773
|
+
type
|
|
774
|
+
};
|
|
775
|
+
if (url) {
|
|
776
|
+
rasterConfig.url = url;
|
|
777
|
+
}
|
|
778
|
+
if (tiles) {
|
|
779
|
+
rasterConfig.tiles = tiles;
|
|
780
|
+
}
|
|
781
|
+
if (tileSize) {
|
|
782
|
+
rasterConfig.tileSize = tileSize;
|
|
783
|
+
}
|
|
784
|
+
if (attribution) {
|
|
785
|
+
rasterConfig.attribution = attribution;
|
|
786
|
+
}
|
|
787
|
+
sourceConfig = rasterConfig;
|
|
788
|
+
} else {
|
|
789
|
+
console.warn(`[maps-react] Unsupported source type: ${type}`);
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const cancelledRef = { current: false };
|
|
793
|
+
const handleSourceData = (e) => {
|
|
794
|
+
if (cancelledRef.current) return;
|
|
795
|
+
if (e.sourceId === id && e.isSourceLoaded) {
|
|
796
|
+
map.off("sourcedata", handleSourceData);
|
|
797
|
+
performFitBounds(cancelledRef);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
map.on("sourcedata", handleSourceData);
|
|
801
|
+
const handleIdle = () => {
|
|
802
|
+
if (cancelledRef.current) return;
|
|
803
|
+
map.off("idle", handleIdle);
|
|
804
|
+
performFitBounds(cancelledRef);
|
|
805
|
+
};
|
|
806
|
+
map.once("idle", handleIdle);
|
|
807
|
+
map.addSource(id, sourceConfig);
|
|
808
|
+
sourceAdded.current = true;
|
|
809
|
+
const source = map.getSource(id);
|
|
810
|
+
if (source && map.isSourceLoaded(id)) {
|
|
811
|
+
map.off("sourcedata", handleSourceData);
|
|
812
|
+
map.off("idle", handleIdle);
|
|
813
|
+
performFitBounds(cancelledRef);
|
|
814
|
+
}
|
|
815
|
+
const cleanupListeners = () => {
|
|
816
|
+
cancelledRef.current = true;
|
|
817
|
+
map.off("sourcedata", handleSourceData);
|
|
818
|
+
map.off("idle", handleIdle);
|
|
819
|
+
};
|
|
820
|
+
return () => {
|
|
821
|
+
cleanupListeners();
|
|
822
|
+
if (map && sourceAdded.current) {
|
|
823
|
+
try {
|
|
824
|
+
const style = map.getStyle();
|
|
825
|
+
if (style?.layers) {
|
|
826
|
+
style.layers.forEach((layer) => {
|
|
827
|
+
if ("source" in layer && layer.source === id) {
|
|
828
|
+
if (map.getLayer(layer.id)) {
|
|
829
|
+
map.removeLayer(layer.id);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
if (map.getSource(id)) {
|
|
835
|
+
map.removeSource(id);
|
|
836
|
+
}
|
|
837
|
+
} catch {
|
|
838
|
+
}
|
|
839
|
+
sourceAdded.current = false;
|
|
840
|
+
initialFitDone.current = false;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
} catch (err) {
|
|
844
|
+
console.error(`[maps-react] Failed to add source "${id}":`, err);
|
|
845
|
+
}
|
|
846
|
+
}, [
|
|
847
|
+
map,
|
|
848
|
+
loaded,
|
|
849
|
+
id,
|
|
850
|
+
type,
|
|
851
|
+
tiles,
|
|
852
|
+
url,
|
|
853
|
+
tileSize,
|
|
854
|
+
attribution,
|
|
855
|
+
cluster,
|
|
856
|
+
clusterRadius,
|
|
857
|
+
clusterMaxZoom,
|
|
858
|
+
generateId,
|
|
859
|
+
promoteId,
|
|
860
|
+
performFitBounds
|
|
861
|
+
// stable due to using ref for params
|
|
862
|
+
]);
|
|
863
|
+
React6.useEffect(() => {
|
|
864
|
+
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
865
|
+
const source = map.getSource(id);
|
|
866
|
+
if (!source) return;
|
|
867
|
+
try {
|
|
868
|
+
if (typeof data === "string") {
|
|
869
|
+
source.setData(data);
|
|
870
|
+
} else if (data && typeof data === "object") {
|
|
871
|
+
source.setData(data);
|
|
872
|
+
}
|
|
873
|
+
} catch (err) {
|
|
874
|
+
console.error(`[maps-react] Failed to update source "${id}" data:`, err);
|
|
875
|
+
}
|
|
876
|
+
}, [map, loaded, id, type, data]);
|
|
877
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
878
|
+
};
|
|
879
|
+
Source.displayName = "Source";
|
|
880
|
+
var Marker = React6.forwardRef(
|
|
881
|
+
({
|
|
882
|
+
id,
|
|
883
|
+
coordinates,
|
|
884
|
+
color,
|
|
885
|
+
anchor = "bottom",
|
|
886
|
+
offset,
|
|
887
|
+
rotation,
|
|
888
|
+
draggable = false,
|
|
889
|
+
scale = 1,
|
|
890
|
+
onClick,
|
|
891
|
+
onDrag,
|
|
892
|
+
onDragEnd,
|
|
893
|
+
children
|
|
894
|
+
}, ref) => {
|
|
895
|
+
const { map, loaded } = useMap();
|
|
896
|
+
const markerRef = React6.useRef(null);
|
|
897
|
+
const elementRef = React6.useRef(null);
|
|
898
|
+
const originalLngLatRef = React6.useRef();
|
|
899
|
+
const clickHandlerRef = React6.useRef(null);
|
|
900
|
+
React6.useEffect(() => {
|
|
901
|
+
if (children && !elementRef.current) {
|
|
902
|
+
elementRef.current = document.createElement("div");
|
|
903
|
+
}
|
|
904
|
+
}, [children]);
|
|
905
|
+
React6.useEffect(() => {
|
|
906
|
+
if (!map || !loaded) return;
|
|
907
|
+
const markerOptions = {
|
|
908
|
+
color: children ? void 0 : color,
|
|
909
|
+
anchor,
|
|
910
|
+
draggable,
|
|
911
|
+
scale
|
|
912
|
+
};
|
|
913
|
+
if (offset) {
|
|
914
|
+
markerOptions.offset = offset;
|
|
915
|
+
}
|
|
916
|
+
if (rotation !== void 0) {
|
|
917
|
+
markerOptions.rotation = rotation;
|
|
918
|
+
}
|
|
919
|
+
if (children && elementRef.current) {
|
|
920
|
+
markerOptions.element = elementRef.current;
|
|
921
|
+
}
|
|
922
|
+
const marker = new maplibregl.Marker(markerOptions).setLngLat(coordinates).addTo(map);
|
|
923
|
+
markerRef.current = marker;
|
|
924
|
+
if (ref) {
|
|
925
|
+
if (typeof ref === "function") {
|
|
926
|
+
ref(marker);
|
|
927
|
+
} else {
|
|
928
|
+
ref.current = marker;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (onClick) {
|
|
932
|
+
const element = marker.getElement();
|
|
933
|
+
const handleClick = (e) => {
|
|
934
|
+
e.stopPropagation();
|
|
935
|
+
const lngLat = marker.getLngLat();
|
|
936
|
+
onClick({
|
|
937
|
+
type: "click",
|
|
938
|
+
markerId: id || "",
|
|
939
|
+
lngLat: [lngLat.lng, lngLat.lat],
|
|
940
|
+
originalEvent: e
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
clickHandlerRef.current = handleClick;
|
|
944
|
+
element.addEventListener("click", handleClick);
|
|
945
|
+
}
|
|
946
|
+
if (draggable) {
|
|
947
|
+
marker.on("dragstart", () => {
|
|
948
|
+
const lngLat = marker.getLngLat();
|
|
949
|
+
originalLngLatRef.current = [lngLat.lng, lngLat.lat];
|
|
950
|
+
});
|
|
951
|
+
marker.on("drag", () => {
|
|
952
|
+
if (onDrag) {
|
|
953
|
+
const lngLat = marker.getLngLat();
|
|
954
|
+
onDrag({
|
|
955
|
+
type: "drag",
|
|
956
|
+
markerId: id || "",
|
|
957
|
+
lngLat: [lngLat.lng, lngLat.lat],
|
|
958
|
+
originalLngLat: originalLngLatRef.current
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
marker.on("dragend", () => {
|
|
963
|
+
if (onDragEnd) {
|
|
964
|
+
const lngLat = marker.getLngLat();
|
|
965
|
+
onDragEnd({
|
|
966
|
+
type: "dragend",
|
|
967
|
+
markerId: id || "",
|
|
968
|
+
lngLat: [lngLat.lng, lngLat.lat],
|
|
969
|
+
originalLngLat: originalLngLatRef.current
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
return () => {
|
|
975
|
+
if (clickHandlerRef.current) {
|
|
976
|
+
marker.getElement().removeEventListener("click", clickHandlerRef.current);
|
|
977
|
+
clickHandlerRef.current = null;
|
|
978
|
+
}
|
|
979
|
+
marker.remove();
|
|
980
|
+
markerRef.current = null;
|
|
981
|
+
};
|
|
982
|
+
}, [map, loaded]);
|
|
983
|
+
React6.useEffect(() => {
|
|
984
|
+
if (markerRef.current) {
|
|
985
|
+
markerRef.current.setLngLat(coordinates);
|
|
986
|
+
}
|
|
987
|
+
}, [coordinates]);
|
|
988
|
+
React6.useEffect(() => {
|
|
989
|
+
if (markerRef.current) {
|
|
990
|
+
markerRef.current.setDraggable(draggable);
|
|
991
|
+
}
|
|
992
|
+
}, [draggable]);
|
|
993
|
+
React6.useEffect(() => {
|
|
994
|
+
if (markerRef.current && rotation !== void 0) {
|
|
995
|
+
markerRef.current.setRotation(rotation);
|
|
996
|
+
}
|
|
997
|
+
}, [rotation]);
|
|
998
|
+
if (children && elementRef.current) {
|
|
999
|
+
return ReactDOM.createPortal(children, elementRef.current);
|
|
1000
|
+
}
|
|
1001
|
+
return null;
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
Marker.displayName = "Marker";
|
|
1005
|
+
function normalizePadding(padding) {
|
|
1006
|
+
if (typeof padding === "number") {
|
|
1007
|
+
return { top: padding, right: padding, bottom: padding, left: padding };
|
|
1008
|
+
}
|
|
1009
|
+
return padding;
|
|
1010
|
+
}
|
|
1011
|
+
function prefersReducedMotion() {
|
|
1012
|
+
if (typeof window === "undefined") return false;
|
|
1013
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1014
|
+
}
|
|
1015
|
+
function panToFitPopup(map, popup, padding) {
|
|
1016
|
+
const popupEl = popup.getElement();
|
|
1017
|
+
if (!popupEl) return;
|
|
1018
|
+
const mapContainer = map.getContainer();
|
|
1019
|
+
const mapRect = mapContainer.getBoundingClientRect();
|
|
1020
|
+
const popupRect = popupEl.getBoundingClientRect();
|
|
1021
|
+
let dx = 0;
|
|
1022
|
+
let dy = 0;
|
|
1023
|
+
if (popupRect.left < mapRect.left + padding.left) {
|
|
1024
|
+
dx = popupRect.left - mapRect.left - padding.left;
|
|
1025
|
+
} else if (popupRect.right > mapRect.right - padding.right) {
|
|
1026
|
+
dx = popupRect.right - mapRect.right + padding.right;
|
|
1027
|
+
}
|
|
1028
|
+
if (popupRect.top < mapRect.top + padding.top) {
|
|
1029
|
+
dy = popupRect.top - mapRect.top - padding.top;
|
|
1030
|
+
} else if (popupRect.bottom > mapRect.bottom - padding.bottom) {
|
|
1031
|
+
dy = popupRect.bottom - mapRect.bottom + padding.bottom;
|
|
1032
|
+
}
|
|
1033
|
+
if (dx !== 0 || dy !== 0) {
|
|
1034
|
+
map.panBy([dx, dy], {
|
|
1035
|
+
animate: !prefersReducedMotion()
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
var Popup = React6.forwardRef(
|
|
1040
|
+
({
|
|
1041
|
+
coordinates,
|
|
1042
|
+
closeButton = true,
|
|
1043
|
+
closeOnClick = true,
|
|
1044
|
+
closeOnMove = false,
|
|
1045
|
+
anchor,
|
|
1046
|
+
offset,
|
|
1047
|
+
maxWidth = "300px",
|
|
1048
|
+
focusAfterOpen = true,
|
|
1049
|
+
autoPan = true,
|
|
1050
|
+
autoPanPadding = 50,
|
|
1051
|
+
open = true,
|
|
1052
|
+
onOpen,
|
|
1053
|
+
onClose,
|
|
1054
|
+
children
|
|
1055
|
+
}, ref) => {
|
|
1056
|
+
const { map, loaded } = useMap();
|
|
1057
|
+
const popupRef = React6.useRef(null);
|
|
1058
|
+
const containerRef = React6.useRef(null);
|
|
1059
|
+
if (!containerRef.current) {
|
|
1060
|
+
containerRef.current = document.createElement("div");
|
|
1061
|
+
containerRef.current.className = "maplibregl-popup-content-wrapper";
|
|
1062
|
+
}
|
|
1063
|
+
const [contentReady, setContentReady] = React6.useState(false);
|
|
1064
|
+
const contentCallbackRef = React6.useCallback((node) => {
|
|
1065
|
+
if (node && containerRef.current) {
|
|
1066
|
+
setContentReady(true);
|
|
1067
|
+
}
|
|
1068
|
+
}, []);
|
|
1069
|
+
React6.useEffect(() => {
|
|
1070
|
+
if (!map || !loaded || !containerRef.current) return;
|
|
1071
|
+
const popup = new maplibregl.Popup({
|
|
1072
|
+
closeButton,
|
|
1073
|
+
closeOnClick,
|
|
1074
|
+
closeOnMove,
|
|
1075
|
+
anchor,
|
|
1076
|
+
offset,
|
|
1077
|
+
maxWidth,
|
|
1078
|
+
focusAfterOpen
|
|
1079
|
+
});
|
|
1080
|
+
popup.setDOMContent(containerRef.current);
|
|
1081
|
+
popupRef.current = popup;
|
|
1082
|
+
if (ref) {
|
|
1083
|
+
if (typeof ref === "function") {
|
|
1084
|
+
ref(popup);
|
|
1085
|
+
} else {
|
|
1086
|
+
ref.current = popup;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
popup.on("open", () => {
|
|
1090
|
+
onOpen?.({
|
|
1091
|
+
type: "open",
|
|
1092
|
+
lngLat: coordinates
|
|
1093
|
+
});
|
|
1094
|
+
});
|
|
1095
|
+
popup.on("close", () => {
|
|
1096
|
+
onClose?.({
|
|
1097
|
+
type: "close",
|
|
1098
|
+
lngLat: coordinates
|
|
1099
|
+
});
|
|
1100
|
+
});
|
|
1101
|
+
return () => {
|
|
1102
|
+
popup.remove();
|
|
1103
|
+
popupRef.current = null;
|
|
1104
|
+
};
|
|
1105
|
+
}, [
|
|
1106
|
+
map,
|
|
1107
|
+
loaded,
|
|
1108
|
+
closeButton,
|
|
1109
|
+
closeOnClick,
|
|
1110
|
+
closeOnMove,
|
|
1111
|
+
anchor,
|
|
1112
|
+
offset,
|
|
1113
|
+
maxWidth,
|
|
1114
|
+
focusAfterOpen,
|
|
1115
|
+
ref,
|
|
1116
|
+
onOpen,
|
|
1117
|
+
onClose,
|
|
1118
|
+
coordinates
|
|
1119
|
+
]);
|
|
1120
|
+
React6.useEffect(() => {
|
|
1121
|
+
if (popupRef.current) {
|
|
1122
|
+
popupRef.current.setLngLat(coordinates);
|
|
1123
|
+
}
|
|
1124
|
+
}, [coordinates]);
|
|
1125
|
+
React6.useEffect(() => {
|
|
1126
|
+
if (!map || !popupRef.current || !contentReady) return;
|
|
1127
|
+
if (open) {
|
|
1128
|
+
popupRef.current.setLngLat(coordinates).addTo(map);
|
|
1129
|
+
if (autoPan) {
|
|
1130
|
+
requestAnimationFrame(() => {
|
|
1131
|
+
if (popupRef.current && map) {
|
|
1132
|
+
panToFitPopup(map, popupRef.current, normalizePadding(autoPanPadding));
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
} else {
|
|
1137
|
+
popupRef.current.remove();
|
|
1138
|
+
}
|
|
1139
|
+
}, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
|
|
1140
|
+
return ReactDOM.createPortal(
|
|
1141
|
+
/* @__PURE__ */ jsx("div", { ref: contentCallbackRef, children }),
|
|
1142
|
+
containerRef.current
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
);
|
|
1146
|
+
Popup.displayName = "Popup";
|
|
1147
|
+
var PopupCard = React6.forwardRef(
|
|
1148
|
+
({ className, children, ...props }, ref) => {
|
|
1149
|
+
return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
|
|
1150
|
+
}
|
|
1151
|
+
);
|
|
1152
|
+
PopupCard.displayName = "PopupCard";
|
|
1153
|
+
var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0", {
|
|
1154
|
+
variants: {
|
|
1155
|
+
badgeVariant: {
|
|
1156
|
+
default: "bg-primary text-primary-foreground",
|
|
1157
|
+
secondary: "bg-secondary text-secondary-foreground",
|
|
1158
|
+
success: "bg-success text-success-foreground",
|
|
1159
|
+
warning: "bg-warning text-warning-foreground",
|
|
1160
|
+
info: "bg-info text-info-foreground"
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
defaultVariants: {
|
|
1164
|
+
badgeVariant: "secondary"
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
var PopupHeader = React6.forwardRef(
|
|
1168
|
+
({ className, title, badge, badgeVariant, ...props }, ref) => {
|
|
1169
|
+
return /* @__PURE__ */ jsxs(
|
|
1170
|
+
"div",
|
|
1171
|
+
{
|
|
1172
|
+
ref,
|
|
1173
|
+
className: cn(
|
|
1174
|
+
"flex items-start justify-between gap-2 border-b border-black dark:border-gray-400 bg-muted/30 px-4 py-3 pr-12",
|
|
1175
|
+
className
|
|
1176
|
+
),
|
|
1177
|
+
...props,
|
|
1178
|
+
children: [
|
|
1179
|
+
/* @__PURE__ */ jsx("h3", { className: "font-semibold text-sm leading-tight", children: title }),
|
|
1180
|
+
badge && /* @__PURE__ */ jsx("span", { className: cn(badgeVariants({ badgeVariant })), children: badge })
|
|
1181
|
+
]
|
|
1182
|
+
}
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1186
|
+
PopupHeader.displayName = "PopupHeader";
|
|
1187
|
+
var PopupContent = React6.forwardRef(
|
|
1188
|
+
({ className, children, ...props }, ref) => {
|
|
1189
|
+
return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
|
|
1190
|
+
}
|
|
1191
|
+
);
|
|
1192
|
+
PopupContent.displayName = "PopupContent";
|
|
1193
|
+
var PopupFooter = React6.forwardRef(
|
|
1194
|
+
({ className, children, ...props }, ref) => {
|
|
1195
|
+
return /* @__PURE__ */ jsx(
|
|
1196
|
+
"div",
|
|
1197
|
+
{
|
|
1198
|
+
ref,
|
|
1199
|
+
className: cn(
|
|
1200
|
+
"flex justify-end gap-2 border-t border-black dark:border-gray-400 bg-muted/30 px-4 py-3",
|
|
1201
|
+
className
|
|
1202
|
+
),
|
|
1203
|
+
...props,
|
|
1204
|
+
children
|
|
1205
|
+
}
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
);
|
|
1209
|
+
PopupFooter.displayName = "PopupFooter";
|
|
1210
|
+
function useLayer({
|
|
1211
|
+
id,
|
|
1212
|
+
source,
|
|
1213
|
+
sourceLayer,
|
|
1214
|
+
type,
|
|
1215
|
+
visible = true,
|
|
1216
|
+
opacity: _opacity,
|
|
1217
|
+
minZoom,
|
|
1218
|
+
maxZoom,
|
|
1219
|
+
filter,
|
|
1220
|
+
beforeId,
|
|
1221
|
+
paint = {},
|
|
1222
|
+
layout = {},
|
|
1223
|
+
onClick,
|
|
1224
|
+
onHover,
|
|
1225
|
+
hoverThrottleMs = 0
|
|
1226
|
+
}) {
|
|
1227
|
+
const { map, loaded } = useMap();
|
|
1228
|
+
const [layerAdded, setLayerAdded] = React6.useState(false);
|
|
1229
|
+
const hoveredFeatureId = React6.useRef(null);
|
|
1230
|
+
const lastHoverCallTime = React6.useRef(0);
|
|
1231
|
+
const lastMousePosition = React6.useRef(null);
|
|
1232
|
+
React6.useEffect(() => {
|
|
1233
|
+
if (!map || !loaded) return;
|
|
1234
|
+
if (!map.getSource(source)) {
|
|
1235
|
+
let timeoutId = null;
|
|
1236
|
+
const checkSource = () => {
|
|
1237
|
+
if (map.getSource(source)) {
|
|
1238
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1239
|
+
addLayer();
|
|
1240
|
+
map.off("sourcedata", checkSource);
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
timeoutId = setTimeout(() => {
|
|
1244
|
+
if (!map.getSource(source)) {
|
|
1245
|
+
console.warn(
|
|
1246
|
+
`[maps-react] Layer "${id}" is waiting for source "${source}" which has not been added after 5 seconds. Ensure the Source component with id="${source}" is rendered before or alongside this layer.`
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
}, 5e3);
|
|
1250
|
+
map.on("sourcedata", checkSource);
|
|
1251
|
+
return () => {
|
|
1252
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1253
|
+
map.off("sourcedata", checkSource);
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
addLayer();
|
|
1257
|
+
function addLayer() {
|
|
1258
|
+
if (layerAdded || map.getLayer(id)) {
|
|
1259
|
+
setLayerAdded(true);
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
try {
|
|
1263
|
+
const layerConfig = {
|
|
1264
|
+
id,
|
|
1265
|
+
type,
|
|
1266
|
+
source,
|
|
1267
|
+
paint,
|
|
1268
|
+
layout: {
|
|
1269
|
+
visibility: visible ? "visible" : "none",
|
|
1270
|
+
...layout
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
if (sourceLayer) {
|
|
1274
|
+
layerConfig["source-layer"] = sourceLayer;
|
|
1275
|
+
}
|
|
1276
|
+
if (minZoom !== void 0) {
|
|
1277
|
+
layerConfig.minzoom = minZoom;
|
|
1278
|
+
}
|
|
1279
|
+
if (maxZoom !== void 0) {
|
|
1280
|
+
layerConfig.maxzoom = maxZoom;
|
|
1281
|
+
}
|
|
1282
|
+
if (filter) {
|
|
1283
|
+
layerConfig.filter = filter;
|
|
1284
|
+
}
|
|
1285
|
+
map.addLayer(layerConfig, beforeId);
|
|
1286
|
+
setLayerAdded(true);
|
|
1287
|
+
} catch (err) {
|
|
1288
|
+
console.error(`[maps-react] Failed to add layer "${id}":`, err);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
return () => {
|
|
1292
|
+
if (map && layerAdded) {
|
|
1293
|
+
try {
|
|
1294
|
+
if (map.getLayer(id)) {
|
|
1295
|
+
map.removeLayer(id);
|
|
1296
|
+
}
|
|
1297
|
+
} catch {
|
|
1298
|
+
}
|
|
1299
|
+
setLayerAdded(false);
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, layerAdded]);
|
|
1303
|
+
React6.useEffect(() => {
|
|
1304
|
+
if (!map || !layerAdded) return;
|
|
1305
|
+
try {
|
|
1306
|
+
map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
|
|
1307
|
+
} catch {
|
|
1308
|
+
}
|
|
1309
|
+
}, [map, id, visible, layerAdded]);
|
|
1310
|
+
React6.useEffect(() => {
|
|
1311
|
+
if (!map || !layerAdded) return;
|
|
1312
|
+
try {
|
|
1313
|
+
Object.entries(paint).forEach(([key, value]) => {
|
|
1314
|
+
map.setPaintProperty(id, key, value);
|
|
1315
|
+
});
|
|
1316
|
+
} catch {
|
|
1317
|
+
}
|
|
1318
|
+
}, [map, id, paint, layerAdded]);
|
|
1319
|
+
React6.useEffect(() => {
|
|
1320
|
+
if (!map || !layerAdded || !filter) return;
|
|
1321
|
+
try {
|
|
1322
|
+
map.setFilter(id, filter);
|
|
1323
|
+
} catch {
|
|
1324
|
+
}
|
|
1325
|
+
}, [map, id, filter, layerAdded]);
|
|
1326
|
+
React6.useEffect(() => {
|
|
1327
|
+
if (!map || !layerAdded) return;
|
|
1328
|
+
const createFeatureParams = (e) => {
|
|
1329
|
+
const feature = e.features?.[0];
|
|
1330
|
+
if (!feature) return null;
|
|
1331
|
+
return {
|
|
1332
|
+
feature,
|
|
1333
|
+
featureId: feature.id,
|
|
1334
|
+
layerId: id,
|
|
1335
|
+
sourceId: source,
|
|
1336
|
+
lngLat: [e.lngLat.lng, e.lngLat.lat],
|
|
1337
|
+
point: [e.point.x, e.point.y],
|
|
1338
|
+
originalEvent: e.originalEvent,
|
|
1339
|
+
map
|
|
1340
|
+
};
|
|
1341
|
+
};
|
|
1342
|
+
const handleClick = (e) => {
|
|
1343
|
+
const params = createFeatureParams(e);
|
|
1344
|
+
if (params) {
|
|
1345
|
+
onClick?.({ type: "click", ...params });
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
const handleMouseEnter = (e) => {
|
|
1349
|
+
map.getCanvas().style.cursor = "pointer";
|
|
1350
|
+
lastMousePosition.current = {
|
|
1351
|
+
lngLat: [e.lngLat.lng, e.lngLat.lat],
|
|
1352
|
+
point: [e.point.x, e.point.y]
|
|
1353
|
+
};
|
|
1354
|
+
const feature = e.features?.[0];
|
|
1355
|
+
if (feature?.id !== void 0) {
|
|
1356
|
+
if (hoveredFeatureId.current !== null) {
|
|
1357
|
+
map.setFeatureState(
|
|
1358
|
+
{ source, sourceLayer, id: hoveredFeatureId.current },
|
|
1359
|
+
{ hover: false }
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
hoveredFeatureId.current = feature.id;
|
|
1363
|
+
map.setFeatureState({ source, sourceLayer, id: feature.id }, { hover: true });
|
|
1364
|
+
}
|
|
1365
|
+
const params = createFeatureParams(e);
|
|
1366
|
+
if (params) {
|
|
1367
|
+
onHover?.({ type: "mouseenter", ...params });
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
const handleMouseMove = (e) => {
|
|
1371
|
+
lastMousePosition.current = {
|
|
1372
|
+
lngLat: [e.lngLat.lng, e.lngLat.lat],
|
|
1373
|
+
point: [e.point.x, e.point.y]
|
|
1374
|
+
};
|
|
1375
|
+
const feature = e.features?.[0];
|
|
1376
|
+
const newFeatureId = feature?.id;
|
|
1377
|
+
if (newFeatureId !== hoveredFeatureId.current) {
|
|
1378
|
+
if (hoveredFeatureId.current !== null) {
|
|
1379
|
+
map.setFeatureState(
|
|
1380
|
+
{ source, sourceLayer, id: hoveredFeatureId.current },
|
|
1381
|
+
{ hover: false }
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
if (newFeatureId !== void 0) {
|
|
1385
|
+
hoveredFeatureId.current = newFeatureId;
|
|
1386
|
+
map.setFeatureState({ source, sourceLayer, id: newFeatureId }, { hover: true });
|
|
1387
|
+
const now = Date.now();
|
|
1388
|
+
if (hoverThrottleMs === 0 || now - lastHoverCallTime.current >= hoverThrottleMs) {
|
|
1389
|
+
lastHoverCallTime.current = now;
|
|
1390
|
+
const params = createFeatureParams(e);
|
|
1391
|
+
if (params) {
|
|
1392
|
+
onHover?.({ type: "mousemove", ...params });
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
} else {
|
|
1396
|
+
hoveredFeatureId.current = null;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
const handleMouseLeave = () => {
|
|
1401
|
+
map.getCanvas().style.cursor = "";
|
|
1402
|
+
if (hoveredFeatureId.current !== null) {
|
|
1403
|
+
map.setFeatureState(
|
|
1404
|
+
{ source, sourceLayer, id: hoveredFeatureId.current },
|
|
1405
|
+
{ hover: false }
|
|
1406
|
+
);
|
|
1407
|
+
hoveredFeatureId.current = null;
|
|
1408
|
+
}
|
|
1409
|
+
const lastPos = lastMousePosition.current;
|
|
1410
|
+
onHover?.({
|
|
1411
|
+
type: "mouseleave",
|
|
1412
|
+
feature: null,
|
|
1413
|
+
layerId: id,
|
|
1414
|
+
sourceId: source,
|
|
1415
|
+
lngLat: lastPos?.lngLat ?? [0, 0],
|
|
1416
|
+
point: lastPos?.point ?? [0, 0],
|
|
1417
|
+
map
|
|
1418
|
+
});
|
|
1419
|
+
lastMousePosition.current = null;
|
|
1420
|
+
};
|
|
1421
|
+
if (onClick) {
|
|
1422
|
+
map.on("click", id, handleClick);
|
|
1423
|
+
}
|
|
1424
|
+
if (onHover) {
|
|
1425
|
+
map.on("mouseenter", id, handleMouseEnter);
|
|
1426
|
+
map.on("mousemove", id, handleMouseMove);
|
|
1427
|
+
map.on("mouseleave", id, handleMouseLeave);
|
|
1428
|
+
}
|
|
1429
|
+
return () => {
|
|
1430
|
+
if (onClick) {
|
|
1431
|
+
map.off("click", id, handleClick);
|
|
1432
|
+
}
|
|
1433
|
+
if (onHover) {
|
|
1434
|
+
map.off("mouseenter", id, handleMouseEnter);
|
|
1435
|
+
map.off("mousemove", id, handleMouseMove);
|
|
1436
|
+
map.off("mouseleave", id, handleMouseLeave);
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
}, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
|
|
1440
|
+
return { layerAdded };
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// src/components/layers/FillLayer.tsx
|
|
1444
|
+
var FillLayer = ({
|
|
1445
|
+
id,
|
|
1446
|
+
source,
|
|
1447
|
+
sourceLayer,
|
|
1448
|
+
visible,
|
|
1449
|
+
opacity,
|
|
1450
|
+
minZoom,
|
|
1451
|
+
maxZoom,
|
|
1452
|
+
filter,
|
|
1453
|
+
beforeId,
|
|
1454
|
+
onClick,
|
|
1455
|
+
onHover,
|
|
1456
|
+
// Fill-specific props
|
|
1457
|
+
fillColor,
|
|
1458
|
+
fillOpacity,
|
|
1459
|
+
fillOutlineColor,
|
|
1460
|
+
fillPattern,
|
|
1461
|
+
fillTranslate,
|
|
1462
|
+
fillAntialias
|
|
1463
|
+
}) => {
|
|
1464
|
+
const paint = {};
|
|
1465
|
+
const layout = {};
|
|
1466
|
+
if (fillColor !== void 0) paint["fill-color"] = fillColor;
|
|
1467
|
+
if (fillOpacity !== void 0) paint["fill-opacity"] = fillOpacity;
|
|
1468
|
+
if (fillOutlineColor !== void 0) paint["fill-outline-color"] = fillOutlineColor;
|
|
1469
|
+
if (fillPattern !== void 0) paint["fill-pattern"] = fillPattern;
|
|
1470
|
+
if (fillTranslate !== void 0) paint["fill-translate"] = fillTranslate;
|
|
1471
|
+
if (fillAntialias !== void 0) paint["fill-antialias"] = fillAntialias;
|
|
1472
|
+
if (opacity !== void 0 && fillOpacity === void 0) {
|
|
1473
|
+
paint["fill-opacity"] = opacity;
|
|
1474
|
+
}
|
|
1475
|
+
useLayer({
|
|
1476
|
+
id,
|
|
1477
|
+
source,
|
|
1478
|
+
sourceLayer,
|
|
1479
|
+
type: "fill",
|
|
1480
|
+
visible,
|
|
1481
|
+
opacity,
|
|
1482
|
+
minZoom,
|
|
1483
|
+
maxZoom,
|
|
1484
|
+
filter,
|
|
1485
|
+
beforeId,
|
|
1486
|
+
paint,
|
|
1487
|
+
layout,
|
|
1488
|
+
onClick,
|
|
1489
|
+
onHover
|
|
1490
|
+
});
|
|
1491
|
+
return null;
|
|
1492
|
+
};
|
|
1493
|
+
FillLayer.displayName = "FillLayer";
|
|
1494
|
+
|
|
1495
|
+
// src/components/layers/LineLayer.tsx
|
|
1496
|
+
var LineLayer = ({
|
|
1497
|
+
id,
|
|
1498
|
+
source,
|
|
1499
|
+
sourceLayer,
|
|
1500
|
+
visible,
|
|
1501
|
+
opacity,
|
|
1502
|
+
minZoom,
|
|
1503
|
+
maxZoom,
|
|
1504
|
+
filter,
|
|
1505
|
+
beforeId,
|
|
1506
|
+
onClick,
|
|
1507
|
+
onHover,
|
|
1508
|
+
// Line-specific props
|
|
1509
|
+
lineColor,
|
|
1510
|
+
lineWidth,
|
|
1511
|
+
lineOpacity,
|
|
1512
|
+
lineBlur,
|
|
1513
|
+
lineCap,
|
|
1514
|
+
lineJoin,
|
|
1515
|
+
lineDasharray,
|
|
1516
|
+
lineGapWidth,
|
|
1517
|
+
lineOffset,
|
|
1518
|
+
lineGradient
|
|
1519
|
+
}) => {
|
|
1520
|
+
const paint = {};
|
|
1521
|
+
const layout = {};
|
|
1522
|
+
if (lineColor !== void 0) paint["line-color"] = lineColor;
|
|
1523
|
+
if (lineWidth !== void 0) paint["line-width"] = lineWidth;
|
|
1524
|
+
if (lineOpacity !== void 0) paint["line-opacity"] = lineOpacity;
|
|
1525
|
+
if (lineBlur !== void 0) paint["line-blur"] = lineBlur;
|
|
1526
|
+
if (lineDasharray !== void 0) paint["line-dasharray"] = lineDasharray;
|
|
1527
|
+
if (lineGapWidth !== void 0) paint["line-gap-width"] = lineGapWidth;
|
|
1528
|
+
if (lineOffset !== void 0) paint["line-offset"] = lineOffset;
|
|
1529
|
+
if (lineGradient !== void 0) paint["line-gradient"] = lineGradient;
|
|
1530
|
+
if (lineCap !== void 0) layout["line-cap"] = lineCap;
|
|
1531
|
+
if (lineJoin !== void 0) layout["line-join"] = lineJoin;
|
|
1532
|
+
if (opacity !== void 0 && lineOpacity === void 0) {
|
|
1533
|
+
paint["line-opacity"] = opacity;
|
|
1534
|
+
}
|
|
1535
|
+
useLayer({
|
|
1536
|
+
id,
|
|
1537
|
+
source,
|
|
1538
|
+
sourceLayer,
|
|
1539
|
+
type: "line",
|
|
1540
|
+
visible,
|
|
1541
|
+
opacity,
|
|
1542
|
+
minZoom,
|
|
1543
|
+
maxZoom,
|
|
1544
|
+
filter,
|
|
1545
|
+
beforeId,
|
|
1546
|
+
paint,
|
|
1547
|
+
layout,
|
|
1548
|
+
onClick,
|
|
1549
|
+
onHover
|
|
1550
|
+
});
|
|
1551
|
+
return null;
|
|
1552
|
+
};
|
|
1553
|
+
LineLayer.displayName = "LineLayer";
|
|
1554
|
+
|
|
1555
|
+
// src/components/layers/CircleLayer.tsx
|
|
1556
|
+
var CircleLayer = ({
|
|
1557
|
+
id,
|
|
1558
|
+
source,
|
|
1559
|
+
sourceLayer,
|
|
1560
|
+
visible,
|
|
1561
|
+
opacity,
|
|
1562
|
+
minZoom,
|
|
1563
|
+
maxZoom,
|
|
1564
|
+
filter,
|
|
1565
|
+
beforeId,
|
|
1566
|
+
onClick,
|
|
1567
|
+
onHover,
|
|
1568
|
+
// Circle-specific props
|
|
1569
|
+
circleRadius,
|
|
1570
|
+
circleColor,
|
|
1571
|
+
circleOpacity,
|
|
1572
|
+
circleStrokeWidth,
|
|
1573
|
+
circleStrokeColor,
|
|
1574
|
+
circleStrokeOpacity,
|
|
1575
|
+
circleBlur,
|
|
1576
|
+
circlePitchAlignment,
|
|
1577
|
+
circlePitchScale,
|
|
1578
|
+
circleTranslate
|
|
1579
|
+
}) => {
|
|
1580
|
+
const paint = {};
|
|
1581
|
+
const layout = {};
|
|
1582
|
+
if (circleRadius !== void 0) paint["circle-radius"] = circleRadius;
|
|
1583
|
+
if (circleColor !== void 0) paint["circle-color"] = circleColor;
|
|
1584
|
+
if (circleOpacity !== void 0) paint["circle-opacity"] = circleOpacity;
|
|
1585
|
+
if (circleStrokeWidth !== void 0) paint["circle-stroke-width"] = circleStrokeWidth;
|
|
1586
|
+
if (circleStrokeColor !== void 0) paint["circle-stroke-color"] = circleStrokeColor;
|
|
1587
|
+
if (circleStrokeOpacity !== void 0) paint["circle-stroke-opacity"] = circleStrokeOpacity;
|
|
1588
|
+
if (circleBlur !== void 0) paint["circle-blur"] = circleBlur;
|
|
1589
|
+
if (circlePitchAlignment !== void 0) paint["circle-pitch-alignment"] = circlePitchAlignment;
|
|
1590
|
+
if (circlePitchScale !== void 0) paint["circle-pitch-scale"] = circlePitchScale;
|
|
1591
|
+
if (circleTranslate !== void 0) paint["circle-translate"] = circleTranslate;
|
|
1592
|
+
if (opacity !== void 0 && circleOpacity === void 0) {
|
|
1593
|
+
paint["circle-opacity"] = opacity;
|
|
1594
|
+
}
|
|
1595
|
+
useLayer({
|
|
1596
|
+
id,
|
|
1597
|
+
source,
|
|
1598
|
+
sourceLayer,
|
|
1599
|
+
type: "circle",
|
|
1600
|
+
visible,
|
|
1601
|
+
opacity,
|
|
1602
|
+
minZoom,
|
|
1603
|
+
maxZoom,
|
|
1604
|
+
filter,
|
|
1605
|
+
beforeId,
|
|
1606
|
+
paint,
|
|
1607
|
+
layout,
|
|
1608
|
+
onClick,
|
|
1609
|
+
onHover
|
|
1610
|
+
});
|
|
1611
|
+
return null;
|
|
1612
|
+
};
|
|
1613
|
+
CircleLayer.displayName = "CircleLayer";
|
|
1614
|
+
|
|
1615
|
+
// src/components/layers/SymbolLayer.tsx
|
|
1616
|
+
var SymbolLayer = ({
|
|
1617
|
+
id,
|
|
1618
|
+
source,
|
|
1619
|
+
sourceLayer,
|
|
1620
|
+
visible,
|
|
1621
|
+
opacity,
|
|
1622
|
+
minZoom,
|
|
1623
|
+
maxZoom,
|
|
1624
|
+
filter,
|
|
1625
|
+
beforeId,
|
|
1626
|
+
onClick,
|
|
1627
|
+
onHover,
|
|
1628
|
+
// Symbol-specific props
|
|
1629
|
+
iconImage,
|
|
1630
|
+
iconSize,
|
|
1631
|
+
iconRotate,
|
|
1632
|
+
iconOffset,
|
|
1633
|
+
iconAnchor,
|
|
1634
|
+
iconOpacity,
|
|
1635
|
+
iconColor,
|
|
1636
|
+
iconHaloColor,
|
|
1637
|
+
iconHaloWidth,
|
|
1638
|
+
iconAllowOverlap,
|
|
1639
|
+
iconIgnorePlacement,
|
|
1640
|
+
textField,
|
|
1641
|
+
textFont,
|
|
1642
|
+
textSize,
|
|
1643
|
+
textColor,
|
|
1644
|
+
textOpacity,
|
|
1645
|
+
textHaloColor,
|
|
1646
|
+
textHaloWidth,
|
|
1647
|
+
textAnchor,
|
|
1648
|
+
textOffset,
|
|
1649
|
+
textRotate,
|
|
1650
|
+
textAllowOverlap,
|
|
1651
|
+
textIgnorePlacement,
|
|
1652
|
+
symbolPlacement,
|
|
1653
|
+
symbolSpacing,
|
|
1654
|
+
symbolSortKey
|
|
1655
|
+
}) => {
|
|
1656
|
+
const paint = {};
|
|
1657
|
+
const layout = {};
|
|
1658
|
+
if (iconOpacity !== void 0) paint["icon-opacity"] = iconOpacity;
|
|
1659
|
+
if (iconColor !== void 0) paint["icon-color"] = iconColor;
|
|
1660
|
+
if (iconHaloColor !== void 0) paint["icon-halo-color"] = iconHaloColor;
|
|
1661
|
+
if (iconHaloWidth !== void 0) paint["icon-halo-width"] = iconHaloWidth;
|
|
1662
|
+
if (textColor !== void 0) paint["text-color"] = textColor;
|
|
1663
|
+
if (textOpacity !== void 0) paint["text-opacity"] = textOpacity;
|
|
1664
|
+
if (textHaloColor !== void 0) paint["text-halo-color"] = textHaloColor;
|
|
1665
|
+
if (textHaloWidth !== void 0) paint["text-halo-width"] = textHaloWidth;
|
|
1666
|
+
if (iconImage !== void 0) layout["icon-image"] = iconImage;
|
|
1667
|
+
if (iconSize !== void 0) layout["icon-size"] = iconSize;
|
|
1668
|
+
if (iconRotate !== void 0) layout["icon-rotate"] = iconRotate;
|
|
1669
|
+
if (iconOffset !== void 0) layout["icon-offset"] = iconOffset;
|
|
1670
|
+
if (iconAnchor !== void 0) layout["icon-anchor"] = iconAnchor;
|
|
1671
|
+
if (iconAllowOverlap !== void 0) layout["icon-allow-overlap"] = iconAllowOverlap;
|
|
1672
|
+
if (iconIgnorePlacement !== void 0) layout["icon-ignore-placement"] = iconIgnorePlacement;
|
|
1673
|
+
if (textField !== void 0) layout["text-field"] = textField;
|
|
1674
|
+
if (textFont !== void 0) layout["text-font"] = textFont;
|
|
1675
|
+
if (textSize !== void 0) layout["text-size"] = textSize;
|
|
1676
|
+
if (textAnchor !== void 0) layout["text-anchor"] = textAnchor;
|
|
1677
|
+
if (textOffset !== void 0) layout["text-offset"] = textOffset;
|
|
1678
|
+
if (textRotate !== void 0) layout["text-rotate"] = textRotate;
|
|
1679
|
+
if (textAllowOverlap !== void 0) layout["text-allow-overlap"] = textAllowOverlap;
|
|
1680
|
+
if (textIgnorePlacement !== void 0) layout["text-ignore-placement"] = textIgnorePlacement;
|
|
1681
|
+
if (symbolPlacement !== void 0) layout["symbol-placement"] = symbolPlacement;
|
|
1682
|
+
if (symbolSpacing !== void 0) layout["symbol-spacing"] = symbolSpacing;
|
|
1683
|
+
if (symbolSortKey !== void 0) layout["symbol-sort-key"] = symbolSortKey;
|
|
1684
|
+
useLayer({
|
|
1685
|
+
id,
|
|
1686
|
+
source,
|
|
1687
|
+
sourceLayer,
|
|
1688
|
+
type: "symbol",
|
|
1689
|
+
visible,
|
|
1690
|
+
opacity,
|
|
1691
|
+
minZoom,
|
|
1692
|
+
maxZoom,
|
|
1693
|
+
filter,
|
|
1694
|
+
beforeId,
|
|
1695
|
+
paint,
|
|
1696
|
+
layout,
|
|
1697
|
+
onClick,
|
|
1698
|
+
onHover
|
|
1699
|
+
});
|
|
1700
|
+
return null;
|
|
1701
|
+
};
|
|
1702
|
+
SymbolLayer.displayName = "SymbolLayer";
|
|
1703
|
+
|
|
1704
|
+
// src/components/layers/FillExtrusionLayer.tsx
|
|
1705
|
+
var FillExtrusionLayer = ({
|
|
1706
|
+
id,
|
|
1707
|
+
source,
|
|
1708
|
+
sourceLayer,
|
|
1709
|
+
visible,
|
|
1710
|
+
opacity,
|
|
1711
|
+
minZoom,
|
|
1712
|
+
maxZoom,
|
|
1713
|
+
filter,
|
|
1714
|
+
beforeId,
|
|
1715
|
+
onClick,
|
|
1716
|
+
onHover,
|
|
1717
|
+
// Fill extrusion-specific props
|
|
1718
|
+
fillExtrusionHeight,
|
|
1719
|
+
fillExtrusionBase,
|
|
1720
|
+
fillExtrusionColor,
|
|
1721
|
+
fillExtrusionOpacity,
|
|
1722
|
+
fillExtrusionPattern,
|
|
1723
|
+
fillExtrusionTranslate,
|
|
1724
|
+
fillExtrusionVerticalGradient
|
|
1725
|
+
}) => {
|
|
1726
|
+
const paint = {};
|
|
1727
|
+
const layout = {};
|
|
1728
|
+
if (fillExtrusionHeight !== void 0) paint["fill-extrusion-height"] = fillExtrusionHeight;
|
|
1729
|
+
if (fillExtrusionBase !== void 0) paint["fill-extrusion-base"] = fillExtrusionBase;
|
|
1730
|
+
if (fillExtrusionColor !== void 0) paint["fill-extrusion-color"] = fillExtrusionColor;
|
|
1731
|
+
if (fillExtrusionOpacity !== void 0) paint["fill-extrusion-opacity"] = fillExtrusionOpacity;
|
|
1732
|
+
if (fillExtrusionPattern !== void 0) paint["fill-extrusion-pattern"] = fillExtrusionPattern;
|
|
1733
|
+
if (fillExtrusionTranslate !== void 0)
|
|
1734
|
+
paint["fill-extrusion-translate"] = fillExtrusionTranslate;
|
|
1735
|
+
if (fillExtrusionVerticalGradient !== void 0) {
|
|
1736
|
+
paint["fill-extrusion-vertical-gradient"] = fillExtrusionVerticalGradient;
|
|
1737
|
+
}
|
|
1738
|
+
if (opacity !== void 0 && fillExtrusionOpacity === void 0) {
|
|
1739
|
+
paint["fill-extrusion-opacity"] = opacity;
|
|
1740
|
+
}
|
|
1741
|
+
useLayer({
|
|
1742
|
+
id,
|
|
1743
|
+
source,
|
|
1744
|
+
sourceLayer,
|
|
1745
|
+
type: "fill-extrusion",
|
|
1746
|
+
visible,
|
|
1747
|
+
opacity,
|
|
1748
|
+
minZoom,
|
|
1749
|
+
maxZoom,
|
|
1750
|
+
filter,
|
|
1751
|
+
beforeId,
|
|
1752
|
+
paint,
|
|
1753
|
+
layout,
|
|
1754
|
+
onClick,
|
|
1755
|
+
onHover
|
|
1756
|
+
});
|
|
1757
|
+
return null;
|
|
1758
|
+
};
|
|
1759
|
+
FillExtrusionLayer.displayName = "FillExtrusionLayer";
|
|
1760
|
+
|
|
1761
|
+
// src/components/layers/HeatmapLayer.tsx
|
|
1762
|
+
var HeatmapLayer = ({
|
|
1763
|
+
id,
|
|
1764
|
+
source,
|
|
1765
|
+
sourceLayer,
|
|
1766
|
+
visible,
|
|
1767
|
+
opacity,
|
|
1768
|
+
minZoom,
|
|
1769
|
+
maxZoom,
|
|
1770
|
+
filter,
|
|
1771
|
+
beforeId,
|
|
1772
|
+
onClick,
|
|
1773
|
+
onHover,
|
|
1774
|
+
// Heatmap-specific props
|
|
1775
|
+
heatmapIntensity,
|
|
1776
|
+
heatmapWeight,
|
|
1777
|
+
heatmapColor,
|
|
1778
|
+
heatmapRadius,
|
|
1779
|
+
heatmapOpacity
|
|
1780
|
+
}) => {
|
|
1781
|
+
const paint = {};
|
|
1782
|
+
const layout = {};
|
|
1783
|
+
if (heatmapIntensity !== void 0) paint["heatmap-intensity"] = heatmapIntensity;
|
|
1784
|
+
if (heatmapWeight !== void 0) paint["heatmap-weight"] = heatmapWeight;
|
|
1785
|
+
if (heatmapColor !== void 0) paint["heatmap-color"] = heatmapColor;
|
|
1786
|
+
if (heatmapRadius !== void 0) paint["heatmap-radius"] = heatmapRadius;
|
|
1787
|
+
if (heatmapOpacity !== void 0) paint["heatmap-opacity"] = heatmapOpacity;
|
|
1788
|
+
if (opacity !== void 0 && heatmapOpacity === void 0) {
|
|
1789
|
+
paint["heatmap-opacity"] = opacity;
|
|
1790
|
+
}
|
|
1791
|
+
useLayer({
|
|
1792
|
+
id,
|
|
1793
|
+
source,
|
|
1794
|
+
sourceLayer,
|
|
1795
|
+
type: "heatmap",
|
|
1796
|
+
visible,
|
|
1797
|
+
opacity,
|
|
1798
|
+
minZoom,
|
|
1799
|
+
maxZoom,
|
|
1800
|
+
filter,
|
|
1801
|
+
beforeId,
|
|
1802
|
+
paint,
|
|
1803
|
+
layout,
|
|
1804
|
+
onClick,
|
|
1805
|
+
onHover
|
|
1806
|
+
});
|
|
1807
|
+
return null;
|
|
1808
|
+
};
|
|
1809
|
+
HeatmapLayer.displayName = "HeatmapLayer";
|
|
1810
|
+
var legendIdCounter = 0;
|
|
1811
|
+
var Legend = ({
|
|
1812
|
+
title,
|
|
1813
|
+
position = "bottom-left",
|
|
1814
|
+
type = "categorical",
|
|
1815
|
+
items = [],
|
|
1816
|
+
gradient = [],
|
|
1817
|
+
minLabel,
|
|
1818
|
+
maxLabel,
|
|
1819
|
+
collapsible = false,
|
|
1820
|
+
collapsed: initialCollapsed = false,
|
|
1821
|
+
class: className,
|
|
1822
|
+
onItemClick
|
|
1823
|
+
}) => {
|
|
1824
|
+
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
1825
|
+
const [isCollapsed, setIsCollapsed] = React6.useState(initialCollapsed);
|
|
1826
|
+
const [customControlOffset, setCustomControlOffset] = React6.useState(0);
|
|
1827
|
+
const legendRef = React6.useRef(null);
|
|
1828
|
+
const legendIdRef = React6.useRef(`legend-${++legendIdCounter}`);
|
|
1829
|
+
React6.useEffect(() => {
|
|
1830
|
+
if (!legendRef.current || !registerControl) return;
|
|
1831
|
+
const updatePosition = () => {
|
|
1832
|
+
if (!legendRef.current) return;
|
|
1833
|
+
const height = legendRef.current.offsetHeight;
|
|
1834
|
+
const offset = registerControl(legendIdRef.current, position, height);
|
|
1835
|
+
setCustomControlOffset(offset);
|
|
1836
|
+
};
|
|
1837
|
+
updatePosition();
|
|
1838
|
+
const observer = new ResizeObserver(updatePosition);
|
|
1839
|
+
observer.observe(legendRef.current);
|
|
1840
|
+
return () => {
|
|
1841
|
+
observer.disconnect();
|
|
1842
|
+
unregisterControl?.(legendIdRef.current, position);
|
|
1843
|
+
};
|
|
1844
|
+
}, [position, registerControl, unregisterControl]);
|
|
1845
|
+
const verticalOffsetStyle = React6.useMemo(() => {
|
|
1846
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
1847
|
+
}, [customControlOffset, position]);
|
|
1848
|
+
const handleItemClick = (item, index) => {
|
|
1849
|
+
if (onItemClick) {
|
|
1850
|
+
onItemClick(item, index);
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
const toggleCollapse = () => {
|
|
1854
|
+
if (collapsible) {
|
|
1855
|
+
setIsCollapsed(!isCollapsed);
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1858
|
+
const gradientStyle = React6.useMemo(() => {
|
|
1859
|
+
if (type !== "gradient" || gradient.length === 0) return "";
|
|
1860
|
+
const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
1861
|
+
return `linear-gradient(to right, ${stops})`;
|
|
1862
|
+
}, [type, gradient]);
|
|
1863
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
1864
|
+
const computedPositionClasses = React6.useMemo(() => {
|
|
1865
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
1866
|
+
}, [position, hasControlsAtPosition]);
|
|
1867
|
+
return /* @__PURE__ */ jsxs(
|
|
1868
|
+
"div",
|
|
1869
|
+
{
|
|
1870
|
+
ref: legendRef,
|
|
1871
|
+
className: cn(
|
|
1872
|
+
"absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
1873
|
+
"text-sm min-w-[140px] max-w-[280px]",
|
|
1874
|
+
computedPositionClasses,
|
|
1875
|
+
className
|
|
1876
|
+
),
|
|
1877
|
+
style: verticalOffsetStyle,
|
|
1878
|
+
children: [
|
|
1879
|
+
(title || collapsible) && /* @__PURE__ */ jsxs(
|
|
1880
|
+
"button",
|
|
1881
|
+
{
|
|
1882
|
+
type: "button",
|
|
1883
|
+
className: cn(
|
|
1884
|
+
"w-full flex items-center justify-between px-3 py-2 font-medium text-card-foreground",
|
|
1885
|
+
collapsible && "cursor-pointer hover:bg-muted rounded-t-lg",
|
|
1886
|
+
!collapsible && "cursor-default"
|
|
1887
|
+
),
|
|
1888
|
+
onClick: toggleCollapse,
|
|
1889
|
+
disabled: !collapsible,
|
|
1890
|
+
children: [
|
|
1891
|
+
/* @__PURE__ */ jsx("span", { children: title || "Legend" }),
|
|
1892
|
+
collapsible && /* @__PURE__ */ jsx(
|
|
1893
|
+
"svg",
|
|
1894
|
+
{
|
|
1895
|
+
className: cn("w-4 h-4 transition-transform", isCollapsed && "-rotate-90"),
|
|
1896
|
+
fill: "none",
|
|
1897
|
+
viewBox: "0 0 24 24",
|
|
1898
|
+
stroke: "currentColor",
|
|
1899
|
+
children: /* @__PURE__ */ jsx(
|
|
1900
|
+
"path",
|
|
1901
|
+
{
|
|
1902
|
+
strokeLinecap: "round",
|
|
1903
|
+
strokeLinejoin: "round",
|
|
1904
|
+
strokeWidth: 2,
|
|
1905
|
+
d: "M19 9l-7 7-7-7"
|
|
1906
|
+
}
|
|
1907
|
+
)
|
|
1908
|
+
}
|
|
1909
|
+
)
|
|
1910
|
+
]
|
|
1911
|
+
}
|
|
1912
|
+
),
|
|
1913
|
+
!isCollapsed && /* @__PURE__ */ jsxs("div", { className: cn("px-3 pb-3", (title || collapsible) && "pt-1"), children: [
|
|
1914
|
+
type === "categorical" && items.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1.5", children: items.map((item, index) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
1915
|
+
"button",
|
|
1916
|
+
{
|
|
1917
|
+
type: "button",
|
|
1918
|
+
className: cn(
|
|
1919
|
+
"flex items-center gap-2 w-full text-left rounded px-1 -mx-1",
|
|
1920
|
+
onItemClick && "hover:bg-muted cursor-pointer",
|
|
1921
|
+
!onItemClick && "cursor-default",
|
|
1922
|
+
item.active === false && "opacity-50"
|
|
1923
|
+
),
|
|
1924
|
+
onClick: () => handleItemClick(item, index),
|
|
1925
|
+
disabled: !onItemClick,
|
|
1926
|
+
children: [
|
|
1927
|
+
/* @__PURE__ */ jsx(
|
|
1928
|
+
"span",
|
|
1929
|
+
{
|
|
1930
|
+
className: "w-4 h-4 rounded flex-shrink-0",
|
|
1931
|
+
style: { backgroundColor: item.color }
|
|
1932
|
+
}
|
|
1933
|
+
),
|
|
1934
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground truncate flex-1", children: item.label }),
|
|
1935
|
+
item.value !== void 0 && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: item.value })
|
|
1936
|
+
]
|
|
1937
|
+
}
|
|
1938
|
+
) }, index)) }),
|
|
1939
|
+
type === "gradient" && gradient.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
1940
|
+
/* @__PURE__ */ jsx("div", { className: "h-3 rounded-sm", style: { background: gradientStyle } }),
|
|
1941
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between text-xs text-muted-foreground", children: [
|
|
1942
|
+
/* @__PURE__ */ jsx("span", { children: minLabel || gradient[0]?.label || "" }),
|
|
1943
|
+
/* @__PURE__ */ jsx("span", { children: maxLabel || gradient[gradient.length - 1]?.label || "" })
|
|
1944
|
+
] })
|
|
1945
|
+
] })
|
|
1946
|
+
] })
|
|
1947
|
+
]
|
|
1948
|
+
}
|
|
1949
|
+
);
|
|
1950
|
+
};
|
|
1951
|
+
Legend.displayName = "Legend";
|
|
1952
|
+
var legendGroupIdCounter = 0;
|
|
1953
|
+
var LegendGroup = ({
|
|
1954
|
+
legends,
|
|
1955
|
+
position = "bottom-left",
|
|
1956
|
+
defaultExpanded,
|
|
1957
|
+
expanded: controlledExpanded,
|
|
1958
|
+
onExpandedChange,
|
|
1959
|
+
allowCollapseAll = false,
|
|
1960
|
+
class: className
|
|
1961
|
+
}) => {
|
|
1962
|
+
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
1963
|
+
const containerRef = React6.useRef(null);
|
|
1964
|
+
const groupIdRef = React6.useRef(`legend-group-${++legendGroupIdCounter}`);
|
|
1965
|
+
const [customControlOffset, setCustomControlOffset] = React6.useState(0);
|
|
1966
|
+
const getInitialExpanded = () => {
|
|
1967
|
+
if (controlledExpanded !== void 0) return controlledExpanded;
|
|
1968
|
+
if (defaultExpanded) return defaultExpanded;
|
|
1969
|
+
return legends[0]?.id || null;
|
|
1970
|
+
};
|
|
1971
|
+
const [internalExpanded, setInternalExpanded] = React6.useState(getInitialExpanded);
|
|
1972
|
+
const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
|
|
1973
|
+
const handleToggle = (id) => {
|
|
1974
|
+
const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
|
|
1975
|
+
if (controlledExpanded === void 0) {
|
|
1976
|
+
setInternalExpanded(newExpanded);
|
|
1977
|
+
}
|
|
1978
|
+
onExpandedChange?.(newExpanded);
|
|
1979
|
+
};
|
|
1980
|
+
React6.useEffect(() => {
|
|
1981
|
+
if (!containerRef.current || !registerControl) return;
|
|
1982
|
+
const timeoutId = setTimeout(() => {
|
|
1983
|
+
if (containerRef.current) {
|
|
1984
|
+
const height = containerRef.current.offsetHeight;
|
|
1985
|
+
const offset = registerControl(groupIdRef.current, position, height);
|
|
1986
|
+
setCustomControlOffset(offset);
|
|
1987
|
+
}
|
|
1988
|
+
}, 50);
|
|
1989
|
+
return () => {
|
|
1990
|
+
clearTimeout(timeoutId);
|
|
1991
|
+
unregisterControl?.(groupIdRef.current, position);
|
|
1992
|
+
};
|
|
1993
|
+
}, [position, expandedId, registerControl, unregisterControl]);
|
|
1994
|
+
const verticalOffsetStyle = React6.useMemo(() => {
|
|
1995
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
1996
|
+
}, [customControlOffset, position]);
|
|
1997
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
1998
|
+
const computedPositionClasses = React6.useMemo(() => {
|
|
1999
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
2000
|
+
}, [position, hasControlsAtPosition]);
|
|
2001
|
+
const getGradientStyle = (legend) => {
|
|
2002
|
+
if (legend.type !== "gradient" || !legend.gradient?.length) return "";
|
|
2003
|
+
const stops = legend.gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
2004
|
+
return `linear-gradient(to right, ${stops})`;
|
|
2005
|
+
};
|
|
2006
|
+
const handleItemClick = (legend, item, index) => {
|
|
2007
|
+
legend.onItemClick?.(item, index);
|
|
2008
|
+
};
|
|
2009
|
+
return /* @__PURE__ */ jsx(
|
|
2010
|
+
"div",
|
|
2011
|
+
{
|
|
2012
|
+
ref: containerRef,
|
|
2013
|
+
className: cn(
|
|
2014
|
+
"absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2015
|
+
"text-sm min-w-[160px] max-w-[280px]",
|
|
2016
|
+
computedPositionClasses,
|
|
2017
|
+
className
|
|
2018
|
+
),
|
|
2019
|
+
style: verticalOffsetStyle,
|
|
2020
|
+
children: legends.map((legend, legendIndex) => {
|
|
2021
|
+
const isExpanded = expandedId === legend.id;
|
|
2022
|
+
const isFirst = legendIndex === 0;
|
|
2023
|
+
const isLast = legendIndex === legends.length - 1;
|
|
2024
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
2025
|
+
!isFirst && /* @__PURE__ */ jsx("div", { className: "border-t border-border" }),
|
|
2026
|
+
/* @__PURE__ */ jsxs(
|
|
2027
|
+
"button",
|
|
2028
|
+
{
|
|
2029
|
+
type: "button",
|
|
2030
|
+
className: cn(
|
|
2031
|
+
"w-full flex items-center justify-between px-3 py-2 font-medium text-card-foreground",
|
|
2032
|
+
"cursor-pointer hover:bg-muted transition-colors",
|
|
2033
|
+
isFirst && "rounded-t-lg",
|
|
2034
|
+
isLast && !isExpanded && "rounded-b-lg"
|
|
2035
|
+
),
|
|
2036
|
+
onClick: () => handleToggle(legend.id),
|
|
2037
|
+
"aria-expanded": isExpanded,
|
|
2038
|
+
children: [
|
|
2039
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: legend.title }),
|
|
2040
|
+
/* @__PURE__ */ jsx(
|
|
2041
|
+
"svg",
|
|
2042
|
+
{
|
|
2043
|
+
className: cn(
|
|
2044
|
+
"w-4 h-4 transition-transform flex-shrink-0 ml-2",
|
|
2045
|
+
!isExpanded && "-rotate-90"
|
|
2046
|
+
),
|
|
2047
|
+
fill: "none",
|
|
2048
|
+
viewBox: "0 0 24 24",
|
|
2049
|
+
stroke: "currentColor",
|
|
2050
|
+
children: /* @__PURE__ */ jsx(
|
|
2051
|
+
"path",
|
|
2052
|
+
{
|
|
2053
|
+
strokeLinecap: "round",
|
|
2054
|
+
strokeLinejoin: "round",
|
|
2055
|
+
strokeWidth: 2,
|
|
2056
|
+
d: "M19 9l-7 7-7-7"
|
|
2057
|
+
}
|
|
2058
|
+
)
|
|
2059
|
+
}
|
|
2060
|
+
)
|
|
2061
|
+
]
|
|
2062
|
+
}
|
|
2063
|
+
),
|
|
2064
|
+
/* @__PURE__ */ jsx(
|
|
2065
|
+
"div",
|
|
2066
|
+
{
|
|
2067
|
+
className: cn(
|
|
2068
|
+
"overflow-hidden transition-all duration-200",
|
|
2069
|
+
isExpanded ? "max-h-96 opacity-100" : "max-h-0 opacity-0"
|
|
2070
|
+
),
|
|
2071
|
+
children: /* @__PURE__ */ jsxs("div", { className: cn("px-3 pb-3", isLast && "rounded-b-lg"), children: [
|
|
2072
|
+
legend.type !== "gradient" && legend.items && legend.items.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1.5", children: legend.items.map((item, index) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
2073
|
+
"button",
|
|
2074
|
+
{
|
|
2075
|
+
type: "button",
|
|
2076
|
+
className: cn(
|
|
2077
|
+
"flex items-center gap-2 w-full text-left rounded px-1 -mx-1",
|
|
2078
|
+
legend.onItemClick && "hover:bg-muted cursor-pointer",
|
|
2079
|
+
!legend.onItemClick && "cursor-default",
|
|
2080
|
+
item.active === false && "opacity-50"
|
|
2081
|
+
),
|
|
2082
|
+
onClick: () => handleItemClick(legend, item, index),
|
|
2083
|
+
disabled: !legend.onItemClick,
|
|
2084
|
+
children: [
|
|
2085
|
+
/* @__PURE__ */ jsx(
|
|
2086
|
+
"span",
|
|
2087
|
+
{
|
|
2088
|
+
className: "w-4 h-4 rounded flex-shrink-0",
|
|
2089
|
+
style: { backgroundColor: item.color }
|
|
2090
|
+
}
|
|
2091
|
+
),
|
|
2092
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground truncate flex-1", children: item.label }),
|
|
2093
|
+
item.value !== void 0 && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: item.value })
|
|
2094
|
+
]
|
|
2095
|
+
}
|
|
2096
|
+
) }, index)) }),
|
|
2097
|
+
legend.type === "gradient" && legend.gradient && legend.gradient.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2098
|
+
/* @__PURE__ */ jsx(
|
|
2099
|
+
"div",
|
|
2100
|
+
{
|
|
2101
|
+
className: "h-3 rounded-sm",
|
|
2102
|
+
style: { background: getGradientStyle(legend) }
|
|
2103
|
+
}
|
|
2104
|
+
),
|
|
2105
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between text-xs text-muted-foreground", children: [
|
|
2106
|
+
/* @__PURE__ */ jsx("span", { children: legend.minLabel || legend.gradient[0]?.label || "" }),
|
|
2107
|
+
/* @__PURE__ */ jsx("span", { children: legend.maxLabel || legend.gradient[legend.gradient.length - 1]?.label || "" })
|
|
2108
|
+
] })
|
|
2109
|
+
] })
|
|
2110
|
+
] })
|
|
2111
|
+
}
|
|
2112
|
+
)
|
|
2113
|
+
] }, legend.id);
|
|
2114
|
+
})
|
|
2115
|
+
}
|
|
2116
|
+
);
|
|
2117
|
+
};
|
|
2118
|
+
LegendGroup.displayName = "LegendGroup";
|
|
2119
|
+
var coordDisplayIdCounter = 0;
|
|
2120
|
+
var CoordinateDisplay = ({
|
|
2121
|
+
position = "bottom-right",
|
|
2122
|
+
format = "decimal",
|
|
2123
|
+
precision = 5,
|
|
2124
|
+
showZoom = true,
|
|
2125
|
+
showBearing = false,
|
|
2126
|
+
class: className
|
|
2127
|
+
}) => {
|
|
2128
|
+
const { map, loaded, controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2129
|
+
const [cursorLngLat, setCursorLngLat] = React6.useState(null);
|
|
2130
|
+
const [currentZoom, setCurrentZoom] = React6.useState(0);
|
|
2131
|
+
const [currentBearing, setCurrentBearing] = React6.useState(0);
|
|
2132
|
+
const [customControlOffset, setCustomControlOffset] = React6.useState(0);
|
|
2133
|
+
const controlRef = React6.useRef(null);
|
|
2134
|
+
const controlIdRef = React6.useRef(`coord-display-${++coordDisplayIdCounter}`);
|
|
2135
|
+
React6.useEffect(() => {
|
|
2136
|
+
if (!controlRef.current || !registerControl) return;
|
|
2137
|
+
const updatePosition = () => {
|
|
2138
|
+
if (!controlRef.current) return;
|
|
2139
|
+
const height = controlRef.current.offsetHeight;
|
|
2140
|
+
const offset = registerControl(controlIdRef.current, position, height);
|
|
2141
|
+
setCustomControlOffset(offset);
|
|
2142
|
+
};
|
|
2143
|
+
updatePosition();
|
|
2144
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2145
|
+
observer.observe(controlRef.current);
|
|
2146
|
+
return () => {
|
|
2147
|
+
observer.disconnect();
|
|
2148
|
+
unregisterControl?.(controlIdRef.current, position);
|
|
2149
|
+
};
|
|
2150
|
+
}, [position, registerControl, unregisterControl]);
|
|
2151
|
+
const verticalOffsetStyle = React6.useMemo(() => {
|
|
2152
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2153
|
+
}, [customControlOffset, position]);
|
|
2154
|
+
const formatCoord = React6.useCallback(
|
|
2155
|
+
(lngLat) => {
|
|
2156
|
+
return formatCoordinates(lngLat, precision, format);
|
|
2157
|
+
},
|
|
2158
|
+
[format, precision]
|
|
2159
|
+
);
|
|
2160
|
+
const formatZoom = (zoom) => {
|
|
2161
|
+
return zoom.toFixed(1);
|
|
2162
|
+
};
|
|
2163
|
+
const formatBearingValue = (bearing) => {
|
|
2164
|
+
const normalized = (bearing % 360 + 360) % 360;
|
|
2165
|
+
return `${normalized.toFixed(0)}\xB0`;
|
|
2166
|
+
};
|
|
2167
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2168
|
+
const computedPositionClasses = React6.useMemo(() => {
|
|
2169
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
2170
|
+
}, [position, hasControlsAtPosition]);
|
|
2171
|
+
React6.useEffect(() => {
|
|
2172
|
+
if (!map || !loaded) return;
|
|
2173
|
+
setCurrentZoom(map.getZoom());
|
|
2174
|
+
setCurrentBearing(map.getBearing());
|
|
2175
|
+
const handleMouseMove = (e) => {
|
|
2176
|
+
setCursorLngLat([e.lngLat.lng, e.lngLat.lat]);
|
|
2177
|
+
};
|
|
2178
|
+
const handleZoom = () => {
|
|
2179
|
+
setCurrentZoom(map.getZoom());
|
|
2180
|
+
};
|
|
2181
|
+
const handleRotate = () => {
|
|
2182
|
+
setCurrentBearing(map.getBearing());
|
|
2183
|
+
};
|
|
2184
|
+
map.on("mousemove", handleMouseMove);
|
|
2185
|
+
map.on("zoom", handleZoom);
|
|
2186
|
+
map.on("rotate", handleRotate);
|
|
2187
|
+
return () => {
|
|
2188
|
+
map.off("mousemove", handleMouseMove);
|
|
2189
|
+
map.off("zoom", handleZoom);
|
|
2190
|
+
map.off("rotate", handleRotate);
|
|
2191
|
+
};
|
|
2192
|
+
}, [map, loaded]);
|
|
2193
|
+
return /* @__PURE__ */ jsxs(
|
|
2194
|
+
"div",
|
|
2195
|
+
{
|
|
2196
|
+
ref: controlRef,
|
|
2197
|
+
className: cn(
|
|
2198
|
+
"absolute z-10 bg-card rounded px-2 py-1",
|
|
2199
|
+
"text-xs font-mono text-muted-foreground",
|
|
2200
|
+
"border border-black dark:border-gray-400 shadow-sm",
|
|
2201
|
+
"flex items-center gap-3",
|
|
2202
|
+
computedPositionClasses,
|
|
2203
|
+
className
|
|
2204
|
+
),
|
|
2205
|
+
style: verticalOffsetStyle,
|
|
2206
|
+
children: [
|
|
2207
|
+
cursorLngLat ? /* @__PURE__ */ jsx("span", { title: "Cursor coordinates", children: formatCoord(cursorLngLat) }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: "Move cursor over map" }),
|
|
2208
|
+
showZoom && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2209
|
+
/* @__PURE__ */ jsx("span", { className: "text-border", children: "|" }),
|
|
2210
|
+
/* @__PURE__ */ jsxs("span", { title: "Zoom level", children: [
|
|
2211
|
+
"z",
|
|
2212
|
+
formatZoom(currentZoom)
|
|
2213
|
+
] })
|
|
2214
|
+
] }),
|
|
2215
|
+
showBearing && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2216
|
+
/* @__PURE__ */ jsx("span", { className: "text-border", children: "|" }),
|
|
2217
|
+
/* @__PURE__ */ jsx("span", { title: "Bearing", children: formatBearingValue(currentBearing) })
|
|
2218
|
+
] })
|
|
2219
|
+
]
|
|
2220
|
+
}
|
|
2221
|
+
);
|
|
2222
|
+
};
|
|
2223
|
+
CoordinateDisplay.displayName = "CoordinateDisplay";
|
|
2224
|
+
var DeckOverlay = ({
|
|
2225
|
+
layers = [],
|
|
2226
|
+
onHover,
|
|
2227
|
+
onClick,
|
|
2228
|
+
getCursor,
|
|
2229
|
+
interleaved = true,
|
|
2230
|
+
effects,
|
|
2231
|
+
deckProps = {}
|
|
2232
|
+
}) => {
|
|
2233
|
+
const { map, loaded } = useMap();
|
|
2234
|
+
const overlayRef = React6.useRef(null);
|
|
2235
|
+
const MapboxOverlayRef = React6.useRef(null);
|
|
2236
|
+
React6.useEffect(() => {
|
|
2237
|
+
if (!map || !loaded) return;
|
|
2238
|
+
const initOverlay = async () => {
|
|
2239
|
+
try {
|
|
2240
|
+
const deckMapbox = await import('@deck.gl/mapbox');
|
|
2241
|
+
const MapboxOverlay = deckMapbox.MapboxOverlay;
|
|
2242
|
+
MapboxOverlayRef.current = MapboxOverlay;
|
|
2243
|
+
const overlay = new MapboxOverlay({
|
|
2244
|
+
interleaved,
|
|
2245
|
+
layers,
|
|
2246
|
+
onHover,
|
|
2247
|
+
onClick,
|
|
2248
|
+
...getCursor ? { getCursor } : {},
|
|
2249
|
+
...effects ? { effects } : {},
|
|
2250
|
+
...deckProps
|
|
2251
|
+
});
|
|
2252
|
+
map.addControl(overlay);
|
|
2253
|
+
overlayRef.current = overlay;
|
|
2254
|
+
} catch (err) {
|
|
2255
|
+
console.warn(
|
|
2256
|
+
"[maps-react] Deck.gl is not available. Install @deck.gl/core, @deck.gl/layers, and @deck.gl/mapbox to use DeckOverlay.",
|
|
2257
|
+
err
|
|
2258
|
+
);
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
initOverlay();
|
|
2262
|
+
return () => {
|
|
2263
|
+
if (overlayRef.current && map) {
|
|
2264
|
+
try {
|
|
2265
|
+
map.removeControl(overlayRef.current);
|
|
2266
|
+
} catch {
|
|
2267
|
+
}
|
|
2268
|
+
overlayRef.current = null;
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
}, [map, loaded, interleaved]);
|
|
2272
|
+
React6.useEffect(() => {
|
|
2273
|
+
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2274
|
+
overlayRef.current.setProps({ layers });
|
|
2275
|
+
}
|
|
2276
|
+
}, [layers]);
|
|
2277
|
+
React6.useEffect(() => {
|
|
2278
|
+
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2279
|
+
overlayRef.current.setProps({
|
|
2280
|
+
onHover,
|
|
2281
|
+
onClick
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
}, [onHover, onClick]);
|
|
2285
|
+
React6.useEffect(() => {
|
|
2286
|
+
if (overlayRef.current && effects && "setProps" in overlayRef.current) {
|
|
2287
|
+
overlayRef.current.setProps({ effects });
|
|
2288
|
+
}
|
|
2289
|
+
}, [effects]);
|
|
2290
|
+
return null;
|
|
2291
|
+
};
|
|
2292
|
+
DeckOverlay.displayName = "DeckOverlay";
|
|
2293
|
+
|
|
2294
|
+
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 };
|