@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.cjs
CHANGED
|
@@ -1008,9 +1008,50 @@ function GeoMap({
|
|
|
1008
1008
|
clearSelectionOnMapClick = true,
|
|
1009
1009
|
mapChildren,
|
|
1010
1010
|
optixFlowConfig,
|
|
1011
|
+
mapSize,
|
|
1011
1012
|
IconComponent = FallbackIcon,
|
|
1012
1013
|
ImgComponent = FallbackImg
|
|
1013
1014
|
}) {
|
|
1015
|
+
const containerRef = React3__namespace.useRef(null);
|
|
1016
|
+
const [containerDimensions, setContainerDimensions] = React3__namespace.useState({
|
|
1017
|
+
width: 800,
|
|
1018
|
+
// Default width
|
|
1019
|
+
height: 520
|
|
1020
|
+
// Default height
|
|
1021
|
+
});
|
|
1022
|
+
const [isMobile, setIsMobile] = React3__namespace.useState(false);
|
|
1023
|
+
React3__namespace.useEffect(() => {
|
|
1024
|
+
const checkMobile = () => {
|
|
1025
|
+
setIsMobile(window.innerWidth < 768);
|
|
1026
|
+
};
|
|
1027
|
+
checkMobile();
|
|
1028
|
+
window.addEventListener("resize", checkMobile);
|
|
1029
|
+
return () => window.removeEventListener("resize", checkMobile);
|
|
1030
|
+
}, []);
|
|
1031
|
+
const calculatedHeight = React3__namespace.useMemo(() => {
|
|
1032
|
+
if (mapSize) {
|
|
1033
|
+
return isMobile ? mapSize.mobile : mapSize.desktop;
|
|
1034
|
+
}
|
|
1035
|
+
return isMobile ? 420 : 520;
|
|
1036
|
+
}, [mapSize, isMobile]);
|
|
1037
|
+
React3__namespace.useEffect(() => {
|
|
1038
|
+
if (!containerRef.current) return;
|
|
1039
|
+
const updateDimensions = () => {
|
|
1040
|
+
if (containerRef.current) {
|
|
1041
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
1042
|
+
setContainerDimensions({
|
|
1043
|
+
width: rect.width || 800,
|
|
1044
|
+
height: rect.height || calculatedHeight
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
updateDimensions();
|
|
1049
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1050
|
+
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
1051
|
+
resizeObserver.observe(containerRef.current);
|
|
1052
|
+
return () => resizeObserver.disconnect();
|
|
1053
|
+
}
|
|
1054
|
+
}, [calculatedHeight]);
|
|
1014
1055
|
const normalizedStandaloneMarkers = React3__namespace.useMemo(
|
|
1015
1056
|
() => markers.map((marker, index) => ({
|
|
1016
1057
|
...marker,
|
|
@@ -1094,39 +1135,41 @@ function GeoMap({
|
|
|
1094
1135
|
longitude: DEFAULT_VIEW_STATE.longitude
|
|
1095
1136
|
};
|
|
1096
1137
|
}, [normalizedClusters, normalizedStandaloneMarkers]);
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
return markerFocusZoom;
|
|
1100
|
-
}
|
|
1101
|
-
const allCoords = [];
|
|
1138
|
+
const zoomCoordinates = React3__namespace.useMemo(() => {
|
|
1139
|
+
const coords = [];
|
|
1102
1140
|
normalizedStandaloneMarkers.forEach((marker) => {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1141
|
+
coords.push({
|
|
1142
|
+
lat: marker.latitude,
|
|
1143
|
+
lng: marker.longitude
|
|
1106
1144
|
});
|
|
1107
1145
|
});
|
|
1108
1146
|
normalizedClusters.forEach((cluster) => {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1147
|
+
coords.push({
|
|
1148
|
+
lat: cluster.latitude,
|
|
1149
|
+
lng: cluster.longitude
|
|
1112
1150
|
});
|
|
1113
1151
|
});
|
|
1114
|
-
|
|
1152
|
+
return coords;
|
|
1153
|
+
}, [normalizedStandaloneMarkers, normalizedClusters]);
|
|
1154
|
+
const properZoom = useDefaultZoom({
|
|
1155
|
+
coordinates: zoomCoordinates,
|
|
1156
|
+
mapWidth: containerDimensions.width,
|
|
1157
|
+
mapHeight: containerDimensions.height,
|
|
1158
|
+
padding: 80,
|
|
1159
|
+
// Increased padding for better framing
|
|
1160
|
+
maxZoom: 18,
|
|
1161
|
+
minZoom: 1
|
|
1162
|
+
});
|
|
1163
|
+
const calculatedZoom = React3__namespace.useMemo(() => {
|
|
1164
|
+
if (zoomCoordinates.length === 1) {
|
|
1165
|
+
return markerFocusZoom;
|
|
1166
|
+
}
|
|
1167
|
+
if (zoomCoordinates.length === 0) {
|
|
1115
1168
|
return DEFAULT_VIEW_STATE.zoom;
|
|
1116
1169
|
}
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
const lngDiff = Math.max(...lngs) - Math.min(...lngs);
|
|
1121
|
-
const maxDiff = Math.max(latDiff, lngDiff);
|
|
1122
|
-
if (maxDiff > 10) return 3;
|
|
1123
|
-
if (maxDiff > 5) return 5;
|
|
1124
|
-
if (maxDiff > 2) return 7;
|
|
1125
|
-
if (maxDiff > 1) return 9;
|
|
1126
|
-
if (maxDiff > 0.5) return 10;
|
|
1127
|
-
if (maxDiff > 0.1) return 12;
|
|
1128
|
-
return 13;
|
|
1129
|
-
}, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom]);
|
|
1170
|
+
const adjustedZoom = properZoom ? properZoom - 0.5 : DEFAULT_VIEW_STATE.zoom;
|
|
1171
|
+
return Math.min(adjustedZoom, 15);
|
|
1172
|
+
}, [properZoom, zoomCoordinates.length, markerFocusZoom]);
|
|
1130
1173
|
const [uncontrolledViewState, setUncontrolledViewState] = React3__namespace.useState({
|
|
1131
1174
|
latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
|
|
1132
1175
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
@@ -1452,25 +1495,35 @@ function GeoMap({
|
|
|
1452
1495
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1453
1496
|
"div",
|
|
1454
1497
|
{
|
|
1498
|
+
ref: containerRef,
|
|
1455
1499
|
className: cn(
|
|
1456
|
-
"relative
|
|
1500
|
+
"relative rounded-2xl border border-border bg-background",
|
|
1501
|
+
// Remove overflow-hidden from outer container to allow panel to overflow
|
|
1457
1502
|
className
|
|
1458
1503
|
),
|
|
1504
|
+
style: {
|
|
1505
|
+
// If className includes height settings, they'll override via CSS specificity
|
|
1506
|
+
height: className?.includes("h-[") || className?.includes("min-h-[") || className?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
|
|
1507
|
+
// Explicitly allow overflow for marker panels
|
|
1508
|
+
overflow: "visible"
|
|
1509
|
+
},
|
|
1459
1510
|
children: [
|
|
1460
1511
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1461
1512
|
"div",
|
|
1462
1513
|
{
|
|
1463
1514
|
className: cn(
|
|
1464
|
-
"w-full",
|
|
1465
|
-
//
|
|
1466
|
-
mapWrapperClassName
|
|
1515
|
+
"w-full rounded-2xl",
|
|
1516
|
+
// Only apply default height class if mapWrapperClassName not provided
|
|
1517
|
+
!mapWrapperClassName && `h-[${calculatedHeight}px]`,
|
|
1518
|
+
mapWrapperClassName
|
|
1467
1519
|
),
|
|
1468
1520
|
style: {
|
|
1469
|
-
//
|
|
1470
|
-
height: mapWrapperClassName ? void 0 :
|
|
1521
|
+
// If mapWrapperClassName includes height, let it handle the height
|
|
1522
|
+
height: mapWrapperClassName?.includes("h-[") || mapWrapperClassName?.includes("min-h-[") || mapWrapperClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
|
|
1471
1523
|
maxHeight: "100vh",
|
|
1472
1524
|
// Prevent excessive growth
|
|
1473
1525
|
position: "relative",
|
|
1526
|
+
// Keep overflow hidden only on the map wrapper to contain the canvas
|
|
1474
1527
|
overflow: "hidden"
|
|
1475
1528
|
},
|
|
1476
1529
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1496,6 +1549,10 @@ function GeoMap({
|
|
|
1496
1549
|
geolocateControlPosition,
|
|
1497
1550
|
flyToOptions,
|
|
1498
1551
|
className: cn("h-full w-full", mapClassName),
|
|
1552
|
+
style: {
|
|
1553
|
+
// Pass the calculated height to MapLibre for better zoom calculations
|
|
1554
|
+
height: mapClassName?.includes("h-[") || mapClassName?.includes("min-h-[") || mapClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`
|
|
1555
|
+
},
|
|
1499
1556
|
children: mapChildren
|
|
1500
1557
|
}
|
|
1501
1558
|
)
|
|
@@ -1505,9 +1562,13 @@ function GeoMap({
|
|
|
1505
1562
|
"div",
|
|
1506
1563
|
{
|
|
1507
1564
|
className: cn(
|
|
1508
|
-
"pointer-events-none absolute z-
|
|
1565
|
+
"pointer-events-none absolute z-30",
|
|
1509
1566
|
PANEL_POSITION_CLASS[panelPosition]
|
|
1510
1567
|
),
|
|
1568
|
+
style: {
|
|
1569
|
+
// Ensure panel can overflow and has higher z-index
|
|
1570
|
+
zIndex: 30
|
|
1571
|
+
},
|
|
1511
1572
|
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto", children: renderMarkerPanel() })
|
|
1512
1573
|
}
|
|
1513
1574
|
) : null
|