Skip to content

Commit

Permalink
Merge pull request #587 from Suntgr/feat/autocenter
Browse files Browse the repository at this point in the history
Feat/autocenter
  • Loading branch information
lihqi authored Oct 16, 2024
2 parents b0a6fbb + 15e1417 commit f192502
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ class PointCloud2DRectOperation extends RectOperation {
}

public rightMouseUp(e: MouseEvent) {
const hoverRect: (IRect & { boxID?: string, extId?: string}) | undefined = super.rightMouseUp(e);
// Use boxId for a normal connection, and use extId when disconnected.
const targetId = hoverRect?.boxID || hoverRect?.extId
const hoverRect: (IRect & { boxID?: string; extId?: string }) | undefined = super.rightMouseUp(e);
// Use boxId for a normal connection, and use extId when disconnected.
const targetId = hoverRect?.boxID || hoverRect?.extId;
this.emit('onRightClick', { event: e, targetId, id: hoverRect?.id });
return hoverRect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ class RectOperation extends BasicToolOperation {
}

public setHoverRectID(id: string) {
this.hoverRectID = id
this.hoverRectID = id;
}
}

Expand Down
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 f192502

Please sign in to comment.