@page-speed/maps 0.2.0 → 0.2.1
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 +45 -3
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.js +45 -3
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +45 -3
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +45 -3
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +45 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -592,6 +592,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
592
592
|
"bottom-left": "bottom-4 left-4",
|
|
593
593
|
"bottom-right": "bottom-4 right-4"
|
|
594
594
|
};
|
|
595
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
596
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
597
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
598
|
+
if (isNorth && isEast) {
|
|
599
|
+
return "bottom-left";
|
|
600
|
+
} else if (isNorth && !isEast) {
|
|
601
|
+
return "bottom-right";
|
|
602
|
+
} else if (!isNorth && isEast) {
|
|
603
|
+
return "top-left";
|
|
604
|
+
} else {
|
|
605
|
+
return "top-right";
|
|
606
|
+
}
|
|
607
|
+
}
|
|
595
608
|
var DEFAULT_VIEW_STATE = {
|
|
596
609
|
latitude: 39.5,
|
|
597
610
|
longitude: -98.35,
|
|
@@ -997,6 +1010,9 @@ function GeoMap({
|
|
|
997
1010
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
998
1011
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
999
1012
|
});
|
|
1013
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
|
|
1014
|
+
panelPosition
|
|
1015
|
+
);
|
|
1000
1016
|
React3.useEffect(() => {
|
|
1001
1017
|
if (!viewState && !defaultViewState) {
|
|
1002
1018
|
setUncontrolledViewState({
|
|
@@ -1076,6 +1092,19 @@ function GeoMap({
|
|
|
1076
1092
|
markerId: marker.id,
|
|
1077
1093
|
clusterId: marker.clusterId
|
|
1078
1094
|
});
|
|
1095
|
+
const currentCenter = resolvedViewState || {
|
|
1096
|
+
latitude: firstCoordinate.latitude,
|
|
1097
|
+
longitude: firstCoordinate.longitude
|
|
1098
|
+
};
|
|
1099
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1100
|
+
marker.latitude,
|
|
1101
|
+
marker.longitude,
|
|
1102
|
+
{
|
|
1103
|
+
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1104
|
+
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1105
|
+
}
|
|
1106
|
+
);
|
|
1107
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1079
1108
|
applyViewState({
|
|
1080
1109
|
latitude: marker.latitude,
|
|
1081
1110
|
longitude: marker.longitude,
|
|
@@ -1083,7 +1112,7 @@ function GeoMap({
|
|
|
1083
1112
|
});
|
|
1084
1113
|
emitSelectionChange({ type: "marker", marker });
|
|
1085
1114
|
},
|
|
1086
|
-
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
1115
|
+
[applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
|
|
1087
1116
|
);
|
|
1088
1117
|
const selectCluster = React3.useCallback(
|
|
1089
1118
|
(cluster) => {
|
|
@@ -1091,6 +1120,19 @@ function GeoMap({
|
|
|
1091
1120
|
type: "cluster",
|
|
1092
1121
|
clusterId: cluster.id
|
|
1093
1122
|
});
|
|
1123
|
+
const currentCenter = resolvedViewState || {
|
|
1124
|
+
latitude: firstCoordinate.latitude,
|
|
1125
|
+
longitude: firstCoordinate.longitude
|
|
1126
|
+
};
|
|
1127
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1128
|
+
cluster.latitude,
|
|
1129
|
+
cluster.longitude,
|
|
1130
|
+
{
|
|
1131
|
+
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1132
|
+
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1094
1136
|
applyViewState({
|
|
1095
1137
|
latitude: cluster.latitude,
|
|
1096
1138
|
longitude: cluster.longitude,
|
|
@@ -1098,7 +1140,7 @@ function GeoMap({
|
|
|
1098
1140
|
});
|
|
1099
1141
|
emitSelectionChange({ type: "cluster", cluster });
|
|
1100
1142
|
},
|
|
1101
|
-
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
1143
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
|
|
1102
1144
|
);
|
|
1103
1145
|
const clearSelection = React3.useCallback(() => {
|
|
1104
1146
|
setSelection({ type: "none" });
|
|
@@ -1385,7 +1427,7 @@ function GeoMap({
|
|
|
1385
1427
|
{
|
|
1386
1428
|
className: cn(
|
|
1387
1429
|
"pointer-events-none absolute z-30",
|
|
1388
|
-
PANEL_POSITION_CLASS[
|
|
1430
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1389
1431
|
),
|
|
1390
1432
|
style: {
|
|
1391
1433
|
// Ensure panel can overflow and has higher z-index
|