Delete the lines temporarily created during the drawing process

This commit is contained in:
ethan 2024-05-14 09:32:07 +08:00
parent bcbbfcb014
commit 2f5e3a50a0
8 changed files with 28 additions and 10 deletions

View File

@ -174,7 +174,12 @@ buttonGroup.onclick = (evt) => {
if (geometry) {
const points = geometry.getPoints();
debugger;
geometry.createGeometryFromData(points);
CesiumPlot.createGeometryFromData(points);
}
break;
case 'cancelDraw':
if (geometry) {
geometry.remove();
}
break;
default:

View File

@ -71,6 +71,7 @@
<button id="removeEvent">解绑事件</button>
<button id="startGrowthAnimation">生长动画</button>
<button id="createGeometryFromData">根据数据生成图形</button>
<button id="cancelDraw">取消绘制</button>
</div>
<script>
window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium';

View File

@ -50,8 +50,9 @@ export default class AttackArrow extends Base {
const tempPoints = [...this.points, cartesian];
this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) {
this.addFirstLineOfTheArrow();
this.addTempLine();
} else {
this.removeTempLine();
const geometryPoints = this.createGraphic(tempPoints);
this.setGeometryPoints(geometryPoints);
this.drawPolygon();

View File

@ -82,8 +82,9 @@ export default class DoubleArrow extends Base {
const tempPoints = [...this.points, cartesian];
this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) {
this.addFirstLineOfTheArrow();
this.addTempLine();
} else if (tempPoints.length > 2) {
this.removeTempLine();
const geometryPoints = this.createGraphic(tempPoints);
this.setGeometryPoints(geometryPoints);
this.drawPolygon();

View File

@ -35,6 +35,7 @@ export default class Base {
points: CesiumTypeOnly.Cartesian3[] = [];
styleCache: GeometryStyle | undefined;
minPointsForShape: number = 0;
tempLineEntity: CesiumTypeOnly.Entity;
constructor(cesium: CesiumTypeOnly, viewer: CesiumTypeOnly.Viewer, style?: GeometryStyle) {
this.cesium = cesium;
@ -266,15 +267,21 @@ export default class Base {
}
}
addFirstLineOfTheArrow() {
if (!this.lineEntity) {
addTempLine() {
if (!this.tempLineEntity) {
// The line style between the first two points matches the outline style.
const style = this.style as PolygonStyle;
const lineStyle = {
material: style.outlineMaterial,
lineWidth: style.outlineWidth,
};
this.lineEntity = this.addLineEntity(lineStyle);
this.tempLineEntity = this.addLineEntity(lineStyle);
}
}
removeTempLine() {
if (this.tempLineEntity) {
this.viewer.entities.remove(this.tempLineEntity);
}
}

View File

@ -25,7 +25,7 @@ export default class Polygon extends Base {
this.points.push(cartesian);
if (this.points.length === 1) {
this.onMouseMove();
}
}
}
/**
@ -35,8 +35,9 @@ export default class Polygon extends Base {
const tempPoints = [...this.points, cartesian];
this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) {
this.addFirstLineOfTheArrow();
this.addTempLine();
} else {
this.removeTempLine();
this.drawPolygon();
}
}

View File

@ -36,8 +36,9 @@ export default class Sector extends Base {
const tempPoints = [...this.points, cartesian];
this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) {
this.addFirstLineOfTheArrow();
this.addTempLine();
} else {
this.removeTempLine();
const geometryPoints = this.createGraphic(tempPoints);
this.setGeometryPoints(geometryPoints);
this.drawPolygon();

View File

@ -36,8 +36,9 @@ export default class Triangle extends Base {
const tempPoints = [...this.points, cartesian];
this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) {
this.addFirstLineOfTheArrow();
this.addTempLine();
} else {
this.removeTempLine();
this.drawPolygon();
}
}