@page-speed/maps 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/geo-map.cjs +161 -32
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.d.cts +5 -1
- package/dist/components/geo-map.d.ts +5 -1
- package/dist/components/geo-map.js +162 -33
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +161 -32
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +162 -33
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +93 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -987,9 +987,50 @@ function GeoMap({
|
|
|
987
987
|
clearSelectionOnMapClick = true,
|
|
988
988
|
mapChildren,
|
|
989
989
|
optixFlowConfig,
|
|
990
|
+
mapSize,
|
|
990
991
|
IconComponent = FallbackIcon,
|
|
991
992
|
ImgComponent = FallbackImg
|
|
992
993
|
}) {
|
|
994
|
+
const containerRef = React3.useRef(null);
|
|
995
|
+
const [containerDimensions, setContainerDimensions] = React3.useState({
|
|
996
|
+
width: 800,
|
|
997
|
+
// Default width
|
|
998
|
+
height: 520
|
|
999
|
+
// Default height
|
|
1000
|
+
});
|
|
1001
|
+
const [isMobile, setIsMobile] = React3.useState(false);
|
|
1002
|
+
React3.useEffect(() => {
|
|
1003
|
+
const checkMobile = () => {
|
|
1004
|
+
setIsMobile(window.innerWidth < 768);
|
|
1005
|
+
};
|
|
1006
|
+
checkMobile();
|
|
1007
|
+
window.addEventListener("resize", checkMobile);
|
|
1008
|
+
return () => window.removeEventListener("resize", checkMobile);
|
|
1009
|
+
}, []);
|
|
1010
|
+
const calculatedHeight = React3.useMemo(() => {
|
|
1011
|
+
if (mapSize) {
|
|
1012
|
+
return isMobile ? mapSize.mobile : mapSize.desktop;
|
|
1013
|
+
}
|
|
1014
|
+
return isMobile ? 420 : 520;
|
|
1015
|
+
}, [mapSize, isMobile]);
|
|
1016
|
+
React3.useEffect(() => {
|
|
1017
|
+
if (!containerRef.current) return;
|
|
1018
|
+
const updateDimensions = () => {
|
|
1019
|
+
if (containerRef.current) {
|
|
1020
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
1021
|
+
setContainerDimensions({
|
|
1022
|
+
width: rect.width || 800,
|
|
1023
|
+
height: rect.height || calculatedHeight
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
updateDimensions();
|
|
1028
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1029
|
+
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
1030
|
+
resizeObserver.observe(containerRef.current);
|
|
1031
|
+
return () => resizeObserver.disconnect();
|
|
1032
|
+
}
|
|
1033
|
+
}, [calculatedHeight]);
|
|
993
1034
|
const normalizedStandaloneMarkers = React3.useMemo(
|
|
994
1035
|
() => markers.map((marker, index) => ({
|
|
995
1036
|
...marker,
|
|
@@ -1073,39 +1114,41 @@ function GeoMap({
|
|
|
1073
1114
|
longitude: DEFAULT_VIEW_STATE.longitude
|
|
1074
1115
|
};
|
|
1075
1116
|
}, [normalizedClusters, normalizedStandaloneMarkers]);
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
return markerFocusZoom;
|
|
1079
|
-
}
|
|
1080
|
-
const allCoords = [];
|
|
1117
|
+
const zoomCoordinates = React3.useMemo(() => {
|
|
1118
|
+
const coords = [];
|
|
1081
1119
|
normalizedStandaloneMarkers.forEach((marker) => {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1120
|
+
coords.push({
|
|
1121
|
+
lat: marker.latitude,
|
|
1122
|
+
lng: marker.longitude
|
|
1085
1123
|
});
|
|
1086
1124
|
});
|
|
1087
1125
|
normalizedClusters.forEach((cluster) => {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1126
|
+
coords.push({
|
|
1127
|
+
lat: cluster.latitude,
|
|
1128
|
+
lng: cluster.longitude
|
|
1091
1129
|
});
|
|
1092
1130
|
});
|
|
1093
|
-
|
|
1131
|
+
return coords;
|
|
1132
|
+
}, [normalizedStandaloneMarkers, normalizedClusters]);
|
|
1133
|
+
const properZoom = useDefaultZoom({
|
|
1134
|
+
coordinates: zoomCoordinates,
|
|
1135
|
+
mapWidth: containerDimensions.width,
|
|
1136
|
+
mapHeight: containerDimensions.height,
|
|
1137
|
+
padding: 80,
|
|
1138
|
+
// Increased padding for better framing
|
|
1139
|
+
maxZoom: 18,
|
|
1140
|
+
minZoom: 1
|
|
1141
|
+
});
|
|
1142
|
+
const calculatedZoom = React3.useMemo(() => {
|
|
1143
|
+
if (zoomCoordinates.length === 1) {
|
|
1144
|
+
return markerFocusZoom;
|
|
1145
|
+
}
|
|
1146
|
+
if (zoomCoordinates.length === 0) {
|
|
1094
1147
|
return DEFAULT_VIEW_STATE.zoom;
|
|
1095
1148
|
}
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
const lngDiff = Math.max(...lngs) - Math.min(...lngs);
|
|
1100
|
-
const maxDiff = Math.max(latDiff, lngDiff);
|
|
1101
|
-
if (maxDiff > 10) return 3;
|
|
1102
|
-
if (maxDiff > 5) return 5;
|
|
1103
|
-
if (maxDiff > 2) return 7;
|
|
1104
|
-
if (maxDiff > 1) return 9;
|
|
1105
|
-
if (maxDiff > 0.5) return 10;
|
|
1106
|
-
if (maxDiff > 0.1) return 12;
|
|
1107
|
-
return 13;
|
|
1108
|
-
}, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom]);
|
|
1149
|
+
const adjustedZoom = properZoom ? properZoom - 0.5 : DEFAULT_VIEW_STATE.zoom;
|
|
1150
|
+
return Math.min(adjustedZoom, 15);
|
|
1151
|
+
}, [properZoom, zoomCoordinates.length, markerFocusZoom]);
|
|
1109
1152
|
const [uncontrolledViewState, setUncontrolledViewState] = React3.useState({
|
|
1110
1153
|
latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
|
|
1111
1154
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
@@ -1431,25 +1474,35 @@ function GeoMap({
|
|
|
1431
1474
|
return /* @__PURE__ */ jsxs(
|
|
1432
1475
|
"div",
|
|
1433
1476
|
{
|
|
1477
|
+
ref: containerRef,
|
|
1434
1478
|
className: cn(
|
|
1435
|
-
"relative
|
|
1479
|
+
"relative rounded-2xl border border-border bg-background",
|
|
1480
|
+
// Remove overflow-hidden from outer container to allow panel to overflow
|
|
1436
1481
|
className
|
|
1437
1482
|
),
|
|
1483
|
+
style: {
|
|
1484
|
+
// If className includes height settings, they'll override via CSS specificity
|
|
1485
|
+
height: className?.includes("h-[") || className?.includes("min-h-[") || className?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
|
|
1486
|
+
// Explicitly allow overflow for marker panels
|
|
1487
|
+
overflow: "visible"
|
|
1488
|
+
},
|
|
1438
1489
|
children: [
|
|
1439
1490
|
/* @__PURE__ */ jsx(
|
|
1440
1491
|
"div",
|
|
1441
1492
|
{
|
|
1442
1493
|
className: cn(
|
|
1443
|
-
"w-full",
|
|
1444
|
-
//
|
|
1445
|
-
mapWrapperClassName
|
|
1494
|
+
"w-full rounded-2xl",
|
|
1495
|
+
// Only apply default height class if mapWrapperClassName not provided
|
|
1496
|
+
!mapWrapperClassName && `h-[${calculatedHeight}px]`,
|
|
1497
|
+
mapWrapperClassName
|
|
1446
1498
|
),
|
|
1447
1499
|
style: {
|
|
1448
|
-
//
|
|
1449
|
-
height: mapWrapperClassName ? void 0 :
|
|
1500
|
+
// If mapWrapperClassName includes height, let it handle the height
|
|
1501
|
+
height: mapWrapperClassName?.includes("h-[") || mapWrapperClassName?.includes("min-h-[") || mapWrapperClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
|
|
1450
1502
|
maxHeight: "100vh",
|
|
1451
1503
|
// Prevent excessive growth
|
|
1452
1504
|
position: "relative",
|
|
1505
|
+
// Keep overflow hidden only on the map wrapper to contain the canvas
|
|
1453
1506
|
overflow: "hidden"
|
|
1454
1507
|
},
|
|
1455
1508
|
children: /* @__PURE__ */ jsx(
|
|
@@ -1475,6 +1528,10 @@ function GeoMap({
|
|
|
1475
1528
|
geolocateControlPosition,
|
|
1476
1529
|
flyToOptions,
|
|
1477
1530
|
className: cn("h-full w-full", mapClassName),
|
|
1531
|
+
style: {
|
|
1532
|
+
// Pass the calculated height to MapLibre for better zoom calculations
|
|
1533
|
+
height: mapClassName?.includes("h-[") || mapClassName?.includes("min-h-[") || mapClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`
|
|
1534
|
+
},
|
|
1478
1535
|
children: mapChildren
|
|
1479
1536
|
}
|
|
1480
1537
|
)
|
|
@@ -1484,9 +1541,13 @@ function GeoMap({
|
|
|
1484
1541
|
"div",
|
|
1485
1542
|
{
|
|
1486
1543
|
className: cn(
|
|
1487
|
-
"pointer-events-none absolute z-
|
|
1544
|
+
"pointer-events-none absolute z-30",
|
|
1488
1545
|
PANEL_POSITION_CLASS[panelPosition]
|
|
1489
1546
|
),
|
|
1547
|
+
style: {
|
|
1548
|
+
// Ensure panel can overflow and has higher z-index
|
|
1549
|
+
zIndex: 30
|
|
1550
|
+
},
|
|
1490
1551
|
children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", children: renderMarkerPanel() })
|
|
1491
1552
|
}
|
|
1492
1553
|
) : null
|