@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/components/index.js
CHANGED
|
@@ -993,9 +993,16 @@ function GeoMap({
|
|
|
993
993
|
const updateDimensions = () => {
|
|
994
994
|
if (containerRef.current) {
|
|
995
995
|
const rect = containerRef.current.getBoundingClientRect();
|
|
996
|
-
setContainerDimensions({
|
|
997
|
-
|
|
998
|
-
|
|
996
|
+
setContainerDimensions((prev) => {
|
|
997
|
+
const newWidth = rect.width || 800;
|
|
998
|
+
const newHeight = rect.height || calculatedHeight;
|
|
999
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
1000
|
+
return prev;
|
|
1001
|
+
}
|
|
1002
|
+
return {
|
|
1003
|
+
width: newWidth,
|
|
1004
|
+
height: newHeight
|
|
1005
|
+
};
|
|
999
1006
|
});
|
|
1000
1007
|
}
|
|
1001
1008
|
};
|
|
@@ -1132,17 +1139,41 @@ function GeoMap({
|
|
|
1132
1139
|
const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
|
|
1133
1140
|
panelPosition
|
|
1134
1141
|
);
|
|
1142
|
+
const viewStateRef = React3.useRef(uncontrolledViewState);
|
|
1135
1143
|
React3.useEffect(() => {
|
|
1136
1144
|
if (!viewState && !defaultViewState) {
|
|
1137
|
-
setUncontrolledViewState({
|
|
1138
|
-
latitude
|
|
1139
|
-
|
|
1140
|
-
|
|
1145
|
+
setUncontrolledViewState((prev) => {
|
|
1146
|
+
if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
|
|
1147
|
+
return prev;
|
|
1148
|
+
}
|
|
1149
|
+
return {
|
|
1150
|
+
latitude: firstCoordinate.latitude,
|
|
1151
|
+
longitude: firstCoordinate.longitude,
|
|
1152
|
+
zoom: calculatedZoom
|
|
1153
|
+
};
|
|
1141
1154
|
});
|
|
1142
1155
|
}
|
|
1143
|
-
}, [
|
|
1156
|
+
}, [
|
|
1157
|
+
// Use primitive values instead of objects to avoid reference changes
|
|
1158
|
+
firstCoordinate.latitude,
|
|
1159
|
+
firstCoordinate.longitude,
|
|
1160
|
+
calculatedZoom,
|
|
1161
|
+
viewState,
|
|
1162
|
+
defaultViewState
|
|
1163
|
+
]);
|
|
1144
1164
|
const isControlledViewState = viewState !== void 0;
|
|
1145
1165
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1166
|
+
React3.useEffect(() => {
|
|
1167
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1168
|
+
}, [
|
|
1169
|
+
// Use primitive values to avoid reference changes
|
|
1170
|
+
resolvedViewState?.latitude,
|
|
1171
|
+
resolvedViewState?.longitude,
|
|
1172
|
+
resolvedViewState?.zoom,
|
|
1173
|
+
uncontrolledViewState.latitude,
|
|
1174
|
+
uncontrolledViewState.longitude,
|
|
1175
|
+
uncontrolledViewState.zoom
|
|
1176
|
+
]);
|
|
1146
1177
|
const applyViewState = React3.useCallback(
|
|
1147
1178
|
(nextState) => {
|
|
1148
1179
|
if (!isControlledViewState) {
|
|
@@ -1181,7 +1212,13 @@ function GeoMap({
|
|
|
1181
1212
|
setSelection({ type: "none" });
|
|
1182
1213
|
onSelectionChange?.({ type: "none" });
|
|
1183
1214
|
}
|
|
1184
|
-
}, [
|
|
1215
|
+
}, [
|
|
1216
|
+
// Use primitive values to avoid object reference issues
|
|
1217
|
+
selection.type,
|
|
1218
|
+
selection.markerId,
|
|
1219
|
+
selectedMarker?.id,
|
|
1220
|
+
onSelectionChange
|
|
1221
|
+
]);
|
|
1185
1222
|
const emitSelectionChange = React3.useCallback(
|
|
1186
1223
|
(nextSelection) => {
|
|
1187
1224
|
if (nextSelection.type === "none") {
|
|
@@ -1211,17 +1248,15 @@ function GeoMap({
|
|
|
1211
1248
|
markerId: marker.id,
|
|
1212
1249
|
clusterId: marker.clusterId
|
|
1213
1250
|
});
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
|
|
1251
|
+
const currentState = viewStateRef.current;
|
|
1252
|
+
const center = {
|
|
1253
|
+
latitude: currentState.latitude ?? 0,
|
|
1254
|
+
longitude: currentState.longitude ?? 0
|
|
1217
1255
|
};
|
|
1218
1256
|
const optimalPosition = getOptimalPanelPosition(
|
|
1219
1257
|
marker.latitude,
|
|
1220
1258
|
marker.longitude,
|
|
1221
|
-
|
|
1222
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1223
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1224
|
-
}
|
|
1259
|
+
center
|
|
1225
1260
|
);
|
|
1226
1261
|
setDynamicPanelPosition(optimalPosition);
|
|
1227
1262
|
applyViewState({
|
|
@@ -1231,7 +1266,7 @@ function GeoMap({
|
|
|
1231
1266
|
});
|
|
1232
1267
|
emitSelectionChange({ type: "marker", marker });
|
|
1233
1268
|
},
|
|
1234
|
-
[applyViewState, emitSelectionChange, markerFocusZoom
|
|
1269
|
+
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
1235
1270
|
);
|
|
1236
1271
|
const selectCluster = React3.useCallback(
|
|
1237
1272
|
(cluster) => {
|
|
@@ -1239,17 +1274,15 @@ function GeoMap({
|
|
|
1239
1274
|
type: "cluster",
|
|
1240
1275
|
clusterId: cluster.id
|
|
1241
1276
|
});
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1277
|
+
const currentState = viewStateRef.current;
|
|
1278
|
+
const center = {
|
|
1279
|
+
latitude: currentState.latitude ?? 0,
|
|
1280
|
+
longitude: currentState.longitude ?? 0
|
|
1245
1281
|
};
|
|
1246
1282
|
const optimalPosition = getOptimalPanelPosition(
|
|
1247
1283
|
cluster.latitude,
|
|
1248
1284
|
cluster.longitude,
|
|
1249
|
-
|
|
1250
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1251
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1252
|
-
}
|
|
1285
|
+
center
|
|
1253
1286
|
);
|
|
1254
1287
|
setDynamicPanelPosition(optimalPosition);
|
|
1255
1288
|
applyViewState({
|
|
@@ -1259,7 +1292,7 @@ function GeoMap({
|
|
|
1259
1292
|
});
|
|
1260
1293
|
emitSelectionChange({ type: "cluster", cluster });
|
|
1261
1294
|
},
|
|
1262
|
-
[applyViewState, clusterFocusZoom, emitSelectionChange
|
|
1295
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
1263
1296
|
);
|
|
1264
1297
|
const clearSelection = React3.useCallback(() => {
|
|
1265
1298
|
setSelection({ type: "none" });
|