@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
package/dist/index.cjs
CHANGED
|
@@ -770,6 +770,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
770
770
|
"bottom-left": "bottom-4 left-4",
|
|
771
771
|
"bottom-right": "bottom-4 right-4"
|
|
772
772
|
};
|
|
773
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
774
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
775
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
776
|
+
if (isNorth && isEast) {
|
|
777
|
+
return "bottom-left";
|
|
778
|
+
} else if (isNorth && !isEast) {
|
|
779
|
+
return "bottom-right";
|
|
780
|
+
} else if (!isNorth && isEast) {
|
|
781
|
+
return "top-left";
|
|
782
|
+
} else {
|
|
783
|
+
return "top-right";
|
|
784
|
+
}
|
|
785
|
+
}
|
|
773
786
|
var DEFAULT_VIEW_STATE = {
|
|
774
787
|
latitude: 39.5,
|
|
775
788
|
longitude: -98.35,
|
|
@@ -1039,9 +1052,16 @@ function GeoMap({
|
|
|
1039
1052
|
const updateDimensions = () => {
|
|
1040
1053
|
if (containerRef.current) {
|
|
1041
1054
|
const rect = containerRef.current.getBoundingClientRect();
|
|
1042
|
-
setContainerDimensions({
|
|
1043
|
-
|
|
1044
|
-
|
|
1055
|
+
setContainerDimensions((prev) => {
|
|
1056
|
+
const newWidth = rect.width || 800;
|
|
1057
|
+
const newHeight = rect.height || calculatedHeight;
|
|
1058
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
1059
|
+
return prev;
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
width: newWidth,
|
|
1063
|
+
height: newHeight
|
|
1064
|
+
};
|
|
1045
1065
|
});
|
|
1046
1066
|
}
|
|
1047
1067
|
};
|
|
@@ -1175,6 +1195,10 @@ function GeoMap({
|
|
|
1175
1195
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
1176
1196
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
1177
1197
|
});
|
|
1198
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
|
|
1199
|
+
panelPosition
|
|
1200
|
+
);
|
|
1201
|
+
const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
|
|
1178
1202
|
React3__namespace.useEffect(() => {
|
|
1179
1203
|
if (!viewState && !defaultViewState) {
|
|
1180
1204
|
setUncontrolledViewState({
|
|
@@ -1186,6 +1210,9 @@ function GeoMap({
|
|
|
1186
1210
|
}, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
|
|
1187
1211
|
const isControlledViewState = viewState !== void 0;
|
|
1188
1212
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1213
|
+
React3__namespace.useEffect(() => {
|
|
1214
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1215
|
+
}, [resolvedViewState, uncontrolledViewState]);
|
|
1189
1216
|
const applyViewState = React3__namespace.useCallback(
|
|
1190
1217
|
(nextState) => {
|
|
1191
1218
|
if (!isControlledViewState) {
|
|
@@ -1254,6 +1281,17 @@ function GeoMap({
|
|
|
1254
1281
|
markerId: marker.id,
|
|
1255
1282
|
clusterId: marker.clusterId
|
|
1256
1283
|
});
|
|
1284
|
+
const currentState = viewStateRef.current;
|
|
1285
|
+
const center = {
|
|
1286
|
+
latitude: currentState.latitude ?? 0,
|
|
1287
|
+
longitude: currentState.longitude ?? 0
|
|
1288
|
+
};
|
|
1289
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1290
|
+
marker.latitude,
|
|
1291
|
+
marker.longitude,
|
|
1292
|
+
center
|
|
1293
|
+
);
|
|
1294
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1257
1295
|
applyViewState({
|
|
1258
1296
|
latitude: marker.latitude,
|
|
1259
1297
|
longitude: marker.longitude,
|
|
@@ -1269,6 +1307,17 @@ function GeoMap({
|
|
|
1269
1307
|
type: "cluster",
|
|
1270
1308
|
clusterId: cluster.id
|
|
1271
1309
|
});
|
|
1310
|
+
const currentState = viewStateRef.current;
|
|
1311
|
+
const center = {
|
|
1312
|
+
latitude: currentState.latitude ?? 0,
|
|
1313
|
+
longitude: currentState.longitude ?? 0
|
|
1314
|
+
};
|
|
1315
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1316
|
+
cluster.latitude,
|
|
1317
|
+
cluster.longitude,
|
|
1318
|
+
center
|
|
1319
|
+
);
|
|
1320
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1272
1321
|
applyViewState({
|
|
1273
1322
|
latitude: cluster.latitude,
|
|
1274
1323
|
longitude: cluster.longitude,
|
|
@@ -1563,7 +1612,7 @@ function GeoMap({
|
|
|
1563
1612
|
{
|
|
1564
1613
|
className: cn(
|
|
1565
1614
|
"pointer-events-none absolute z-30",
|
|
1566
|
-
PANEL_POSITION_CLASS[
|
|
1615
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1567
1616
|
),
|
|
1568
1617
|
style: {
|
|
1569
1618
|
// Ensure panel can overflow and has higher z-index
|