Skip to content

Commit

Permalink
feat(point-tool): Support the multiMove mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin-L committed Nov 29, 2022
1 parent 89559a0 commit 06a86ea
Showing 1 changed file with 93 additions and 18 deletions.
111 changes: 93 additions & 18 deletions packages/lb-annotation/src/core/toolOperation/pointOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { edgeAdsorptionScope, ELineTypes, EToolName } from '@/constant/tool';
import { edgeAdsorptionScope, ELineTypes, EOperationMode, EToolName } from '@/constant/tool';
import RectUtils from '@/utils/tool/RectUtils';
import PolygonUtils from '@/utils/tool/PolygonUtils';
import MarkerUtils from '@/utils/tool/MarkerUtils';
Expand Down Expand Up @@ -36,6 +36,11 @@ class PointOperation extends BasicToolOperation {

public markerIndex: number; // 用于列表标签定位

public dragInfo?: {
dragStartCoord: ICoordinate;
originPointList: IPointUnit[];
};

private _textAttributInstance?: TextAttributeClass;

constructor(props: IPointOperationProps) {
Expand Down Expand Up @@ -113,6 +118,7 @@ class PointOperation extends BasicToolOperation {
this.clearActiveStatus();
this.setPointList(pointList);
this.setNextMarker(pointList);
this.recoverOperationMode();
this.render();
}

Expand Down Expand Up @@ -263,20 +269,58 @@ class PointOperation extends BasicToolOperation {
this.clearActiveStatus();
}

/**
* Offset is under zooming.
* @param offset
*/
public onDragMoveAll(offset: ICoordinate) {
if (!this.dragInfo?.originPointList?.length) {
return;
}
this.setPointList(
this.dragInfo.originPointList.map((point: IPointUnit) => {
const newRect = {
...point,
x: point.x + offset.x / this.zoom,
y: point.y + offset.y / this.zoom,
};

return newRect;
}),
);

this.render();
}

public onMouseDown(e: MouseEvent) {
if (super.onMouseDown(e) || this.forbidMouseOperation) {
return;
}

// 当前目标下没有 hoverId 才进行标注
if (e.button === 0 && !this.hoverID) {
this.recoverOperationMode();
this.createPoint(e);
this.render();

return;
}
// 有选中的点时 才能进行拖拽
if (this.hoverID === this.selectedID && e.button === 0) {

/**
* Drag precondition
*
* 1. hoverID === Selected ID
* 2. It's multiMoveMode & Hover a point.
*/
if ((this.hoverID === this.selectedID || (this.isMultiMoveMode && this.hoverID)) && e.button === 0) {
this.dragStatus = EDragStatus.Start;
if (this.isMultiMoveMode) {
this.dragInfo = {
dragStartCoord: this.getCoordinateUnderZoom(e),
originPointList: this.pointList,
};
}
return;
}

this.render();
Expand All @@ -287,6 +331,7 @@ class PointOperation extends BasicToolOperation {
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
return;
}

this.hoverID = this.getHoverId();
// 拖拽中
if (this.dragStatus === EDragStatus.Start || this.dragStatus === EDragStatus.Move) {
Expand All @@ -310,6 +355,7 @@ class PointOperation extends BasicToolOperation {
// 拖拽停止
if (this.dragStatus === EDragStatus.Move) {
this.history.pushHistory(this.pointList);
this.dragInfo = undefined;
}
this.dragStatus = EDragStatus.Wait;
this.render();
Expand All @@ -319,6 +365,15 @@ class PointOperation extends BasicToolOperation {
if (!this.imgInfo) return;
this.dragStatus = EDragStatus.Move;
const coordinateZoom = this.getCoordinateUnderZoom(e);

if (this.isMultiMoveMode && this.dragInfo) {
const offset = {
x: coordinateZoom.x - this.dragInfo.dragStartCoord.x,
y: coordinateZoom.y - this.dragInfo.dragStartCoord.y,
};
this.onDragMoveAll(offset);
return;
}
// 缩放后的坐标
const zoomCoordinate = AxisUtils.changeDrawOutsideTarget(
coordinateZoom,
Expand Down Expand Up @@ -542,6 +597,8 @@ class PointOperation extends BasicToolOperation {
}

public rightMouseUp() {
this.recoverOperationMode();

// 删除操作
if (this.selectedID === this.hoverID) {
const pointList = this.pointList.filter((point) => point.id !== this.selectedID);
Expand Down Expand Up @@ -744,9 +801,9 @@ class PointOperation extends BasicToolOperation {
/**
* 绘制标点
*/
public renderPoint(point: IPointUnit) {
public renderPoint(point: IPointUnit, isSelected = false) {
const { textAttribute = '', attribute } = point;
const selected = point.id === this.selectedID;
const selected = isSelected || point.id === this.selectedID;
const toolColor = this.getColor(attribute);

const transformPoint = AxisUtils.changePointByZoom(point, this.zoom, this.currentPos);
Expand Down Expand Up @@ -807,22 +864,40 @@ class PointOperation extends BasicToolOperation {
}
}

public renderMultiSelectedPoint() {
if (!this.isMultiMoveMode) {
return;
}

this.pointList.forEach((point) => {
this.renderPoint(point, true);
});
}

public renderPointList() {
const [showingPointList, selectedPoint] = CommonToolUtils.getRenderResultList<IPointUnit>(
this.pointList,
CommonToolUtils.getSourceID(this.basicResult),
this.attributeLockList,
this.selectedID,
);
switch (this.operationMode) {
case EOperationMode.MultiMove:
this.renderMultiSelectedPoint();
break;

if (!this.isHidden) {
showingPointList.forEach((point) => {
this.renderPoint(point);
});
}
default: {
const [showingPointList, selectedPoint] = CommonToolUtils.getRenderResultList<IPointUnit>(
this.pointList,
CommonToolUtils.getSourceID(this.basicResult),
this.attributeLockList,
this.selectedID,
);

if (selectedPoint) {
this.renderPoint(selectedPoint);
if (!this.isHidden) {
showingPointList.forEach((point) => {
this.renderPoint(point);
});
}

if (selectedPoint) {
this.renderPoint(selectedPoint);
}
}
}
}

Expand Down

0 comments on commit 06a86ea

Please sign in to comment.