@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
|
@@ -732,6 +732,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
732
732
|
"bottom-left": "bottom-4 left-4",
|
|
733
733
|
"bottom-right": "bottom-4 right-4"
|
|
734
734
|
};
|
|
735
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
736
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
737
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
738
|
+
if (isNorth && isEast) {
|
|
739
|
+
return "bottom-left";
|
|
740
|
+
} else if (isNorth && !isEast) {
|
|
741
|
+
return "bottom-right";
|
|
742
|
+
} else if (!isNorth && isEast) {
|
|
743
|
+
return "top-left";
|
|
744
|
+
} else {
|
|
745
|
+
return "top-right";
|
|
746
|
+
}
|
|
747
|
+
}
|
|
735
748
|
var DEFAULT_VIEW_STATE = {
|
|
736
749
|
latitude: 39.5,
|
|
737
750
|
longitude: -98.35,
|
|
@@ -1001,9 +1014,16 @@ function GeoMap({
|
|
|
1001
1014
|
const updateDimensions = () => {
|
|
1002
1015
|
if (containerRef.current) {
|
|
1003
1016
|
const rect = containerRef.current.getBoundingClientRect();
|
|
1004
|
-
setContainerDimensions({
|
|
1005
|
-
|
|
1006
|
-
|
|
1017
|
+
setContainerDimensions((prev) => {
|
|
1018
|
+
const newWidth = rect.width || 800;
|
|
1019
|
+
const newHeight = rect.height || calculatedHeight;
|
|
1020
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
1021
|
+
return prev;
|
|
1022
|
+
}
|
|
1023
|
+
return {
|
|
1024
|
+
width: newWidth,
|
|
1025
|
+
height: newHeight
|
|
1026
|
+
};
|
|
1007
1027
|
});
|
|
1008
1028
|
}
|
|
1009
1029
|
};
|
|
@@ -1137,6 +1157,10 @@ function GeoMap({
|
|
|
1137
1157
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
1138
1158
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
1139
1159
|
});
|
|
1160
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
|
|
1161
|
+
panelPosition
|
|
1162
|
+
);
|
|
1163
|
+
const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
|
|
1140
1164
|
React3__namespace.useEffect(() => {
|
|
1141
1165
|
if (!viewState && !defaultViewState) {
|
|
1142
1166
|
setUncontrolledViewState({
|
|
@@ -1148,6 +1172,9 @@ function GeoMap({
|
|
|
1148
1172
|
}, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
|
|
1149
1173
|
const isControlledViewState = viewState !== void 0;
|
|
1150
1174
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1175
|
+
React3__namespace.useEffect(() => {
|
|
1176
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1177
|
+
}, [resolvedViewState, uncontrolledViewState]);
|
|
1151
1178
|
const applyViewState = React3__namespace.useCallback(
|
|
1152
1179
|
(nextState) => {
|
|
1153
1180
|
if (!isControlledViewState) {
|
|
@@ -1216,6 +1243,17 @@ function GeoMap({
|
|
|
1216
1243
|
markerId: marker.id,
|
|
1217
1244
|
clusterId: marker.clusterId
|
|
1218
1245
|
});
|
|
1246
|
+
const currentState = viewStateRef.current;
|
|
1247
|
+
const center = {
|
|
1248
|
+
latitude: currentState.latitude ?? 0,
|
|
1249
|
+
longitude: currentState.longitude ?? 0
|
|
1250
|
+
};
|
|
1251
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1252
|
+
marker.latitude,
|
|
1253
|
+
marker.longitude,
|
|
1254
|
+
center
|
|
1255
|
+
);
|
|
1256
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1219
1257
|
applyViewState({
|
|
1220
1258
|
latitude: marker.latitude,
|
|
1221
1259
|
longitude: marker.longitude,
|
|
@@ -1231,6 +1269,17 @@ function GeoMap({
|
|
|
1231
1269
|
type: "cluster",
|
|
1232
1270
|
clusterId: cluster.id
|
|
1233
1271
|
});
|
|
1272
|
+
const currentState = viewStateRef.current;
|
|
1273
|
+
const center = {
|
|
1274
|
+
latitude: currentState.latitude ?? 0,
|
|
1275
|
+
longitude: currentState.longitude ?? 0
|
|
1276
|
+
};
|
|
1277
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1278
|
+
cluster.latitude,
|
|
1279
|
+
cluster.longitude,
|
|
1280
|
+
center
|
|
1281
|
+
);
|
|
1282
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1234
1283
|
applyViewState({
|
|
1235
1284
|
latitude: cluster.latitude,
|
|
1236
1285
|
longitude: cluster.longitude,
|
|
@@ -1525,7 +1574,7 @@ function GeoMap({
|
|
|
1525
1574
|
{
|
|
1526
1575
|
className: cn(
|
|
1527
1576
|
"pointer-events-none absolute z-30",
|
|
1528
|
-
PANEL_POSITION_CLASS[
|
|
1577
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1529
1578
|
),
|
|
1530
1579
|
style: {
|
|
1531
1580
|
// Ensure panel can overflow and has higher z-index
|