@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.js
CHANGED
|
@@ -749,6 +749,19 @@ var PANEL_POSITION_CLASS = {
|
|
|
749
749
|
"bottom-left": "bottom-4 left-4",
|
|
750
750
|
"bottom-right": "bottom-4 right-4"
|
|
751
751
|
};
|
|
752
|
+
function getOptimalPanelPosition(markerLat, markerLng, mapCenter) {
|
|
753
|
+
const isNorth = markerLat >= mapCenter.latitude;
|
|
754
|
+
const isEast = markerLng >= mapCenter.longitude;
|
|
755
|
+
if (isNorth && isEast) {
|
|
756
|
+
return "bottom-left";
|
|
757
|
+
} else if (isNorth && !isEast) {
|
|
758
|
+
return "bottom-right";
|
|
759
|
+
} else if (!isNorth && isEast) {
|
|
760
|
+
return "top-left";
|
|
761
|
+
} else {
|
|
762
|
+
return "top-right";
|
|
763
|
+
}
|
|
764
|
+
}
|
|
752
765
|
var DEFAULT_VIEW_STATE = {
|
|
753
766
|
latitude: 39.5,
|
|
754
767
|
longitude: -98.35,
|
|
@@ -1018,9 +1031,16 @@ function GeoMap({
|
|
|
1018
1031
|
const updateDimensions = () => {
|
|
1019
1032
|
if (containerRef.current) {
|
|
1020
1033
|
const rect = containerRef.current.getBoundingClientRect();
|
|
1021
|
-
setContainerDimensions({
|
|
1022
|
-
|
|
1023
|
-
|
|
1034
|
+
setContainerDimensions((prev) => {
|
|
1035
|
+
const newWidth = rect.width || 800;
|
|
1036
|
+
const newHeight = rect.height || calculatedHeight;
|
|
1037
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
1038
|
+
return prev;
|
|
1039
|
+
}
|
|
1040
|
+
return {
|
|
1041
|
+
width: newWidth,
|
|
1042
|
+
height: newHeight
|
|
1043
|
+
};
|
|
1024
1044
|
});
|
|
1025
1045
|
}
|
|
1026
1046
|
};
|
|
@@ -1154,6 +1174,10 @@ function GeoMap({
|
|
|
1154
1174
|
longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
|
|
1155
1175
|
zoom: defaultViewState?.zoom ?? calculatedZoom
|
|
1156
1176
|
});
|
|
1177
|
+
const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
|
|
1178
|
+
panelPosition
|
|
1179
|
+
);
|
|
1180
|
+
const viewStateRef = React3.useRef(uncontrolledViewState);
|
|
1157
1181
|
React3.useEffect(() => {
|
|
1158
1182
|
if (!viewState && !defaultViewState) {
|
|
1159
1183
|
setUncontrolledViewState({
|
|
@@ -1165,6 +1189,9 @@ function GeoMap({
|
|
|
1165
1189
|
}, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
|
|
1166
1190
|
const isControlledViewState = viewState !== void 0;
|
|
1167
1191
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1192
|
+
React3.useEffect(() => {
|
|
1193
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1194
|
+
}, [resolvedViewState, uncontrolledViewState]);
|
|
1168
1195
|
const applyViewState = React3.useCallback(
|
|
1169
1196
|
(nextState) => {
|
|
1170
1197
|
if (!isControlledViewState) {
|
|
@@ -1233,6 +1260,17 @@ function GeoMap({
|
|
|
1233
1260
|
markerId: marker.id,
|
|
1234
1261
|
clusterId: marker.clusterId
|
|
1235
1262
|
});
|
|
1263
|
+
const currentState = viewStateRef.current;
|
|
1264
|
+
const center = {
|
|
1265
|
+
latitude: currentState.latitude ?? 0,
|
|
1266
|
+
longitude: currentState.longitude ?? 0
|
|
1267
|
+
};
|
|
1268
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1269
|
+
marker.latitude,
|
|
1270
|
+
marker.longitude,
|
|
1271
|
+
center
|
|
1272
|
+
);
|
|
1273
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1236
1274
|
applyViewState({
|
|
1237
1275
|
latitude: marker.latitude,
|
|
1238
1276
|
longitude: marker.longitude,
|
|
@@ -1248,6 +1286,17 @@ function GeoMap({
|
|
|
1248
1286
|
type: "cluster",
|
|
1249
1287
|
clusterId: cluster.id
|
|
1250
1288
|
});
|
|
1289
|
+
const currentState = viewStateRef.current;
|
|
1290
|
+
const center = {
|
|
1291
|
+
latitude: currentState.latitude ?? 0,
|
|
1292
|
+
longitude: currentState.longitude ?? 0
|
|
1293
|
+
};
|
|
1294
|
+
const optimalPosition = getOptimalPanelPosition(
|
|
1295
|
+
cluster.latitude,
|
|
1296
|
+
cluster.longitude,
|
|
1297
|
+
center
|
|
1298
|
+
);
|
|
1299
|
+
setDynamicPanelPosition(optimalPosition);
|
|
1251
1300
|
applyViewState({
|
|
1252
1301
|
latitude: cluster.latitude,
|
|
1253
1302
|
longitude: cluster.longitude,
|
|
@@ -1542,7 +1591,7 @@ function GeoMap({
|
|
|
1542
1591
|
{
|
|
1543
1592
|
className: cn(
|
|
1544
1593
|
"pointer-events-none absolute z-30",
|
|
1545
|
-
PANEL_POSITION_CLASS[
|
|
1594
|
+
PANEL_POSITION_CLASS[dynamicPanelPosition]
|
|
1546
1595
|
),
|
|
1547
1596
|
style: {
|
|
1548
1597
|
// Ensure panel can overflow and has higher z-index
|