@page-speed/maps 0.1.9 → 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 +121 -28
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.js +122 -29
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +121 -28
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +122 -29
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +53 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -991,6 +991,13 @@ function GeoMap({
|
|
|
991
991
|
IconComponent = FallbackIcon,
|
|
992
992
|
ImgComponent = FallbackImg
|
|
993
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
|
+
});
|
|
994
1001
|
const [isMobile, setIsMobile] = React3.useState(false);
|
|
995
1002
|
React3.useEffect(() => {
|
|
996
1003
|
const checkMobile = () => {
|
|
@@ -1006,6 +1013,24 @@ function GeoMap({
|
|
|
1006
1013
|
}
|
|
1007
1014
|
return isMobile ? 420 : 520;
|
|
1008
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]);
|
|
1009
1034
|
const normalizedStandaloneMarkers = React3.useMemo(
|
|
1010
1035
|
() => markers.map((marker, index) => ({
|
|
1011
1036
|
...marker,
|
|
@@ -1089,42 +1114,41 @@ function GeoMap({
|
|
|
1089
1114
|
longitude: DEFAULT_VIEW_STATE.longitude
|
|
1090
1115
|
};
|
|
1091
1116
|
}, [normalizedClusters, normalizedStandaloneMarkers]);
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1094
|
-
return markerFocusZoom;
|
|
1095
|
-
}
|
|
1096
|
-
const allCoords = [];
|
|
1117
|
+
const zoomCoordinates = React3.useMemo(() => {
|
|
1118
|
+
const coords = [];
|
|
1097
1119
|
normalizedStandaloneMarkers.forEach((marker) => {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1120
|
+
coords.push({
|
|
1121
|
+
lat: marker.latitude,
|
|
1122
|
+
lng: marker.longitude
|
|
1101
1123
|
});
|
|
1102
1124
|
});
|
|
1103
1125
|
normalizedClusters.forEach((cluster) => {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1126
|
+
coords.push({
|
|
1127
|
+
lat: cluster.latitude,
|
|
1128
|
+
lng: cluster.longitude
|
|
1107
1129
|
});
|
|
1108
1130
|
});
|
|
1109
|
-
|
|
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) {
|
|
1110
1147
|
return DEFAULT_VIEW_STATE.zoom;
|
|
1111
1148
|
}
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
const lngDiff = Math.max(...lngs) - Math.min(...lngs);
|
|
1116
|
-
const maxDiff = Math.max(latDiff, lngDiff);
|
|
1117
|
-
const heightFactor = calculatedHeight / 520;
|
|
1118
|
-
const paddingFactor = 0.85;
|
|
1119
|
-
if (maxDiff > 10) return Math.max(2, 3 * heightFactor * paddingFactor);
|
|
1120
|
-
if (maxDiff > 5) return Math.max(4, 5 * heightFactor * paddingFactor);
|
|
1121
|
-
if (maxDiff > 2) return Math.max(6, 7 * heightFactor * paddingFactor);
|
|
1122
|
-
if (maxDiff > 1) return Math.max(8, 9 * heightFactor * paddingFactor);
|
|
1123
|
-
if (maxDiff > 0.5) return Math.max(9, 10 * heightFactor * paddingFactor);
|
|
1124
|
-
if (maxDiff > 0.1) return Math.max(11, 12 * heightFactor * paddingFactor);
|
|
1125
|
-
if (maxDiff > 0.01) return Math.max(12, 13 * heightFactor * paddingFactor);
|
|
1126
|
-
return Math.max(11, 12 * heightFactor * paddingFactor);
|
|
1127
|
-
}, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom, calculatedHeight]);
|
|
1149
|
+
const adjustedZoom = properZoom ? properZoom - 0.5 : DEFAULT_VIEW_STATE.zoom;
|
|
1150
|
+
return Math.min(adjustedZoom, 15);
|
|
1151
|
+
}, [properZoom, zoomCoordinates.length, markerFocusZoom]);
|
|
1128
1152
|
const [uncontrolledViewState, setUncontrolledViewState] = React3.useState({
|
|
1129
1153
|
latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
|
|
1130
1154
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
@@ -1450,6 +1474,7 @@ function GeoMap({
|
|
|
1450
1474
|
return /* @__PURE__ */ jsxs(
|
|
1451
1475
|
"div",
|
|
1452
1476
|
{
|
|
1477
|
+
ref: containerRef,
|
|
1453
1478
|
className: cn(
|
|
1454
1479
|
"relative rounded-2xl border border-border bg-background",
|
|
1455
1480
|
// Remove overflow-hidden from outer container to allow panel to overflow
|