@page-speed/maps 0.1.3 → 0.1.5
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 +120 -0
- package/dist/components/geo-map.cjs +1228 -0
- package/dist/components/geo-map.cjs.map +1 -0
- package/dist/components/geo-map.d.cts +138 -0
- package/dist/components/geo-map.d.ts +138 -0
- package/dist/components/geo-map.js +1207 -0
- package/dist/components/geo-map.js.map +1 -0
- package/dist/components/index.cjs +1350 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +1326 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/map-marker.cjs +137 -0
- package/dist/components/map-marker.cjs.map +1 -0
- package/dist/components/map-marker.d.cts +76 -0
- package/dist/components/map-marker.d.ts +76 -0
- package/dist/components/map-marker.js +130 -0
- package/dist/components/map-marker.js.map +1 -0
- package/dist/core/MapLibre.cjs +46 -20
- package/dist/core/MapLibre.cjs.map +1 -1
- package/dist/core/MapLibre.js +46 -20
- package/dist/core/MapLibre.js.map +1 -1
- package/dist/core/index.cjs +46 -20
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +46 -20
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +964 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +945 -39
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.cts +5 -5
- package/dist/types/index.d.ts +5 -5
- package/dist/utils/cn.cjs +13 -0
- package/dist/utils/cn.cjs.map +1 -0
- package/dist/utils/cn.d.cts +16 -0
- package/dist/utils/cn.d.ts +16 -0
- package/dist/utils/cn.js +11 -0
- package/dist/utils/cn.js.map +1 -0
- package/dist/utils/index.cjs +63 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +42 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/simple-pressable.cjs +63 -0
- package/dist/utils/simple-pressable.cjs.map +1 -0
- package/dist/utils/simple-pressable.d.cts +20 -0
- package/dist/utils/simple-pressable.d.ts +20 -0
- package/dist/utils/simple-pressable.js +41 -0
- package/dist/utils/simple-pressable.js.map +1 -0
- package/package.json +29 -2
|
@@ -0,0 +1,1207 @@
|
|
|
1
|
+
import * as React3 from 'react';
|
|
2
|
+
import React3__default from 'react';
|
|
3
|
+
import { Marker, Map as Map$1, GeolocateControl, NavigationControl } from 'react-map-gl/maplibre';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/utils/getMapLibreStyleUrl.ts
|
|
9
|
+
var MAPLIBRE_DEFAULT_STYLE_URL = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
|
|
10
|
+
var DEFAULT_STADIA_STYLE_URL = "https://tiles.stadiamaps.com/styles/osm_bright.json";
|
|
11
|
+
var STYLE_MAP = {
|
|
12
|
+
default: DEFAULT_STADIA_STYLE_URL,
|
|
13
|
+
"alidade-smooth": "https://tiles.stadiamaps.com/styles/alidade_smooth.json",
|
|
14
|
+
"alidade-smooth-dark": "https://tiles.stadiamaps.com/styles/alidade_smooth_dark.json",
|
|
15
|
+
"maplibre-default": MAPLIBRE_DEFAULT_STYLE_URL,
|
|
16
|
+
"osm-bright": "https://tiles.stadiamaps.com/styles/osm_bright.json",
|
|
17
|
+
"stadia-outdoors": "https://tiles.stadiamaps.com/styles/outdoors.json",
|
|
18
|
+
"stamen-toner": "https://tiles.stadiamaps.com/styles/stamen_toner.json",
|
|
19
|
+
"stamen-terrain": "https://tiles.stadiamaps.com/styles/stamen_terrain.json",
|
|
20
|
+
"stamen-watercolor": "https://tiles.stadiamaps.com/styles/stamen_watercolor.json"
|
|
21
|
+
};
|
|
22
|
+
var HTTP_URL_REGEX = /^https?:\/\//i;
|
|
23
|
+
function isStadiaMapsUrl(url) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = new URL(url);
|
|
26
|
+
return parsed.hostname === "tiles.stadiamaps.com";
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function assertStadiaApiKey(stadiaApiKey) {
|
|
32
|
+
if (!stadiaApiKey.trim()) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"A non-empty stadiaApiKey is required for Stadia Maps style URLs."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function appendStadiaApiKey(styleUrl, stadiaApiKey) {
|
|
39
|
+
if (!isStadiaMapsUrl(styleUrl)) {
|
|
40
|
+
return styleUrl;
|
|
41
|
+
}
|
|
42
|
+
assertStadiaApiKey(stadiaApiKey);
|
|
43
|
+
const parsed = new URL(styleUrl);
|
|
44
|
+
if (!parsed.searchParams.has("api_key")) {
|
|
45
|
+
parsed.searchParams.set("api_key", stadiaApiKey);
|
|
46
|
+
}
|
|
47
|
+
return parsed.toString();
|
|
48
|
+
}
|
|
49
|
+
function getMapLibreStyleUrl(value, stadiaApiKey) {
|
|
50
|
+
const normalizedApiKey = stadiaApiKey.trim();
|
|
51
|
+
if (!value || typeof value !== "string") {
|
|
52
|
+
if (!normalizedApiKey) {
|
|
53
|
+
return MAPLIBRE_DEFAULT_STYLE_URL;
|
|
54
|
+
}
|
|
55
|
+
return appendStadiaApiKey(DEFAULT_STADIA_STYLE_URL, normalizedApiKey);
|
|
56
|
+
}
|
|
57
|
+
if (STYLE_MAP[value]) {
|
|
58
|
+
const mappedStyleUrl = STYLE_MAP[value];
|
|
59
|
+
if (isStadiaMapsUrl(mappedStyleUrl) && !normalizedApiKey) {
|
|
60
|
+
return MAPLIBRE_DEFAULT_STYLE_URL;
|
|
61
|
+
}
|
|
62
|
+
return appendStadiaApiKey(mappedStyleUrl, normalizedApiKey);
|
|
63
|
+
}
|
|
64
|
+
if (HTTP_URL_REGEX.test(value)) {
|
|
65
|
+
if (isStadiaMapsUrl(value) && !normalizedApiKey) {
|
|
66
|
+
return MAPLIBRE_DEFAULT_STYLE_URL;
|
|
67
|
+
}
|
|
68
|
+
return appendStadiaApiKey(value, normalizedApiKey);
|
|
69
|
+
}
|
|
70
|
+
if (!normalizedApiKey) {
|
|
71
|
+
return MAPLIBRE_DEFAULT_STYLE_URL;
|
|
72
|
+
}
|
|
73
|
+
return appendStadiaApiKey(DEFAULT_STADIA_STYLE_URL, normalizedApiKey);
|
|
74
|
+
}
|
|
75
|
+
function cn(...inputs) {
|
|
76
|
+
return twMerge(clsx(inputs));
|
|
77
|
+
}
|
|
78
|
+
var SimplePressable = React3.forwardRef(({ children, className, href, onClick, ...props }, ref) => {
|
|
79
|
+
if (href) {
|
|
80
|
+
const isExternal = href.startsWith("http://") || href.startsWith("https://");
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
"a",
|
|
83
|
+
{
|
|
84
|
+
ref,
|
|
85
|
+
href,
|
|
86
|
+
className,
|
|
87
|
+
target: isExternal ? "_blank" : props.target,
|
|
88
|
+
rel: isExternal ? "noopener noreferrer" : props.rel,
|
|
89
|
+
onClick,
|
|
90
|
+
...props,
|
|
91
|
+
children
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (onClick) {
|
|
96
|
+
return /* @__PURE__ */ jsx(
|
|
97
|
+
"button",
|
|
98
|
+
{
|
|
99
|
+
ref,
|
|
100
|
+
type: "button",
|
|
101
|
+
className,
|
|
102
|
+
onClick,
|
|
103
|
+
...props,
|
|
104
|
+
children
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return /* @__PURE__ */ jsx("span", { className, children });
|
|
109
|
+
});
|
|
110
|
+
SimplePressable.displayName = "SimplePressable";
|
|
111
|
+
var DEFAULT_MAPLIBRE_CSS_HREF = "https://cdn.jsdelivr.net/npm/maplibre-gl@5.18.0/dist/maplibre-gl.css";
|
|
112
|
+
var MAPLIBRE_STYLESHEET_ID = "page-speed-maplibre-gl-css";
|
|
113
|
+
var DEFAULT_FLY_TO_OPTIONS = Object.freeze({});
|
|
114
|
+
var VIEW_STATE_COORDINATE_EPSILON = 1e-6;
|
|
115
|
+
var VIEW_STATE_ZOOM_EPSILON = 0.01;
|
|
116
|
+
var DEFAULT_FLY_TO_EASING = (t) => 1 - Math.pow(1 - t, 3);
|
|
117
|
+
function joinClassNames(...classNames) {
|
|
118
|
+
return classNames.filter(Boolean).join(" ");
|
|
119
|
+
}
|
|
120
|
+
function hasMeaningfulViewStateDelta(previous, next) {
|
|
121
|
+
return Math.abs(previous.latitude - next.latitude) > VIEW_STATE_COORDINATE_EPSILON || Math.abs(previous.longitude - next.longitude) > VIEW_STATE_COORDINATE_EPSILON || Math.abs(previous.zoom - next.zoom) > VIEW_STATE_ZOOM_EPSILON;
|
|
122
|
+
}
|
|
123
|
+
function ensureMapLibreStylesheet(href) {
|
|
124
|
+
if (typeof document === "undefined") {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const existingLink = document.getElementById(MAPLIBRE_STYLESHEET_ID);
|
|
128
|
+
if (existingLink instanceof HTMLLinkElement) {
|
|
129
|
+
if (existingLink.getAttribute("href") !== href) {
|
|
130
|
+
existingLink.setAttribute("href", href);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const matchingLink = Array.from(
|
|
135
|
+
document.querySelectorAll("link[rel='stylesheet']")
|
|
136
|
+
).find((link) => link.getAttribute("href") === href);
|
|
137
|
+
if (matchingLink instanceof HTMLLinkElement) {
|
|
138
|
+
matchingLink.id = MAPLIBRE_STYLESHEET_ID;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const stylesheet = document.createElement("link");
|
|
142
|
+
stylesheet.id = MAPLIBRE_STYLESHEET_ID;
|
|
143
|
+
stylesheet.rel = "stylesheet";
|
|
144
|
+
stylesheet.href = href;
|
|
145
|
+
stylesheet.dataset.pageSpeedMaps = "maplibre-css";
|
|
146
|
+
document.head.appendChild(stylesheet);
|
|
147
|
+
}
|
|
148
|
+
function DefaultMarker({ marker }) {
|
|
149
|
+
return /* @__PURE__ */ jsxs(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
style: {
|
|
153
|
+
cursor: marker.draggable ? "grab" : "pointer",
|
|
154
|
+
transform: "translate(-50%, -100%)",
|
|
155
|
+
display: "inline-flex",
|
|
156
|
+
alignItems: "center",
|
|
157
|
+
justifyContent: "center",
|
|
158
|
+
position: "relative"
|
|
159
|
+
},
|
|
160
|
+
onClick: marker.onClick,
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsx(
|
|
163
|
+
"svg",
|
|
164
|
+
{
|
|
165
|
+
"aria-hidden": "true",
|
|
166
|
+
width: "32",
|
|
167
|
+
height: "32",
|
|
168
|
+
viewBox: "0 0 24 24",
|
|
169
|
+
fill: marker.color || "#3B82F6",
|
|
170
|
+
style: { filter: "drop-shadow(0 2px 8px rgba(0,0,0,0.35))" },
|
|
171
|
+
children: /* @__PURE__ */ jsx("path", { d: "M12 2C8.13 2 5 5.13 5 9c0 4.85 6.13 12.24 6.39 12.55a.75.75 0 0 0 1.16 0C12.87 21.24 19 13.85 19 9c0-3.87-3.13-7-7-7Zm0 9.75A2.75 2.75 0 1 1 12 6.25a2.75 2.75 0 0 1 0 5.5Z" })
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
marker.label ? /* @__PURE__ */ jsx(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
style: {
|
|
178
|
+
position: "absolute",
|
|
179
|
+
bottom: -28,
|
|
180
|
+
left: "50%",
|
|
181
|
+
transform: "translateX(-50%)",
|
|
182
|
+
background: "#FFFFFF",
|
|
183
|
+
borderRadius: 6,
|
|
184
|
+
padding: "2px 8px",
|
|
185
|
+
fontSize: 12,
|
|
186
|
+
fontWeight: 500,
|
|
187
|
+
whiteSpace: "nowrap",
|
|
188
|
+
boxShadow: "0 3px 10px rgba(0, 0, 0, 0.2)"
|
|
189
|
+
},
|
|
190
|
+
children: marker.label
|
|
191
|
+
}
|
|
192
|
+
) : null
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
function normalizeMarkers(markers) {
|
|
198
|
+
return markers.map((marker, index) => {
|
|
199
|
+
if (marker.lat !== void 0 && marker.lng !== void 0) {
|
|
200
|
+
return marker;
|
|
201
|
+
}
|
|
202
|
+
const basicMarker = marker;
|
|
203
|
+
return {
|
|
204
|
+
id: basicMarker.id ?? index,
|
|
205
|
+
lat: basicMarker.latitude,
|
|
206
|
+
lng: basicMarker.longitude,
|
|
207
|
+
color: basicMarker.color,
|
|
208
|
+
draggable: basicMarker.draggable,
|
|
209
|
+
label: basicMarker.label,
|
|
210
|
+
element: basicMarker.element,
|
|
211
|
+
onClick: basicMarker.onClick
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function MapLibre({
|
|
216
|
+
stadiaApiKey,
|
|
217
|
+
mapLibreCssHref,
|
|
218
|
+
viewState,
|
|
219
|
+
onViewStateChange,
|
|
220
|
+
mapStyle,
|
|
221
|
+
center = viewState ? { lat: viewState.latitude ?? 0, lng: viewState.longitude ?? 0 } : { lat: 0, lng: 0 },
|
|
222
|
+
zoom = viewState?.zoom ?? 14,
|
|
223
|
+
styleUrl,
|
|
224
|
+
markers = [],
|
|
225
|
+
onMoveEnd,
|
|
226
|
+
onClick,
|
|
227
|
+
onMarkerDrag,
|
|
228
|
+
className,
|
|
229
|
+
style,
|
|
230
|
+
children,
|
|
231
|
+
showNavigationControl = true,
|
|
232
|
+
showGeolocateControl = false,
|
|
233
|
+
navigationControlPosition = "bottom-right",
|
|
234
|
+
geolocateControlPosition = "top-left",
|
|
235
|
+
flyToOptions = DEFAULT_FLY_TO_OPTIONS
|
|
236
|
+
}) {
|
|
237
|
+
const mapRef = React3__default.useRef(null);
|
|
238
|
+
const resolvedMapLibreCssHref = mapLibreCssHref && mapLibreCssHref.trim().length > 0 ? mapLibreCssHref : DEFAULT_MAPLIBRE_CSS_HREF;
|
|
239
|
+
const [internalViewState, setInternalViewState] = React3__default.useState({
|
|
240
|
+
latitude: viewState?.latitude ?? center.lat,
|
|
241
|
+
longitude: viewState?.longitude ?? center.lng,
|
|
242
|
+
zoom: viewState?.zoom ?? zoom
|
|
243
|
+
});
|
|
244
|
+
const isUserInteracting = React3__default.useRef(false);
|
|
245
|
+
const isMarkerDragging = React3__default.useRef(false);
|
|
246
|
+
const dragAnimationFrame = React3__default.useRef(null);
|
|
247
|
+
const lastReportedViewState = React3__default.useRef(null);
|
|
248
|
+
const resolvedFlyToOptions = React3__default.useMemo(
|
|
249
|
+
() => ({
|
|
250
|
+
speed: flyToOptions.speed ?? 0.8,
|
|
251
|
+
curve: flyToOptions.curve ?? 1.2,
|
|
252
|
+
bearing: flyToOptions.bearing ?? 0,
|
|
253
|
+
easing: flyToOptions.easing ?? DEFAULT_FLY_TO_EASING
|
|
254
|
+
}),
|
|
255
|
+
[
|
|
256
|
+
flyToOptions.bearing,
|
|
257
|
+
flyToOptions.curve,
|
|
258
|
+
flyToOptions.easing,
|
|
259
|
+
flyToOptions.speed
|
|
260
|
+
]
|
|
261
|
+
);
|
|
262
|
+
React3__default.useEffect(() => {
|
|
263
|
+
ensureMapLibreStylesheet(resolvedMapLibreCssHref);
|
|
264
|
+
}, [resolvedMapLibreCssHref]);
|
|
265
|
+
React3__default.useEffect(() => {
|
|
266
|
+
if (!mapRef.current || !viewState || isUserInteracting.current || isMarkerDragging.current) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
setInternalViewState((previous) => {
|
|
270
|
+
const next = {
|
|
271
|
+
latitude: viewState.latitude ?? previous.latitude,
|
|
272
|
+
longitude: viewState.longitude ?? previous.longitude,
|
|
273
|
+
zoom: viewState.zoom ?? previous.zoom
|
|
274
|
+
};
|
|
275
|
+
const hasChanged = hasMeaningfulViewStateDelta(previous, next);
|
|
276
|
+
if (!hasChanged) {
|
|
277
|
+
return previous;
|
|
278
|
+
}
|
|
279
|
+
const isEchoedMoveState = !!lastReportedViewState.current && !hasMeaningfulViewStateDelta(lastReportedViewState.current, next);
|
|
280
|
+
if (!isEchoedMoveState) {
|
|
281
|
+
mapRef.current?.flyTo({
|
|
282
|
+
center: [next.longitude, next.latitude],
|
|
283
|
+
zoom: next.zoom,
|
|
284
|
+
speed: resolvedFlyToOptions.speed,
|
|
285
|
+
curve: resolvedFlyToOptions.curve,
|
|
286
|
+
bearing: resolvedFlyToOptions.bearing,
|
|
287
|
+
easing: resolvedFlyToOptions.easing,
|
|
288
|
+
essential: true
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return next;
|
|
292
|
+
});
|
|
293
|
+
}, [
|
|
294
|
+
resolvedFlyToOptions,
|
|
295
|
+
viewState?.latitude,
|
|
296
|
+
viewState?.longitude,
|
|
297
|
+
viewState?.zoom
|
|
298
|
+
]);
|
|
299
|
+
const handleMoveStart = React3__default.useCallback(() => {
|
|
300
|
+
isUserInteracting.current = true;
|
|
301
|
+
}, []);
|
|
302
|
+
const handleMove = React3__default.useCallback(
|
|
303
|
+
(event) => {
|
|
304
|
+
const nextViewState = event.viewState;
|
|
305
|
+
setInternalViewState({
|
|
306
|
+
latitude: nextViewState.latitude,
|
|
307
|
+
longitude: nextViewState.longitude,
|
|
308
|
+
zoom: nextViewState.zoom
|
|
309
|
+
});
|
|
310
|
+
const roundedViewState = {
|
|
311
|
+
latitude: Number(nextViewState.latitude.toFixed(6)),
|
|
312
|
+
longitude: Number(nextViewState.longitude.toFixed(6)),
|
|
313
|
+
zoom: Number(nextViewState.zoom.toFixed(2))
|
|
314
|
+
};
|
|
315
|
+
lastReportedViewState.current = roundedViewState;
|
|
316
|
+
onViewStateChange?.(roundedViewState);
|
|
317
|
+
},
|
|
318
|
+
[onViewStateChange]
|
|
319
|
+
);
|
|
320
|
+
const handleMoveEnd = React3__default.useCallback(
|
|
321
|
+
(event) => {
|
|
322
|
+
isUserInteracting.current = false;
|
|
323
|
+
if (!onMoveEnd) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const map = event.target;
|
|
327
|
+
const nextCenter = map.getCenter();
|
|
328
|
+
const nextZoom = map.getZoom();
|
|
329
|
+
const bounds = map.getBounds();
|
|
330
|
+
onMoveEnd(
|
|
331
|
+
{
|
|
332
|
+
lat: Number(nextCenter.lat.toFixed(6)),
|
|
333
|
+
lng: Number(nextCenter.lng.toFixed(6))
|
|
334
|
+
},
|
|
335
|
+
Number(nextZoom.toFixed(2)),
|
|
336
|
+
bounds
|
|
337
|
+
);
|
|
338
|
+
},
|
|
339
|
+
[onMoveEnd]
|
|
340
|
+
);
|
|
341
|
+
const handleMapClick = React3__default.useCallback(
|
|
342
|
+
(event) => {
|
|
343
|
+
if (!onClick) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
onClick({ latitude: event.lngLat.lat, longitude: event.lngLat.lng });
|
|
347
|
+
},
|
|
348
|
+
[onClick]
|
|
349
|
+
);
|
|
350
|
+
const normalizedMarkers = React3__default.useMemo(
|
|
351
|
+
() => normalizeMarkers(markers),
|
|
352
|
+
[markers]
|
|
353
|
+
);
|
|
354
|
+
const markerElements = React3__default.useMemo(
|
|
355
|
+
() => normalizedMarkers.map((marker) => /* @__PURE__ */ jsx(
|
|
356
|
+
Marker,
|
|
357
|
+
{
|
|
358
|
+
longitude: marker.lng,
|
|
359
|
+
latitude: marker.lat,
|
|
360
|
+
draggable: marker.draggable,
|
|
361
|
+
onDragStart: () => {
|
|
362
|
+
isMarkerDragging.current = true;
|
|
363
|
+
},
|
|
364
|
+
onDrag: (event) => {
|
|
365
|
+
if (!mapRef.current) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const nextLngLat = event.lngLat;
|
|
369
|
+
if (!nextLngLat || nextLngLat.lng === void 0 || nextLngLat.lat === void 0) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const draggedLng = nextLngLat.lng;
|
|
373
|
+
const draggedLat = nextLngLat.lat;
|
|
374
|
+
if (dragAnimationFrame.current) {
|
|
375
|
+
cancelAnimationFrame(dragAnimationFrame.current);
|
|
376
|
+
}
|
|
377
|
+
dragAnimationFrame.current = requestAnimationFrame(() => {
|
|
378
|
+
if (!mapRef.current) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const bounds = mapRef.current.getBounds();
|
|
382
|
+
const viewportWidth = bounds.getEast() - bounds.getWest();
|
|
383
|
+
const viewportHeight = bounds.getNorth() - bounds.getSouth();
|
|
384
|
+
const edgePadding = 0.1;
|
|
385
|
+
const westThreshold = bounds.getWest() + viewportWidth * edgePadding;
|
|
386
|
+
const eastThreshold = bounds.getEast() - viewportWidth * edgePadding;
|
|
387
|
+
const southThreshold = bounds.getSouth() + viewportHeight * edgePadding;
|
|
388
|
+
const northThreshold = bounds.getNorth() - viewportHeight * edgePadding;
|
|
389
|
+
const nearWestEdge = draggedLng < westThreshold;
|
|
390
|
+
const nearEastEdge = draggedLng > eastThreshold;
|
|
391
|
+
const nearSouthEdge = draggedLat < southThreshold;
|
|
392
|
+
const nearNorthEdge = draggedLat > northThreshold;
|
|
393
|
+
if (!nearWestEdge && !nearEastEdge && !nearSouthEdge && !nearNorthEdge) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
let panLng = draggedLng;
|
|
397
|
+
let panLat = draggedLat;
|
|
398
|
+
const offsetAmount = 0.2;
|
|
399
|
+
if (nearWestEdge) {
|
|
400
|
+
panLng = draggedLng - viewportWidth * offsetAmount;
|
|
401
|
+
}
|
|
402
|
+
if (nearEastEdge) {
|
|
403
|
+
panLng = draggedLng + viewportWidth * offsetAmount;
|
|
404
|
+
}
|
|
405
|
+
if (nearSouthEdge) {
|
|
406
|
+
panLat = draggedLat - viewportHeight * offsetAmount;
|
|
407
|
+
}
|
|
408
|
+
if (nearNorthEdge) {
|
|
409
|
+
panLat = draggedLat + viewportHeight * offsetAmount;
|
|
410
|
+
}
|
|
411
|
+
mapRef.current?.easeTo({
|
|
412
|
+
center: [panLng, panLat],
|
|
413
|
+
duration: 200
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
},
|
|
417
|
+
onDragEnd: (event) => {
|
|
418
|
+
isMarkerDragging.current = false;
|
|
419
|
+
if (dragAnimationFrame.current) {
|
|
420
|
+
cancelAnimationFrame(dragAnimationFrame.current);
|
|
421
|
+
dragAnimationFrame.current = null;
|
|
422
|
+
}
|
|
423
|
+
if (!onMarkerDrag) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const nextLngLat = event.lngLat;
|
|
427
|
+
if (!nextLngLat || nextLngLat.lng === void 0 || nextLngLat.lat === void 0) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
onMarkerDrag(marker.id ?? null, {
|
|
431
|
+
latitude: nextLngLat.lat,
|
|
432
|
+
longitude: nextLngLat.lng
|
|
433
|
+
});
|
|
434
|
+
},
|
|
435
|
+
children: marker.element ? typeof marker.element === "function" ? marker.element() : marker.element : /* @__PURE__ */ jsx(DefaultMarker, { marker })
|
|
436
|
+
},
|
|
437
|
+
marker.id
|
|
438
|
+
)),
|
|
439
|
+
[normalizedMarkers, onMarkerDrag]
|
|
440
|
+
);
|
|
441
|
+
const resolvedMapStyleUrl = React3__default.useMemo(() => {
|
|
442
|
+
if (styleUrl) {
|
|
443
|
+
return appendStadiaApiKey(styleUrl, stadiaApiKey);
|
|
444
|
+
}
|
|
445
|
+
if (mapStyle) {
|
|
446
|
+
return getMapLibreStyleUrl(mapStyle, stadiaApiKey);
|
|
447
|
+
}
|
|
448
|
+
return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
|
|
449
|
+
}, [mapStyle, stadiaApiKey, styleUrl]);
|
|
450
|
+
return /* @__PURE__ */ jsx(
|
|
451
|
+
"div",
|
|
452
|
+
{
|
|
453
|
+
className: joinClassNames("relative w-full h-full", className),
|
|
454
|
+
style: { width: "100%", height: "100%", ...style },
|
|
455
|
+
children: /* @__PURE__ */ jsxs(
|
|
456
|
+
Map$1,
|
|
457
|
+
{
|
|
458
|
+
ref: mapRef,
|
|
459
|
+
...internalViewState,
|
|
460
|
+
mapStyle: resolvedMapStyleUrl,
|
|
461
|
+
onMoveStart: handleMoveStart,
|
|
462
|
+
onMove: handleMove,
|
|
463
|
+
onMoveEnd: handleMoveEnd,
|
|
464
|
+
onClick: handleMapClick,
|
|
465
|
+
attributionControl: false,
|
|
466
|
+
trackResize: true,
|
|
467
|
+
dragRotate: false,
|
|
468
|
+
touchZoomRotate: false,
|
|
469
|
+
children: [
|
|
470
|
+
showGeolocateControl ? /* @__PURE__ */ jsx(GeolocateControl, { position: geolocateControlPosition }) : null,
|
|
471
|
+
showNavigationControl ? /* @__PURE__ */ jsx(NavigationControl, { position: navigationControlPosition }) : null,
|
|
472
|
+
markerElements,
|
|
473
|
+
children
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
)
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
var PANEL_POSITION_CLASS = {
|
|
481
|
+
"top-left": "left-4 top-4",
|
|
482
|
+
"top-right": "right-4 top-4",
|
|
483
|
+
"bottom-left": "bottom-4 left-4",
|
|
484
|
+
"bottom-right": "bottom-4 right-4"
|
|
485
|
+
};
|
|
486
|
+
var DEFAULT_VIEW_STATE = {
|
|
487
|
+
latitude: 39.5,
|
|
488
|
+
longitude: -98.35,
|
|
489
|
+
zoom: 3
|
|
490
|
+
};
|
|
491
|
+
var VIDEO_FILE_EXTENSION_REGEX = /\.(mp4|webm|ogg|mov|m4v|m3u8)(\?.*)?$/i;
|
|
492
|
+
function resolveMediaType(item) {
|
|
493
|
+
if (item.type) {
|
|
494
|
+
return item.type;
|
|
495
|
+
}
|
|
496
|
+
return VIDEO_FILE_EXTENSION_REGEX.test(item.src) ? "video" : "image";
|
|
497
|
+
}
|
|
498
|
+
function normalizeId(value, fallback) {
|
|
499
|
+
if (value === null || value === void 0 || value === "") {
|
|
500
|
+
return fallback;
|
|
501
|
+
}
|
|
502
|
+
return String(value);
|
|
503
|
+
}
|
|
504
|
+
function buildClusterCenter(markers) {
|
|
505
|
+
if (!markers.length) {
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
const total = markers.reduce(
|
|
509
|
+
(accumulator, marker) => ({
|
|
510
|
+
latitude: accumulator.latitude + marker.latitude,
|
|
511
|
+
longitude: accumulator.longitude + marker.longitude
|
|
512
|
+
}),
|
|
513
|
+
{ latitude: 0, longitude: 0 }
|
|
514
|
+
);
|
|
515
|
+
return {
|
|
516
|
+
latitude: total.latitude / markers.length,
|
|
517
|
+
longitude: total.longitude / markers.length
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function resolveActionKey(action, index) {
|
|
521
|
+
if (typeof action.label === "string" && action.label.trim().length > 0) {
|
|
522
|
+
return `label:${action.label}:${index}`;
|
|
523
|
+
}
|
|
524
|
+
if (action.href) {
|
|
525
|
+
return `href:${action.href}:${index}`;
|
|
526
|
+
}
|
|
527
|
+
return `action:${index}`;
|
|
528
|
+
}
|
|
529
|
+
var FallbackIcon = ({
|
|
530
|
+
size = 20,
|
|
531
|
+
className
|
|
532
|
+
}) => /* @__PURE__ */ jsx(
|
|
533
|
+
"svg",
|
|
534
|
+
{
|
|
535
|
+
width: size,
|
|
536
|
+
height: size,
|
|
537
|
+
viewBox: "0 0 24 24",
|
|
538
|
+
fill: "none",
|
|
539
|
+
stroke: "currentColor",
|
|
540
|
+
strokeWidth: "2",
|
|
541
|
+
strokeLinecap: "round",
|
|
542
|
+
strokeLinejoin: "round",
|
|
543
|
+
className,
|
|
544
|
+
children: /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" })
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
var FallbackImg = ({ src, alt, className, loading }) => /* @__PURE__ */ jsx("img", { src, alt, className, loading });
|
|
548
|
+
function MarkerActions({ actions }) {
|
|
549
|
+
if (!actions || actions.length === 0) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
return /* @__PURE__ */ jsx("div", { className: "mt-4 flex flex-wrap gap-2", children: actions.map((action, index) => {
|
|
553
|
+
const {
|
|
554
|
+
label,
|
|
555
|
+
icon,
|
|
556
|
+
iconAfter,
|
|
557
|
+
children,
|
|
558
|
+
href,
|
|
559
|
+
onClick,
|
|
560
|
+
className: actionClassName,
|
|
561
|
+
variant,
|
|
562
|
+
size,
|
|
563
|
+
asButton,
|
|
564
|
+
...rest
|
|
565
|
+
} = action;
|
|
566
|
+
const buttonStyles = cn(
|
|
567
|
+
"inline-flex items-center gap-2 px-4 py-2 rounded-md font-medium transition-colors",
|
|
568
|
+
variant === "outline" ? "border border-border bg-background hover:bg-muted" : "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
569
|
+
size === "sm" && "text-sm px-3 py-1.5",
|
|
570
|
+
size === "icon" && "p-2",
|
|
571
|
+
actionClassName
|
|
572
|
+
);
|
|
573
|
+
return /* @__PURE__ */ jsx(
|
|
574
|
+
SimplePressable,
|
|
575
|
+
{
|
|
576
|
+
href,
|
|
577
|
+
onClick,
|
|
578
|
+
className: buttonStyles,
|
|
579
|
+
...rest,
|
|
580
|
+
children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
581
|
+
icon,
|
|
582
|
+
label,
|
|
583
|
+
iconAfter
|
|
584
|
+
] })
|
|
585
|
+
},
|
|
586
|
+
resolveActionKey(action, index)
|
|
587
|
+
);
|
|
588
|
+
}) });
|
|
589
|
+
}
|
|
590
|
+
function MarkerMediaCarousel({
|
|
591
|
+
mediaItems,
|
|
592
|
+
optixFlowConfig,
|
|
593
|
+
IconComponent = FallbackIcon,
|
|
594
|
+
ImgComponent = FallbackImg
|
|
595
|
+
}) {
|
|
596
|
+
const [activeIndex, setActiveIndex] = React3.useState(0);
|
|
597
|
+
const totalItems = mediaItems.length;
|
|
598
|
+
const mediaResetKey = React3.useMemo(
|
|
599
|
+
() => mediaItems.map((item, index) => {
|
|
600
|
+
const itemId = normalizeId(item.id, `media-${index}`);
|
|
601
|
+
return `${itemId}:${item.src}:${item.type ?? ""}:${item.poster ?? ""}`;
|
|
602
|
+
}).join("|"),
|
|
603
|
+
[mediaItems]
|
|
604
|
+
);
|
|
605
|
+
const activeItemIndex = Math.min(activeIndex, Math.max(0, totalItems - 1));
|
|
606
|
+
React3.useEffect(() => {
|
|
607
|
+
setActiveIndex(0);
|
|
608
|
+
}, [mediaResetKey]);
|
|
609
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative border-b border-border/60 bg-muted/40", children: [
|
|
610
|
+
/* @__PURE__ */ jsx("div", { className: "relative aspect-video w-full overflow-hidden", children: mediaItems.map((item, index) => {
|
|
611
|
+
const isActive = index === activeItemIndex;
|
|
612
|
+
const mediaType = resolveMediaType(item);
|
|
613
|
+
return /* @__PURE__ */ jsx(
|
|
614
|
+
"div",
|
|
615
|
+
{
|
|
616
|
+
"aria-hidden": !isActive,
|
|
617
|
+
className: cn(
|
|
618
|
+
"absolute inset-0 transition-opacity duration-500 ease-in-out",
|
|
619
|
+
isActive ? "opacity-100 z-1" : "opacity-0 z-0 pointer-events-none"
|
|
620
|
+
),
|
|
621
|
+
children: mediaType === "video" ? /* @__PURE__ */ jsx(
|
|
622
|
+
"video",
|
|
623
|
+
{
|
|
624
|
+
className: "h-full w-full object-cover",
|
|
625
|
+
controls: isActive,
|
|
626
|
+
preload: "metadata",
|
|
627
|
+
poster: item.poster,
|
|
628
|
+
tabIndex: isActive ? 0 : -1,
|
|
629
|
+
children: /* @__PURE__ */ jsx("source", { src: item.src })
|
|
630
|
+
}
|
|
631
|
+
) : /* @__PURE__ */ jsx(
|
|
632
|
+
ImgComponent,
|
|
633
|
+
{
|
|
634
|
+
src: item.src,
|
|
635
|
+
alt: item.alt ?? "Map marker media",
|
|
636
|
+
className: "h-full w-full object-cover",
|
|
637
|
+
loading: "eager",
|
|
638
|
+
optixFlowConfig
|
|
639
|
+
}
|
|
640
|
+
)
|
|
641
|
+
},
|
|
642
|
+
normalizeId(item.id, `media-slide-${index}`)
|
|
643
|
+
);
|
|
644
|
+
}) }),
|
|
645
|
+
totalItems > 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
646
|
+
/* @__PURE__ */ jsx(
|
|
647
|
+
"button",
|
|
648
|
+
{
|
|
649
|
+
type: "button",
|
|
650
|
+
"aria-label": "Show previous media",
|
|
651
|
+
className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-[2]",
|
|
652
|
+
onClick: () => {
|
|
653
|
+
setActiveIndex(
|
|
654
|
+
(current) => (current - 1 + totalItems) % totalItems
|
|
655
|
+
);
|
|
656
|
+
},
|
|
657
|
+
children: /* @__PURE__ */ jsx(IconComponent, { name: "lucide/arrow-left", size: 18 })
|
|
658
|
+
}
|
|
659
|
+
),
|
|
660
|
+
/* @__PURE__ */ jsx(
|
|
661
|
+
"button",
|
|
662
|
+
{
|
|
663
|
+
type: "button",
|
|
664
|
+
"aria-label": "Show next media",
|
|
665
|
+
className: "absolute right-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-2",
|
|
666
|
+
onClick: () => {
|
|
667
|
+
setActiveIndex((current) => (current + 1) % totalItems);
|
|
668
|
+
},
|
|
669
|
+
children: /* @__PURE__ */ jsx(IconComponent, { name: "lucide/arrow-right", size: 18 })
|
|
670
|
+
}
|
|
671
|
+
),
|
|
672
|
+
/* @__PURE__ */ jsx("div", { className: "absolute bottom-2 left-1/2 flex -translate-x-1/2 items-center gap-1.5 z-[2]", children: mediaItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
673
|
+
"button",
|
|
674
|
+
{
|
|
675
|
+
type: "button",
|
|
676
|
+
"aria-label": `Show media item ${index + 1}`,
|
|
677
|
+
className: cn(
|
|
678
|
+
"h-2 rounded-full transition-all duration-300",
|
|
679
|
+
index === activeItemIndex ? "w-6 bg-card" : "w-2 bg-card opacity-50 hover:opacity-100"
|
|
680
|
+
),
|
|
681
|
+
onClick: () => setActiveIndex(index)
|
|
682
|
+
},
|
|
683
|
+
normalizeId(item.id, `media-dot-${index}`)
|
|
684
|
+
)) })
|
|
685
|
+
] }) : null
|
|
686
|
+
] });
|
|
687
|
+
}
|
|
688
|
+
function getMarkerTitle(marker, markerIndex) {
|
|
689
|
+
if (marker.title !== void 0 && marker.title !== null) {
|
|
690
|
+
return marker.title;
|
|
691
|
+
}
|
|
692
|
+
if (marker.label !== void 0 && marker.label !== null) {
|
|
693
|
+
return marker.label;
|
|
694
|
+
}
|
|
695
|
+
return `Location ${markerIndex + 1}`;
|
|
696
|
+
}
|
|
697
|
+
function GeoMap({
|
|
698
|
+
className,
|
|
699
|
+
mapWrapperClassName,
|
|
700
|
+
mapClassName,
|
|
701
|
+
panelClassName,
|
|
702
|
+
panelPosition = "top-left",
|
|
703
|
+
stadiaApiKey = "",
|
|
704
|
+
mapStyle = "osm-bright",
|
|
705
|
+
styleUrl,
|
|
706
|
+
mapLibreCssHref,
|
|
707
|
+
markers = [],
|
|
708
|
+
clusters = [],
|
|
709
|
+
viewState,
|
|
710
|
+
defaultViewState,
|
|
711
|
+
onViewStateChange,
|
|
712
|
+
onMapClick,
|
|
713
|
+
onMarkerDrag,
|
|
714
|
+
showNavigationControl = true,
|
|
715
|
+
showGeolocateControl = false,
|
|
716
|
+
navigationControlPosition = "top-right",
|
|
717
|
+
geolocateControlPosition = "top-left",
|
|
718
|
+
flyToOptions,
|
|
719
|
+
markerFocusZoom = 14,
|
|
720
|
+
clusterFocusZoom = 5,
|
|
721
|
+
selectedMarkerId,
|
|
722
|
+
initialSelectedMarkerId,
|
|
723
|
+
onSelectionChange,
|
|
724
|
+
clearSelectionOnMapClick = true,
|
|
725
|
+
mapChildren,
|
|
726
|
+
optixFlowConfig,
|
|
727
|
+
IconComponent = FallbackIcon,
|
|
728
|
+
ImgComponent = FallbackImg
|
|
729
|
+
}) {
|
|
730
|
+
const normalizedStandaloneMarkers = React3.useMemo(
|
|
731
|
+
() => markers.map((marker, index) => ({
|
|
732
|
+
...marker,
|
|
733
|
+
id: normalizeId(marker.id, `marker-${index}`)
|
|
734
|
+
})),
|
|
735
|
+
[markers]
|
|
736
|
+
);
|
|
737
|
+
const normalizedClusters = React3.useMemo(() => {
|
|
738
|
+
const results = [];
|
|
739
|
+
clusters.forEach((cluster, clusterIndex) => {
|
|
740
|
+
const clusterId = normalizeId(cluster.id, `cluster-${clusterIndex}`);
|
|
741
|
+
const normalizedClusterMarkers = cluster.markers.map(
|
|
742
|
+
(marker, markerIndex) => ({
|
|
743
|
+
...marker,
|
|
744
|
+
id: normalizeId(marker.id, `${clusterId}-marker-${markerIndex}`),
|
|
745
|
+
clusterId
|
|
746
|
+
})
|
|
747
|
+
);
|
|
748
|
+
const clusterCenter = cluster.latitude !== void 0 && cluster.longitude !== void 0 ? { latitude: cluster.latitude, longitude: cluster.longitude } : buildClusterCenter(normalizedClusterMarkers);
|
|
749
|
+
if (!clusterCenter) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
results.push({
|
|
753
|
+
...cluster,
|
|
754
|
+
id: clusterId,
|
|
755
|
+
latitude: clusterCenter.latitude,
|
|
756
|
+
longitude: clusterCenter.longitude,
|
|
757
|
+
markers: normalizedClusterMarkers
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
return results;
|
|
761
|
+
}, [clusters]);
|
|
762
|
+
const markerLookup = React3.useMemo(() => {
|
|
763
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
764
|
+
normalizedStandaloneMarkers.forEach((marker) => {
|
|
765
|
+
lookup.set(marker.id, marker);
|
|
766
|
+
});
|
|
767
|
+
normalizedClusters.forEach((cluster) => {
|
|
768
|
+
cluster.markers.forEach((marker) => {
|
|
769
|
+
lookup.set(marker.id, marker);
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
return lookup;
|
|
773
|
+
}, [normalizedClusters, normalizedStandaloneMarkers]);
|
|
774
|
+
const clusterLookup = React3.useMemo(() => {
|
|
775
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
776
|
+
normalizedClusters.forEach((cluster) => {
|
|
777
|
+
lookup.set(cluster.id, cluster);
|
|
778
|
+
});
|
|
779
|
+
return lookup;
|
|
780
|
+
}, [normalizedClusters]);
|
|
781
|
+
const firstCoordinate = React3.useMemo(() => {
|
|
782
|
+
const allCoords = [];
|
|
783
|
+
normalizedStandaloneMarkers.forEach((marker) => {
|
|
784
|
+
allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
|
|
785
|
+
});
|
|
786
|
+
normalizedClusters.forEach((cluster) => {
|
|
787
|
+
allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
|
|
788
|
+
});
|
|
789
|
+
if (allCoords.length > 0) {
|
|
790
|
+
const sum = allCoords.reduce(
|
|
791
|
+
(acc, coord) => ({
|
|
792
|
+
latitude: acc.latitude + coord.latitude,
|
|
793
|
+
longitude: acc.longitude + coord.longitude
|
|
794
|
+
}),
|
|
795
|
+
{ latitude: 0, longitude: 0 }
|
|
796
|
+
);
|
|
797
|
+
return {
|
|
798
|
+
latitude: sum.latitude / allCoords.length,
|
|
799
|
+
longitude: sum.longitude / allCoords.length
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
return {
|
|
803
|
+
latitude: DEFAULT_VIEW_STATE.latitude,
|
|
804
|
+
longitude: DEFAULT_VIEW_STATE.longitude
|
|
805
|
+
};
|
|
806
|
+
}, [normalizedClusters, normalizedStandaloneMarkers]);
|
|
807
|
+
const calculatedZoom = React3.useMemo(() => {
|
|
808
|
+
if (normalizedStandaloneMarkers.length + normalizedClusters.length <= 1) {
|
|
809
|
+
return markerFocusZoom;
|
|
810
|
+
}
|
|
811
|
+
const allCoords = [];
|
|
812
|
+
normalizedStandaloneMarkers.forEach((marker) => {
|
|
813
|
+
allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
|
|
814
|
+
});
|
|
815
|
+
normalizedClusters.forEach((cluster) => {
|
|
816
|
+
allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
|
|
817
|
+
});
|
|
818
|
+
if (allCoords.length === 0) {
|
|
819
|
+
return DEFAULT_VIEW_STATE.zoom;
|
|
820
|
+
}
|
|
821
|
+
const lats = allCoords.map((c) => c.latitude);
|
|
822
|
+
const lngs = allCoords.map((c) => c.longitude);
|
|
823
|
+
const latDiff = Math.max(...lats) - Math.min(...lats);
|
|
824
|
+
const lngDiff = Math.max(...lngs) - Math.min(...lngs);
|
|
825
|
+
const maxDiff = Math.max(latDiff, lngDiff);
|
|
826
|
+
if (maxDiff > 10) return 3;
|
|
827
|
+
if (maxDiff > 5) return 5;
|
|
828
|
+
if (maxDiff > 2) return 7;
|
|
829
|
+
if (maxDiff > 1) return 9;
|
|
830
|
+
if (maxDiff > 0.5) return 10;
|
|
831
|
+
if (maxDiff > 0.1) return 12;
|
|
832
|
+
return 13;
|
|
833
|
+
}, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom]);
|
|
834
|
+
const [uncontrolledViewState, setUncontrolledViewState] = React3.useState({
|
|
835
|
+
latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
|
|
836
|
+
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
837
|
+
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
838
|
+
});
|
|
839
|
+
React3.useEffect(() => {
|
|
840
|
+
if (!viewState && !defaultViewState) {
|
|
841
|
+
setUncontrolledViewState({
|
|
842
|
+
latitude: firstCoordinate.latitude,
|
|
843
|
+
longitude: firstCoordinate.longitude,
|
|
844
|
+
zoom: calculatedZoom
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
}, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
|
|
848
|
+
const isControlledViewState = viewState !== void 0;
|
|
849
|
+
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
850
|
+
const applyViewState = React3.useCallback(
|
|
851
|
+
(nextState) => {
|
|
852
|
+
if (!isControlledViewState) {
|
|
853
|
+
setUncontrolledViewState((current) => {
|
|
854
|
+
const next = { ...current, ...nextState };
|
|
855
|
+
const hasChanged = current.latitude !== next.latitude || current.longitude !== next.longitude || current.zoom !== next.zoom;
|
|
856
|
+
return hasChanged ? next : current;
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
onViewStateChange?.(nextState);
|
|
860
|
+
},
|
|
861
|
+
[isControlledViewState, onViewStateChange]
|
|
862
|
+
);
|
|
863
|
+
const [selection, setSelection] = React3.useState(() => {
|
|
864
|
+
if (initialSelectedMarkerId !== void 0 && initialSelectedMarkerId !== null) {
|
|
865
|
+
return {
|
|
866
|
+
type: "marker",
|
|
867
|
+
markerId: String(initialSelectedMarkerId)
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
return { type: "none" };
|
|
871
|
+
});
|
|
872
|
+
React3.useEffect(() => {
|
|
873
|
+
if (selectedMarkerId === void 0 || selectedMarkerId === null) {
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
setSelection({
|
|
877
|
+
type: "marker",
|
|
878
|
+
markerId: String(selectedMarkerId)
|
|
879
|
+
});
|
|
880
|
+
}, [selectedMarkerId]);
|
|
881
|
+
const selectedMarker = selection.markerId ? markerLookup.get(selection.markerId) : void 0;
|
|
882
|
+
const selectedCluster = selection.clusterId ? clusterLookup.get(selection.clusterId) : void 0;
|
|
883
|
+
React3.useEffect(() => {
|
|
884
|
+
if (selection.type === "marker" && selection.markerId && !selectedMarker) {
|
|
885
|
+
setSelection({ type: "none" });
|
|
886
|
+
onSelectionChange?.({ type: "none" });
|
|
887
|
+
}
|
|
888
|
+
}, [onSelectionChange, selectedMarker, selection]);
|
|
889
|
+
const emitSelectionChange = React3.useCallback(
|
|
890
|
+
(nextSelection) => {
|
|
891
|
+
if (nextSelection.type === "none") {
|
|
892
|
+
onSelectionChange?.({ type: "none" });
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
if (nextSelection.type === "marker") {
|
|
896
|
+
const parentCluster = nextSelection.marker.clusterId ? clusterLookup.get(nextSelection.marker.clusterId) : void 0;
|
|
897
|
+
onSelectionChange?.({
|
|
898
|
+
type: "marker",
|
|
899
|
+
marker: nextSelection.marker,
|
|
900
|
+
cluster: parentCluster
|
|
901
|
+
});
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
onSelectionChange?.({
|
|
905
|
+
type: "cluster",
|
|
906
|
+
cluster: nextSelection.cluster
|
|
907
|
+
});
|
|
908
|
+
},
|
|
909
|
+
[clusterLookup, onSelectionChange]
|
|
910
|
+
);
|
|
911
|
+
const selectMarker = React3.useCallback(
|
|
912
|
+
(marker) => {
|
|
913
|
+
setSelection({
|
|
914
|
+
type: "marker",
|
|
915
|
+
markerId: marker.id,
|
|
916
|
+
clusterId: marker.clusterId
|
|
917
|
+
});
|
|
918
|
+
applyViewState({
|
|
919
|
+
latitude: marker.latitude,
|
|
920
|
+
longitude: marker.longitude,
|
|
921
|
+
zoom: markerFocusZoom
|
|
922
|
+
});
|
|
923
|
+
emitSelectionChange({ type: "marker", marker });
|
|
924
|
+
},
|
|
925
|
+
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
926
|
+
);
|
|
927
|
+
const selectCluster = React3.useCallback(
|
|
928
|
+
(cluster) => {
|
|
929
|
+
setSelection({
|
|
930
|
+
type: "cluster",
|
|
931
|
+
clusterId: cluster.id
|
|
932
|
+
});
|
|
933
|
+
applyViewState({
|
|
934
|
+
latitude: cluster.latitude,
|
|
935
|
+
longitude: cluster.longitude,
|
|
936
|
+
zoom: clusterFocusZoom
|
|
937
|
+
});
|
|
938
|
+
emitSelectionChange({ type: "cluster", cluster });
|
|
939
|
+
},
|
|
940
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
941
|
+
);
|
|
942
|
+
const clearSelection = React3.useCallback(() => {
|
|
943
|
+
setSelection({ type: "none" });
|
|
944
|
+
emitSelectionChange({ type: "none" });
|
|
945
|
+
}, [emitSelectionChange]);
|
|
946
|
+
const mapMarkers = React3.useMemo(() => {
|
|
947
|
+
const resolvedMarkers = [];
|
|
948
|
+
normalizedClusters.forEach((cluster) => {
|
|
949
|
+
const isSelected = selection.type === "cluster" && selection.clusterId === cluster.id;
|
|
950
|
+
resolvedMarkers.push({
|
|
951
|
+
id: `cluster-pin:${cluster.id}`,
|
|
952
|
+
latitude: cluster.latitude,
|
|
953
|
+
longitude: cluster.longitude,
|
|
954
|
+
element: () => {
|
|
955
|
+
const customMarkerElement = cluster.markerElement;
|
|
956
|
+
const markerBody = typeof customMarkerElement === "function" ? customMarkerElement({
|
|
957
|
+
isSelected,
|
|
958
|
+
count: cluster.markers.length
|
|
959
|
+
}) : customMarkerElement;
|
|
960
|
+
return /* @__PURE__ */ jsx(
|
|
961
|
+
"button",
|
|
962
|
+
{
|
|
963
|
+
type: "button",
|
|
964
|
+
className: "group cursor-pointer",
|
|
965
|
+
onClick: (event) => {
|
|
966
|
+
event.preventDefault();
|
|
967
|
+
event.stopPropagation();
|
|
968
|
+
selectCluster(cluster);
|
|
969
|
+
},
|
|
970
|
+
"aria-label": `View ${cluster.markers.length} clustered locations`,
|
|
971
|
+
children: markerBody ?? /* @__PURE__ */ jsx(
|
|
972
|
+
"span",
|
|
973
|
+
{
|
|
974
|
+
className: cn(
|
|
975
|
+
"inline-flex min-h-10 min-w-10 items-center justify-center rounded-full border-2 border-white px-2 text-xs font-semibold text-white shadow-lg transition-transform duration-200 group-hover:scale-105",
|
|
976
|
+
isSelected && "ring-4 ring-primary/30",
|
|
977
|
+
cluster.pinClassName
|
|
978
|
+
),
|
|
979
|
+
style: {
|
|
980
|
+
backgroundColor: cluster.pinColor ?? "var(--foreground)"
|
|
981
|
+
},
|
|
982
|
+
children: cluster.markers.length
|
|
983
|
+
}
|
|
984
|
+
)
|
|
985
|
+
}
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
});
|
|
990
|
+
normalizedStandaloneMarkers.forEach((marker) => {
|
|
991
|
+
const isSelected = selection.type === "marker" && selection.markerId === marker.id;
|
|
992
|
+
const customMarkerElement = marker.markerElement;
|
|
993
|
+
resolvedMarkers.push({
|
|
994
|
+
id: marker.id,
|
|
995
|
+
latitude: marker.latitude,
|
|
996
|
+
longitude: marker.longitude,
|
|
997
|
+
draggable: marker.draggable,
|
|
998
|
+
element: () => {
|
|
999
|
+
const markerBody = typeof customMarkerElement === "function" ? customMarkerElement({ isSelected }) : customMarkerElement;
|
|
1000
|
+
return /* @__PURE__ */ jsx(
|
|
1001
|
+
"button",
|
|
1002
|
+
{
|
|
1003
|
+
type: "button",
|
|
1004
|
+
className: "group cursor-pointer",
|
|
1005
|
+
onClick: (event) => {
|
|
1006
|
+
event.preventDefault();
|
|
1007
|
+
event.stopPropagation();
|
|
1008
|
+
selectMarker(marker);
|
|
1009
|
+
},
|
|
1010
|
+
"aria-label": typeof marker.title === "string" ? `View ${marker.title}` : "View location details",
|
|
1011
|
+
children: markerBody ?? /* @__PURE__ */ jsx(
|
|
1012
|
+
"span",
|
|
1013
|
+
{
|
|
1014
|
+
className: cn(
|
|
1015
|
+
"inline-flex h-4 w-4 rounded-full border-2 border-white shadow-md transition-transform duration-200 group-hover:scale-110",
|
|
1016
|
+
isSelected && "h-5 w-5 ring-4 ring-primary/30",
|
|
1017
|
+
marker.pinClassName
|
|
1018
|
+
),
|
|
1019
|
+
style: {
|
|
1020
|
+
backgroundColor: marker.pinColor ?? "#f43f5e"
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
)
|
|
1024
|
+
}
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
return resolvedMarkers;
|
|
1030
|
+
}, [
|
|
1031
|
+
normalizedClusters,
|
|
1032
|
+
normalizedStandaloneMarkers,
|
|
1033
|
+
selectCluster,
|
|
1034
|
+
selectMarker,
|
|
1035
|
+
selection
|
|
1036
|
+
]);
|
|
1037
|
+
const renderMarkerPanel = () => {
|
|
1038
|
+
if (selectedMarker) {
|
|
1039
|
+
const markerMediaItems = selectedMarker.mediaItems ?? [];
|
|
1040
|
+
return /* @__PURE__ */ jsxs(
|
|
1041
|
+
"div",
|
|
1042
|
+
{
|
|
1043
|
+
className: cn(
|
|
1044
|
+
"relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
|
|
1045
|
+
panelClassName
|
|
1046
|
+
),
|
|
1047
|
+
children: [
|
|
1048
|
+
/* @__PURE__ */ jsx(
|
|
1049
|
+
"button",
|
|
1050
|
+
{
|
|
1051
|
+
type: "button",
|
|
1052
|
+
"aria-label": "Close marker details",
|
|
1053
|
+
className: "flex size-12 items-center justify-center rounded-bl-lg rounded-br-0 rounded-t-0 bg-black text-white transition-all duration-500 absolute top-0 right-0 z-10 cursor-pointer ring-4 ring-white",
|
|
1054
|
+
onClick: clearSelection,
|
|
1055
|
+
children: /* @__PURE__ */ jsx(IconComponent, { name: "lucide/x", size: 20 })
|
|
1056
|
+
}
|
|
1057
|
+
),
|
|
1058
|
+
markerMediaItems.length > 0 ? /* @__PURE__ */ jsx(
|
|
1059
|
+
MarkerMediaCarousel,
|
|
1060
|
+
{
|
|
1061
|
+
mediaItems: markerMediaItems,
|
|
1062
|
+
optixFlowConfig,
|
|
1063
|
+
IconComponent,
|
|
1064
|
+
ImgComponent
|
|
1065
|
+
}
|
|
1066
|
+
) : null,
|
|
1067
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2 p-4", children: [
|
|
1068
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-start justify-between gap-3", children: /* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1", children: [
|
|
1069
|
+
selectedMarker.eyebrow ? /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wide", children: selectedMarker.eyebrow }) : null,
|
|
1070
|
+
/* @__PURE__ */ jsx("div", { className: "text-base font-semibold leading-tight", children: selectedMarker.title ?? selectedMarker.label ?? "Location" })
|
|
1071
|
+
] }) }),
|
|
1072
|
+
selectedMarker.summary ? /* @__PURE__ */ jsx("div", { className: "text-sm leading-relaxed", children: selectedMarker.summary }) : null,
|
|
1073
|
+
selectedMarker.locationLine ? /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-start text-sm gap-2", children: [
|
|
1074
|
+
/* @__PURE__ */ jsx(
|
|
1075
|
+
IconComponent,
|
|
1076
|
+
{
|
|
1077
|
+
name: "lucide:map-pin",
|
|
1078
|
+
className: "opacity-50",
|
|
1079
|
+
size: 18
|
|
1080
|
+
}
|
|
1081
|
+
),
|
|
1082
|
+
typeof selectedMarker.locationLine === "string" ? /* @__PURE__ */ jsx(
|
|
1083
|
+
SimplePressable,
|
|
1084
|
+
{
|
|
1085
|
+
href: selectedMarker.locationUrl,
|
|
1086
|
+
className: cn(
|
|
1087
|
+
"transition-all duration-500",
|
|
1088
|
+
"font-medium opacity-75 hover:opacity-100",
|
|
1089
|
+
selectedMarker.locationUrl ? "underline underline-offset-4" : ""
|
|
1090
|
+
),
|
|
1091
|
+
children: selectedMarker.locationLine
|
|
1092
|
+
}
|
|
1093
|
+
) : selectedMarker.locationLine
|
|
1094
|
+
] }) : null,
|
|
1095
|
+
selectedMarker.hoursLine ? /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-start text-sm gap-2", children: [
|
|
1096
|
+
/* @__PURE__ */ jsx(
|
|
1097
|
+
IconComponent,
|
|
1098
|
+
{
|
|
1099
|
+
name: "lucide:clock",
|
|
1100
|
+
className: "opacity-50",
|
|
1101
|
+
size: 18
|
|
1102
|
+
}
|
|
1103
|
+
),
|
|
1104
|
+
typeof selectedMarker.hoursLine === "string" ? /* @__PURE__ */ jsx("div", { className: "font-medium", children: selectedMarker.hoursLine }) : selectedMarker.hoursLine
|
|
1105
|
+
] }) : null,
|
|
1106
|
+
selectedMarker.markerContentComponent ? /* @__PURE__ */ jsx("div", { className: "relative", children: selectedMarker.markerContentComponent }) : null,
|
|
1107
|
+
/* @__PURE__ */ jsx(MarkerActions, { actions: selectedMarker.actions })
|
|
1108
|
+
] })
|
|
1109
|
+
]
|
|
1110
|
+
}
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
if (selectedCluster) {
|
|
1114
|
+
return /* @__PURE__ */ jsxs(
|
|
1115
|
+
"div",
|
|
1116
|
+
{
|
|
1117
|
+
className: cn(
|
|
1118
|
+
"relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
|
|
1119
|
+
panelClassName
|
|
1120
|
+
),
|
|
1121
|
+
children: [
|
|
1122
|
+
/* @__PURE__ */ jsx(
|
|
1123
|
+
"button",
|
|
1124
|
+
{
|
|
1125
|
+
type: "button",
|
|
1126
|
+
"aria-label": "Close cluster details",
|
|
1127
|
+
className: "flex size-8 items-center justify-center rounded-full border border-border bg-card text-card-foreground transition hover:bg-muted hover:text-foreground absolute top-2 right-2 z-10",
|
|
1128
|
+
onClick: clearSelection,
|
|
1129
|
+
children: /* @__PURE__ */ jsx(IconComponent, { name: "lucide/x", size: 20 })
|
|
1130
|
+
}
|
|
1131
|
+
),
|
|
1132
|
+
/* @__PURE__ */ jsx("div", { className: "mb-3 flex items-start justify-between gap-3", children: /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
1133
|
+
selectedCluster.label ? /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: selectedCluster.label }) : null,
|
|
1134
|
+
/* @__PURE__ */ jsx("div", { className: "text-base font-semibold leading-tight text-foreground", children: selectedCluster.title ?? "Clustered Locations" }),
|
|
1135
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: selectedCluster.summary ?? `${selectedCluster.markers.length} location${selectedCluster.markers.length === 1 ? "" : "s"} in this cluster.` })
|
|
1136
|
+
] }) }),
|
|
1137
|
+
/* @__PURE__ */ jsx("div", { className: "max-h-56 space-y-2 overflow-y-auto pr-1", children: selectedCluster.markers.map((marker, markerIndex) => /* @__PURE__ */ jsxs(
|
|
1138
|
+
"button",
|
|
1139
|
+
{
|
|
1140
|
+
type: "button",
|
|
1141
|
+
className: "w-full rounded-lg border border-border/60 p-3 text-left transition hover:border-border hover:bg-muted/50",
|
|
1142
|
+
onClick: () => selectMarker(marker),
|
|
1143
|
+
children: [
|
|
1144
|
+
/* @__PURE__ */ jsx("div", { className: "line-clamp-1 text-sm font-semibold text-foreground", children: getMarkerTitle(marker, markerIndex) }),
|
|
1145
|
+
marker.summary ? /* @__PURE__ */ jsx("div", { className: "mt-1 line-clamp-2 text-xs text-muted-foreground", children: marker.summary }) : null
|
|
1146
|
+
]
|
|
1147
|
+
},
|
|
1148
|
+
marker.id
|
|
1149
|
+
)) })
|
|
1150
|
+
]
|
|
1151
|
+
}
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
return null;
|
|
1155
|
+
};
|
|
1156
|
+
return /* @__PURE__ */ jsxs(
|
|
1157
|
+
"div",
|
|
1158
|
+
{
|
|
1159
|
+
className: cn(
|
|
1160
|
+
"relative overflow-hidden rounded-2xl border border-border bg-background",
|
|
1161
|
+
className
|
|
1162
|
+
),
|
|
1163
|
+
children: [
|
|
1164
|
+
/* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
|
|
1165
|
+
MapLibre,
|
|
1166
|
+
{
|
|
1167
|
+
stadiaApiKey,
|
|
1168
|
+
mapStyle,
|
|
1169
|
+
styleUrl,
|
|
1170
|
+
mapLibreCssHref,
|
|
1171
|
+
viewState: resolvedViewState,
|
|
1172
|
+
onViewStateChange: applyViewState,
|
|
1173
|
+
markers: mapMarkers,
|
|
1174
|
+
onClick: (coord) => {
|
|
1175
|
+
onMapClick?.(coord);
|
|
1176
|
+
if (clearSelectionOnMapClick) {
|
|
1177
|
+
clearSelection();
|
|
1178
|
+
}
|
|
1179
|
+
},
|
|
1180
|
+
onMarkerDrag,
|
|
1181
|
+
showNavigationControl,
|
|
1182
|
+
showGeolocateControl,
|
|
1183
|
+
navigationControlPosition,
|
|
1184
|
+
geolocateControlPosition,
|
|
1185
|
+
flyToOptions,
|
|
1186
|
+
className: cn("h-full w-full", mapClassName),
|
|
1187
|
+
children: mapChildren
|
|
1188
|
+
}
|
|
1189
|
+
) }),
|
|
1190
|
+
selection.type !== "none" ? /* @__PURE__ */ jsx(
|
|
1191
|
+
"div",
|
|
1192
|
+
{
|
|
1193
|
+
className: cn(
|
|
1194
|
+
"pointer-events-none absolute z-20",
|
|
1195
|
+
PANEL_POSITION_CLASS[panelPosition]
|
|
1196
|
+
),
|
|
1197
|
+
children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", children: renderMarkerPanel() })
|
|
1198
|
+
}
|
|
1199
|
+
) : null
|
|
1200
|
+
]
|
|
1201
|
+
}
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
export { GeoMap };
|
|
1206
|
+
//# sourceMappingURL=geo-map.js.map
|
|
1207
|
+
//# sourceMappingURL=geo-map.js.map
|