@page-speed/maps 0.2.1 → 0.2.3
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 +58 -25
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.js +58 -25
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +58 -25
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +58 -25
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +58 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1031,9 +1031,16 @@ function GeoMap({
|
|
|
1031
1031
|
const updateDimensions = () => {
|
|
1032
1032
|
if (containerRef.current) {
|
|
1033
1033
|
const rect = containerRef.current.getBoundingClientRect();
|
|
1034
|
-
setContainerDimensions({
|
|
1035
|
-
|
|
1036
|
-
|
|
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
|
+
};
|
|
1037
1044
|
});
|
|
1038
1045
|
}
|
|
1039
1046
|
};
|
|
@@ -1170,17 +1177,41 @@ function GeoMap({
|
|
|
1170
1177
|
const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
|
|
1171
1178
|
panelPosition
|
|
1172
1179
|
);
|
|
1180
|
+
const viewStateRef = React3.useRef(uncontrolledViewState);
|
|
1173
1181
|
React3.useEffect(() => {
|
|
1174
1182
|
if (!viewState && !defaultViewState) {
|
|
1175
|
-
setUncontrolledViewState({
|
|
1176
|
-
latitude
|
|
1177
|
-
|
|
1178
|
-
|
|
1183
|
+
setUncontrolledViewState((prev) => {
|
|
1184
|
+
if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
|
|
1185
|
+
return prev;
|
|
1186
|
+
}
|
|
1187
|
+
return {
|
|
1188
|
+
latitude: firstCoordinate.latitude,
|
|
1189
|
+
longitude: firstCoordinate.longitude,
|
|
1190
|
+
zoom: calculatedZoom
|
|
1191
|
+
};
|
|
1179
1192
|
});
|
|
1180
1193
|
}
|
|
1181
|
-
}, [
|
|
1194
|
+
}, [
|
|
1195
|
+
// Use primitive values instead of objects to avoid reference changes
|
|
1196
|
+
firstCoordinate.latitude,
|
|
1197
|
+
firstCoordinate.longitude,
|
|
1198
|
+
calculatedZoom,
|
|
1199
|
+
viewState,
|
|
1200
|
+
defaultViewState
|
|
1201
|
+
]);
|
|
1182
1202
|
const isControlledViewState = viewState !== void 0;
|
|
1183
1203
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1204
|
+
React3.useEffect(() => {
|
|
1205
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1206
|
+
}, [
|
|
1207
|
+
// Use primitive values to avoid reference changes
|
|
1208
|
+
resolvedViewState?.latitude,
|
|
1209
|
+
resolvedViewState?.longitude,
|
|
1210
|
+
resolvedViewState?.zoom,
|
|
1211
|
+
uncontrolledViewState.latitude,
|
|
1212
|
+
uncontrolledViewState.longitude,
|
|
1213
|
+
uncontrolledViewState.zoom
|
|
1214
|
+
]);
|
|
1184
1215
|
const applyViewState = React3.useCallback(
|
|
1185
1216
|
(nextState) => {
|
|
1186
1217
|
if (!isControlledViewState) {
|
|
@@ -1219,7 +1250,13 @@ function GeoMap({
|
|
|
1219
1250
|
setSelection({ type: "none" });
|
|
1220
1251
|
onSelectionChange?.({ type: "none" });
|
|
1221
1252
|
}
|
|
1222
|
-
}, [
|
|
1253
|
+
}, [
|
|
1254
|
+
// Use primitive values to avoid object reference issues
|
|
1255
|
+
selection.type,
|
|
1256
|
+
selection.markerId,
|
|
1257
|
+
selectedMarker?.id,
|
|
1258
|
+
onSelectionChange
|
|
1259
|
+
]);
|
|
1223
1260
|
const emitSelectionChange = React3.useCallback(
|
|
1224
1261
|
(nextSelection) => {
|
|
1225
1262
|
if (nextSelection.type === "none") {
|
|
@@ -1249,17 +1286,15 @@ function GeoMap({
|
|
|
1249
1286
|
markerId: marker.id,
|
|
1250
1287
|
clusterId: marker.clusterId
|
|
1251
1288
|
});
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1254
|
-
|
|
1289
|
+
const currentState = viewStateRef.current;
|
|
1290
|
+
const center = {
|
|
1291
|
+
latitude: currentState.latitude ?? 0,
|
|
1292
|
+
longitude: currentState.longitude ?? 0
|
|
1255
1293
|
};
|
|
1256
1294
|
const optimalPosition = getOptimalPanelPosition(
|
|
1257
1295
|
marker.latitude,
|
|
1258
1296
|
marker.longitude,
|
|
1259
|
-
|
|
1260
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1261
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1262
|
-
}
|
|
1297
|
+
center
|
|
1263
1298
|
);
|
|
1264
1299
|
setDynamicPanelPosition(optimalPosition);
|
|
1265
1300
|
applyViewState({
|
|
@@ -1269,7 +1304,7 @@ function GeoMap({
|
|
|
1269
1304
|
});
|
|
1270
1305
|
emitSelectionChange({ type: "marker", marker });
|
|
1271
1306
|
},
|
|
1272
|
-
[applyViewState, emitSelectionChange, markerFocusZoom
|
|
1307
|
+
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
1273
1308
|
);
|
|
1274
1309
|
const selectCluster = React3.useCallback(
|
|
1275
1310
|
(cluster) => {
|
|
@@ -1277,17 +1312,15 @@ function GeoMap({
|
|
|
1277
1312
|
type: "cluster",
|
|
1278
1313
|
clusterId: cluster.id
|
|
1279
1314
|
});
|
|
1280
|
-
const
|
|
1281
|
-
|
|
1282
|
-
|
|
1315
|
+
const currentState = viewStateRef.current;
|
|
1316
|
+
const center = {
|
|
1317
|
+
latitude: currentState.latitude ?? 0,
|
|
1318
|
+
longitude: currentState.longitude ?? 0
|
|
1283
1319
|
};
|
|
1284
1320
|
const optimalPosition = getOptimalPanelPosition(
|
|
1285
1321
|
cluster.latitude,
|
|
1286
1322
|
cluster.longitude,
|
|
1287
|
-
|
|
1288
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1289
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1290
|
-
}
|
|
1323
|
+
center
|
|
1291
1324
|
);
|
|
1292
1325
|
setDynamicPanelPosition(optimalPosition);
|
|
1293
1326
|
applyViewState({
|
|
@@ -1297,7 +1330,7 @@ function GeoMap({
|
|
|
1297
1330
|
});
|
|
1298
1331
|
emitSelectionChange({ type: "cluster", cluster });
|
|
1299
1332
|
},
|
|
1300
|
-
[applyViewState, clusterFocusZoom, emitSelectionChange
|
|
1333
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
1301
1334
|
);
|
|
1302
1335
|
const clearSelection = React3.useCallback(() => {
|
|
1303
1336
|
setSelection({ type: "none" });
|