Skip to content

Commit

Permalink
feat: Auto-centering after changing the selectId
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyang committed Oct 15, 2024
1 parent deb82c8 commit 15e1417
Showing 1 changed file with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLatest, useMemoizedFn } from 'ahooks';
import { useLatest, useMemoizedFn, useDebounceEffect } from 'ahooks';
import { Spin } from 'antd/es';
import React, {
useCallback,
Expand Down Expand Up @@ -67,7 +67,7 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp
updateRectListByReducer,
selectedIDs,
setSelectedIDs,
selectedID
selectedID,
} = useContext(PointCloudContext);

const { value: toolStyle } = useToolStyleContext();
Expand Down Expand Up @@ -125,7 +125,7 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp

const handleUpdateDragResult = (rect: IPointCloud2DRectOperationViewRect) => {
const { boxID } = rect;

setNeedUpdateCenter(false);
if (!shouldExcludePointCloudBoxListUpdate) {
if (boxID) {
recoverSelectedIds(() => {
Expand Down Expand Up @@ -410,29 +410,35 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp
updateRectList();
}, [selectedIDs]);

useEffect(() => {
// Center the view by selectedID
if (!selectedID || !needUpdateCenter) {
setNeedUpdateCenter(true);
return;
}
const {rectList, size, zoom} = operation.current
// Use boxId for a normal connection, and use extId when disconnected.
const rect = rectList.find((el: any) => el.boxID === selectedID || el.extId === selectedID)
if (!rect) {
setNeedUpdateCenter(true);
return;
}
const centerPoint = {
x: rect.x + rect.width / 2,
y: rect.y + rect.height / 2
}
const currentPos = MathUtils.getCurrentPosFromRectCenter(size, centerPoint, zoom)
operation.current.setHoverRectID(rect.id)
operation.current.setCurrentPos(currentPos)
operation.current.renderBasicCanvas()
operation.current.render()
}, [selectedID]);
useDebounceEffect(
() => {
// Center the view by selectedID
if (!selectedID || !needUpdateCenter) {
setNeedUpdateCenter(true);
return;
}
const { rectList, size, zoom } = operation.current;
// Use boxId for a normal connection, and use extId when disconnected.
const rect = rectList.find((el: any) => el.boxID === selectedID || el.extId === selectedID);
if (!rect) {
setNeedUpdateCenter(true);
return;
}
const centerPoint = {
x: rect.x + rect.width / 2,
y: rect.y + rect.height / 2,
};
const currentPos = MathUtils.getCurrentPosFromRectCenter(size, centerPoint, zoom);
operation.current.setHoverRectID(rect.id);
operation.current.setCurrentPos(currentPos);
operation.current.renderBasicCanvas();
operation.current.render();
},
[selectedID],
{
wait: 200,
},
);

useEffect(() => {
const { hiddenText } = toolStyle || {};
Expand Down

0 comments on commit 15e1417

Please sign in to comment.