@page-speed/maps 0.2.1 → 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.
@@ -874,9 +874,16 @@ function GeoMap({
874
874
  const updateDimensions = () => {
875
875
  if (containerRef.current) {
876
876
  const rect = containerRef.current.getBoundingClientRect();
877
- setContainerDimensions({
878
- width: rect.width || 800,
879
- height: rect.height || calculatedHeight
877
+ setContainerDimensions((prev) => {
878
+ const newWidth = rect.width || 800;
879
+ const newHeight = rect.height || calculatedHeight;
880
+ if (prev.width === newWidth && prev.height === newHeight) {
881
+ return prev;
882
+ }
883
+ return {
884
+ width: newWidth,
885
+ height: newHeight
886
+ };
880
887
  });
881
888
  }
882
889
  };
@@ -1013,6 +1020,7 @@ function GeoMap({
1013
1020
  const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
1014
1021
  panelPosition
1015
1022
  );
1023
+ const viewStateRef = React3.useRef(uncontrolledViewState);
1016
1024
  React3.useEffect(() => {
1017
1025
  if (!viewState && !defaultViewState) {
1018
1026
  setUncontrolledViewState({
@@ -1024,6 +1032,9 @@ function GeoMap({
1024
1032
  }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
1025
1033
  const isControlledViewState = viewState !== void 0;
1026
1034
  const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
1035
+ React3.useEffect(() => {
1036
+ viewStateRef.current = resolvedViewState || uncontrolledViewState;
1037
+ }, [resolvedViewState, uncontrolledViewState]);
1027
1038
  const applyViewState = React3.useCallback(
1028
1039
  (nextState) => {
1029
1040
  if (!isControlledViewState) {
@@ -1092,17 +1103,15 @@ function GeoMap({
1092
1103
  markerId: marker.id,
1093
1104
  clusterId: marker.clusterId
1094
1105
  });
1095
- const currentCenter = resolvedViewState || {
1096
- latitude: firstCoordinate.latitude,
1097
- longitude: firstCoordinate.longitude
1106
+ const currentState = viewStateRef.current;
1107
+ const center = {
1108
+ latitude: currentState.latitude ?? 0,
1109
+ longitude: currentState.longitude ?? 0
1098
1110
  };
1099
1111
  const optimalPosition = getOptimalPanelPosition(
1100
1112
  marker.latitude,
1101
1113
  marker.longitude,
1102
- {
1103
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1104
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1105
- }
1114
+ center
1106
1115
  );
1107
1116
  setDynamicPanelPosition(optimalPosition);
1108
1117
  applyViewState({
@@ -1112,7 +1121,7 @@ function GeoMap({
1112
1121
  });
1113
1122
  emitSelectionChange({ type: "marker", marker });
1114
1123
  },
1115
- [applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
1124
+ [applyViewState, emitSelectionChange, markerFocusZoom]
1116
1125
  );
1117
1126
  const selectCluster = React3.useCallback(
1118
1127
  (cluster) => {
@@ -1120,17 +1129,15 @@ function GeoMap({
1120
1129
  type: "cluster",
1121
1130
  clusterId: cluster.id
1122
1131
  });
1123
- const currentCenter = resolvedViewState || {
1124
- latitude: firstCoordinate.latitude,
1125
- longitude: firstCoordinate.longitude
1132
+ const currentState = viewStateRef.current;
1133
+ const center = {
1134
+ latitude: currentState.latitude ?? 0,
1135
+ longitude: currentState.longitude ?? 0
1126
1136
  };
1127
1137
  const optimalPosition = getOptimalPanelPosition(
1128
1138
  cluster.latitude,
1129
1139
  cluster.longitude,
1130
- {
1131
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1132
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1133
- }
1140
+ center
1134
1141
  );
1135
1142
  setDynamicPanelPosition(optimalPosition);
1136
1143
  applyViewState({
@@ -1140,7 +1147,7 @@ function GeoMap({
1140
1147
  });
1141
1148
  emitSelectionChange({ type: "cluster", cluster });
1142
1149
  },
1143
- [applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
1150
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
1144
1151
  );
1145
1152
  const clearSelection = React3.useCallback(() => {
1146
1153
  setSelection({ type: "none" });