mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-06-23 19:17:29 +00:00
Delete the lines temporarily created during the drawing process
This commit is contained in:
parent
bcbbfcb014
commit
2f5e3a50a0
@ -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:
|
||||
|
@ -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';
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
13
src/base.ts
13
src/base.ts
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user