@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
package/dist/components/index.js
CHANGED
|
@@ -711,6 +711,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
711
711
|
"bottom-left": "bottom-4 left-4",
|
|
712
712
|
"bottom-right": "bottom-4 right-4"
|
|
713
713
|
};
|
|
714
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
715
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
716
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
717
|
+
if (isNorth && isEast) {
|
|
718
|
+
return "bottom-left";
|
|
719
|
+
} else if (isNorth && !isEast) {
|
|
720
|
+
return "bottom-right";
|
|
721
|
+
} else if (!isNorth && isEast) {
|
|
722
|
+
return "top-left";
|
|
723
|
+
} else {
|
|
724
|
+
return "top-right";
|
|
725
|
+
}
|
|
726
|
+
}
|
|
714
727
|
var DEFAULT_VIEW_STATE = {
|
|
715
728
|
latitude: 39.5,
|
|
716
729
|
longitude: -98.35,
|
|
@@ -1116,6 +1129,9 @@ function GeoMap({
|
|
|
1116
1129
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
1117
1130
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
1118
1131
|
});
|
|
1132
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
|
|
1133
|
+
panelPosition
|
|
1134
|
+
);
|
|
1119
1135
|
React3.useEffect(() => {
|
|
1120
1136
|
if (!viewState && !defaultViewState) {
|
|
1121
1137
|
setUncontrolledViewState({
|
|
@@ -1195,6 +1211,19 @@ function GeoMap({
|
|
|
1195
1211
|
markerId: marker.id,
|
|
1196
1212
|
clusterId: marker.clusterId
|
|
1197
1213
|
});
|
|
1214
|
+
const currentCenter = resolvedViewState || {
|
|
1215
|
+
latitude: firstCoordinate.latitude,
|
|
1216
|
+
longitude: firstCoordinate.longitude
|
|
1217
|
+
};
|
|
1218
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1219
|
+
marker.latitude,
|
|
1220
|
+
marker.longitude,
|
|
1221
|
+
{
|
|
1222
|
+
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1223
|
+
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1224
|
+
}
|
|
1225
|
+
);
|
|
1226
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1198
1227
|
applyViewState({
|
|
1199
1228
|
latitude: marker.latitude,
|
|
1200
1229
|
longitude: marker.longitude,
|
|
@@ -1202,7 +1231,7 @@ function GeoMap({
|
|
|
1202
1231
|
});
|
|
1203
1232
|
emitSelectionChange({ type: "marker", marker });
|
|
1204
1233
|
},
|
|
1205
|
-
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
1234
|
+
[applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
|
|
1206
1235
|
);
|
|
1207
1236
|
const selectCluster = React3.useCallback(
|
|
1208
1237
|
(cluster) => {
|
|
@@ -1210,6 +1239,19 @@ function GeoMap({
|
|
|
1210
1239
|
type: "cluster",
|
|
1211
1240
|
clusterId: cluster.id
|
|
1212
1241
|
});
|
|
1242
|
+
const currentCenter = resolvedViewState || {
|
|
1243
|
+
latitude: firstCoordinate.latitude,
|
|
1244
|
+
longitude: firstCoordinate.longitude
|
|
1245
|
+
};
|
|
1246
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1247
|
+
cluster.latitude,
|
|
1248
|
+
cluster.longitude,
|
|
1249
|
+
{
|
|
1250
|
+
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1251
|
+
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1252
|
+
}
|
|
1253
|
+
);
|
|
1254
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1213
1255
|
applyViewState({
|
|
1214
1256
|
latitude: cluster.latitude,
|
|
1215
1257
|
longitude: cluster.longitude,
|
|
@@ -1217,7 +1259,7 @@ function GeoMap({
|
|
|
1217
1259
|
});
|
|
1218
1260
|
emitSelectionChange({ type: "cluster", cluster });
|
|
1219
1261
|
},
|
|
1220
|
-
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
1262
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
|
|
1221
1263
|
);
|
|
1222
1264
|
const clearSelection = React3.useCallback(() => {
|
|
1223
1265
|
setSelection({ type: "none" });
|
|
@@ -1504,7 +1546,7 @@ function GeoMap({
|
|
|
1504
1546
|
{
|
|
1505
1547
|
className: cn(
|
|
1506
1548
|
"pointer-events-none absolute z-30",
|
|
1507
|
-
PANEL_POSITION_CLASS[
|
|
1549
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1508
1550
|
),
|
|
1509
1551
|
style: {
|
|
1510
1552
|
// Ensure panel can overflow and has higher z-index
|