@page-speed/maps 0.2.0 → 0.2.2
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 +53 -4
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.js +53 -4
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +53 -4
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +53 -4
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +53 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -613,6 +613,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
613
613
|
"bottom-left": "bottom-4 left-4",
|
|
614
614
|
"bottom-right": "bottom-4 right-4"
|
|
615
615
|
};
|
|
616
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
617
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
618
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
619
|
+
if (isNorth && isEast) {
|
|
620
|
+
return "bottom-left";
|
|
621
|
+
} else if (isNorth && !isEast) {
|
|
622
|
+
return "bottom-right";
|
|
623
|
+
} else if (!isNorth && isEast) {
|
|
624
|
+
return "top-left";
|
|
625
|
+
} else {
|
|
626
|
+
return "top-right";
|
|
627
|
+
}
|
|
628
|
+
}
|
|
616
629
|
var DEFAULT_VIEW_STATE = {
|
|
617
630
|
latitude: 39.5,
|
|
618
631
|
longitude: -98.35,
|
|
@@ -882,9 +895,16 @@ function GeoMap({
|
|
|
882
895
|
const updateDimensions = () => {
|
|
883
896
|
if (containerRef.current) {
|
|
884
897
|
const rect = containerRef.current.getBoundingClientRect();
|
|
885
|
-
setContainerDimensions({
|
|
886
|
-
|
|
887
|
-
|
|
898
|
+
setContainerDimensions((prev) => {
|
|
899
|
+
const newWidth = rect.width || 800;
|
|
900
|
+
const newHeight = rect.height || calculatedHeight;
|
|
901
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
902
|
+
return prev;
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
width: newWidth,
|
|
906
|
+
height: newHeight
|
|
907
|
+
};
|
|
888
908
|
});
|
|
889
909
|
}
|
|
890
910
|
};
|
|
@@ -1018,6 +1038,10 @@ function GeoMap({
|
|
|
1018
1038
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
1019
1039
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
1020
1040
|
});
|
|
1041
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
|
|
1042
|
+
panelPosition
|
|
1043
|
+
);
|
|
1044
|
+
const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
|
|
1021
1045
|
React3__namespace.useEffect(() => {
|
|
1022
1046
|
if (!viewState && !defaultViewState) {
|
|
1023
1047
|
setUncontrolledViewState({
|
|
@@ -1029,6 +1053,9 @@ function GeoMap({
|
|
|
1029
1053
|
}, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
|
|
1030
1054
|
const isControlledViewState = viewState !== void 0;
|
|
1031
1055
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1056
|
+
React3__namespace.useEffect(() => {
|
|
1057
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1058
|
+
}, [resolvedViewState, uncontrolledViewState]);
|
|
1032
1059
|
const applyViewState = React3__namespace.useCallback(
|
|
1033
1060
|
(nextState) => {
|
|
1034
1061
|
if (!isControlledViewState) {
|
|
@@ -1097,6 +1124,17 @@ function GeoMap({
|
|
|
1097
1124
|
markerId: marker.id,
|
|
1098
1125
|
clusterId: marker.clusterId
|
|
1099
1126
|
});
|
|
1127
|
+
const currentState = viewStateRef.current;
|
|
1128
|
+
const center = {
|
|
1129
|
+
latitude: currentState.latitude ?? 0,
|
|
1130
|
+
longitude: currentState.longitude ?? 0
|
|
1131
|
+
};
|
|
1132
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1133
|
+
marker.latitude,
|
|
1134
|
+
marker.longitude,
|
|
1135
|
+
center
|
|
1136
|
+
);
|
|
1137
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1100
1138
|
applyViewState({
|
|
1101
1139
|
latitude: marker.latitude,
|
|
1102
1140
|
longitude: marker.longitude,
|
|
@@ -1112,6 +1150,17 @@ function GeoMap({
|
|
|
1112
1150
|
type: "cluster",
|
|
1113
1151
|
clusterId: cluster.id
|
|
1114
1152
|
});
|
|
1153
|
+
const currentState = viewStateRef.current;
|
|
1154
|
+
const center = {
|
|
1155
|
+
latitude: currentState.latitude ?? 0,
|
|
1156
|
+
longitude: currentState.longitude ?? 0
|
|
1157
|
+
};
|
|
1158
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1159
|
+
cluster.latitude,
|
|
1160
|
+
cluster.longitude,
|
|
1161
|
+
center
|
|
1162
|
+
);
|
|
1163
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1115
1164
|
applyViewState({
|
|
1116
1165
|
latitude: cluster.latitude,
|
|
1117
1166
|
longitude: cluster.longitude,
|
|
@@ -1406,7 +1455,7 @@ function GeoMap({
|
|
|
1406
1455
|
{
|
|
1407
1456
|
className: cn(
|
|
1408
1457
|
"pointer-events-none absolute z-30",
|
|
1409
|
-
PANEL_POSITION_CLASS[
|
|
1458
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1410
1459
|
),
|
|
1411
1460
|
style: {
|
|
1412
1461
|
// Ensure panel can overflow and has higher z-index
|