edit AttackArrow

This commit is contained in:
ethan 2023-08-17 19:35:20 +08:00
parent b7191a8054
commit 1730b93706
2 changed files with 22 additions and 9 deletions

View File

@ -135,4 +135,14 @@ export default class AttackArrow extends Draw {
} }
return leftBodyPnts.concat(rightBodyPnts); return leftBodyPnts.concat(rightBodyPnts);
} }
/**
* In edit mode, drag key points to update corresponding key point data.
*/
updateDraggingPoint(cartesian: Cartesian3, index: number) {
this.points[index] = cartesian;
const geometryPoints = this.createPolygon(this.points);
this.setGeometryPoints(geometryPoints);
this.addToMap();
}
} }

View File

@ -8,7 +8,7 @@ export default class Draw {
polygonEntity: CesiumTypeOnly.Entity; polygonEntity: CesiumTypeOnly.Entity;
geometryPoints: CesiumTypeOnly.Cartesian3[] = []; geometryPoints: CesiumTypeOnly.Cartesian3[] = [];
state: State = 'drawing'; state: State = 'drawing';
controlPoints: CesiumTypeOnly.EntityCollection; controlPoints: CesiumTypeOnly.EntityCollection = [];
controlPointsEventHandler: CesiumTypeOnly.ScreenSpaceEventHandler; controlPointsEventHandler: CesiumTypeOnly.ScreenSpaceEventHandler;
lineEntity: CesiumTypeOnly.Entity; lineEntity: CesiumTypeOnly.Entity;
@ -55,8 +55,8 @@ export default class Draw {
} }
this.addPoint(cartesian); this.addPoint(cartesian);
} else if (this.state === 'edit') { } else if (this.state === 'edit') {
//In edit mode, exiting the edit state and deleting control points when clicking in the blank area. //In edit mode, exit the editing state and delete control points when clicking outside the currently edited shape.
if (!hitEntities) { if (!hitEntities || this.polygonEntity.id !== pickedObject.id.id) {
this.setState('static'); this.setState('static');
this.removeControlPoints(); this.removeControlPoints();
} }
@ -217,6 +217,7 @@ export default class Draw {
const cartesian = this.viewer.camera.pickEllipsoid(moveEvent.endPosition, this.viewer.scene.globe.ellipsoid); const cartesian = this.viewer.camera.pickEllipsoid(moveEvent.endPosition, this.viewer.scene.globe.ellipsoid);
if (cartesian) { if (cartesian) {
draggedIcon.position.setValue(cartesian); draggedIcon.position.setValue(cartesian);
console.error(123);
this.updateDraggingPoint(cartesian, draggedIcon.index); this.updateDraggingPoint(cartesian, draggedIcon.index);
} }
} }
@ -231,12 +232,14 @@ export default class Draw {
} }
removeControlPoints() { removeControlPoints() {
this.controlPoints.forEach((entity: CesiumTypeOnly.Entity) => { if (this.controlPoints.length > 0) {
this.viewer.entities.remove(entity); this.controlPoints.forEach((entity: CesiumTypeOnly.Entity) => {
}); this.viewer.entities.remove(entity);
this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.LEFT_DOWN); });
this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.MOUSE_MOVE); this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.LEFT_DOWN);
this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.LEFT_UP); this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.controlPointsEventHandler.removeInputAction(this.cesium.ScreenSpaceEventType.LEFT_UP);
}
} }
addPoint(cartesian: CesiumTypeOnly.Cartesian3) { addPoint(cartesian: CesiumTypeOnly.Cartesian3) {