@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.
package/dist/index.cjs CHANGED
@@ -1052,9 +1052,16 @@ function GeoMap({
1052
1052
  const updateDimensions = () => {
1053
1053
  if (containerRef.current) {
1054
1054
  const rect = containerRef.current.getBoundingClientRect();
1055
- setContainerDimensions({
1056
- width: rect.width || 800,
1057
- height: rect.height || calculatedHeight
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
+ };
1058
1065
  });
1059
1066
  }
1060
1067
  };
@@ -1191,6 +1198,7 @@ function GeoMap({
1191
1198
  const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
1192
1199
  panelPosition
1193
1200
  );
1201
+ const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
1194
1202
  React3__namespace.useEffect(() => {
1195
1203
  if (!viewState && !defaultViewState) {
1196
1204
  setUncontrolledViewState({
@@ -1202,6 +1210,9 @@ function GeoMap({
1202
1210
  }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
1203
1211
  const isControlledViewState = viewState !== void 0;
1204
1212
  const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
1213
+ React3__namespace.useEffect(() => {
1214
+ viewStateRef.current = resolvedViewState || uncontrolledViewState;
1215
+ }, [resolvedViewState, uncontrolledViewState]);
1205
1216
  const applyViewState = React3__namespace.useCallback(
1206
1217
  (nextState) => {
1207
1218
  if (!isControlledViewState) {
@@ -1270,17 +1281,15 @@ function GeoMap({
1270
1281
  markerId: marker.id,
1271
1282
  clusterId: marker.clusterId
1272
1283
  });
1273
- const currentCenter = resolvedViewState || {
1274
- latitude: firstCoordinate.latitude,
1275
- longitude: firstCoordinate.longitude
1284
+ const currentState = viewStateRef.current;
1285
+ const center = {
1286
+ latitude: currentState.latitude ?? 0,
1287
+ longitude: currentState.longitude ?? 0
1276
1288
  };
1277
1289
  const optimalPosition = getOptimalPanelPosition(
1278
1290
  marker.latitude,
1279
1291
  marker.longitude,
1280
- {
1281
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1282
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1283
- }
1292
+ center
1284
1293
  );
1285
1294
  setDynamicPanelPosition(optimalPosition);
1286
1295
  applyViewState({
@@ -1290,7 +1299,7 @@ function GeoMap({
1290
1299
  });
1291
1300
  emitSelectionChange({ type: "marker", marker });
1292
1301
  },
1293
- [applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
1302
+ [applyViewState, emitSelectionChange, markerFocusZoom]
1294
1303
  );
1295
1304
  const selectCluster = React3__namespace.useCallback(
1296
1305
  (cluster) => {
@@ -1298,17 +1307,15 @@ function GeoMap({
1298
1307
  type: "cluster",
1299
1308
  clusterId: cluster.id
1300
1309
  });
1301
- const currentCenter = resolvedViewState || {
1302
- latitude: firstCoordinate.latitude,
1303
- longitude: firstCoordinate.longitude
1310
+ const currentState = viewStateRef.current;
1311
+ const center = {
1312
+ latitude: currentState.latitude ?? 0,
1313
+ longitude: currentState.longitude ?? 0
1304
1314
  };
1305
1315
  const optimalPosition = getOptimalPanelPosition(
1306
1316
  cluster.latitude,
1307
1317
  cluster.longitude,
1308
- {
1309
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1310
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1311
- }
1318
+ center
1312
1319
  );
1313
1320
  setDynamicPanelPosition(optimalPosition);
1314
1321
  applyViewState({
@@ -1318,7 +1325,7 @@ function GeoMap({
1318
1325
  });
1319
1326
  emitSelectionChange({ type: "cluster", cluster });
1320
1327
  },
1321
- [applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
1328
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
1322
1329
  );
1323
1330
  const clearSelection = React3__namespace.useCallback(() => {
1324
1331
  setSelection({ type: "none" });