mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-06-24 03:27: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) {
|
if (geometry) {
|
||||||
const points = geometry.getPoints();
|
const points = geometry.getPoints();
|
||||||
debugger;
|
debugger;
|
||||||
geometry.createGeometryFromData(points);
|
CesiumPlot.createGeometryFromData(points);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'cancelDraw':
|
||||||
|
if (geometry) {
|
||||||
|
geometry.remove();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
<button id="removeEvent">解绑事件</button>
|
<button id="removeEvent">解绑事件</button>
|
||||||
<button id="startGrowthAnimation">生长动画</button>
|
<button id="startGrowthAnimation">生长动画</button>
|
||||||
<button id="createGeometryFromData">根据数据生成图形</button>
|
<button id="createGeometryFromData">根据数据生成图形</button>
|
||||||
|
<button id="cancelDraw">取消绘制</button>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium';
|
window.CESIUM_BASE_URL = 'node_modules/cesium/Build/Cesium';
|
||||||
|
@ -50,8 +50,9 @@ export default class AttackArrow extends Base {
|
|||||||
const tempPoints = [...this.points, cartesian];
|
const tempPoints = [...this.points, cartesian];
|
||||||
this.setGeometryPoints(tempPoints);
|
this.setGeometryPoints(tempPoints);
|
||||||
if (tempPoints.length === 2) {
|
if (tempPoints.length === 2) {
|
||||||
this.addFirstLineOfTheArrow();
|
this.addTempLine();
|
||||||
} else {
|
} else {
|
||||||
|
this.removeTempLine();
|
||||||
const geometryPoints = this.createGraphic(tempPoints);
|
const geometryPoints = this.createGraphic(tempPoints);
|
||||||
this.setGeometryPoints(geometryPoints);
|
this.setGeometryPoints(geometryPoints);
|
||||||
this.drawPolygon();
|
this.drawPolygon();
|
||||||
|
@ -82,8 +82,9 @@ export default class DoubleArrow extends Base {
|
|||||||
const tempPoints = [...this.points, cartesian];
|
const tempPoints = [...this.points, cartesian];
|
||||||
this.setGeometryPoints(tempPoints);
|
this.setGeometryPoints(tempPoints);
|
||||||
if (tempPoints.length === 2) {
|
if (tempPoints.length === 2) {
|
||||||
this.addFirstLineOfTheArrow();
|
this.addTempLine();
|
||||||
} else if (tempPoints.length > 2) {
|
} else if (tempPoints.length > 2) {
|
||||||
|
this.removeTempLine();
|
||||||
const geometryPoints = this.createGraphic(tempPoints);
|
const geometryPoints = this.createGraphic(tempPoints);
|
||||||
this.setGeometryPoints(geometryPoints);
|
this.setGeometryPoints(geometryPoints);
|
||||||
this.drawPolygon();
|
this.drawPolygon();
|
||||||
|
13
src/base.ts
13
src/base.ts
@ -35,6 +35,7 @@ export default class Base {
|
|||||||
points: CesiumTypeOnly.Cartesian3[] = [];
|
points: CesiumTypeOnly.Cartesian3[] = [];
|
||||||
styleCache: GeometryStyle | undefined;
|
styleCache: GeometryStyle | undefined;
|
||||||
minPointsForShape: number = 0;
|
minPointsForShape: number = 0;
|
||||||
|
tempLineEntity: CesiumTypeOnly.Entity;
|
||||||
|
|
||||||
constructor(cesium: CesiumTypeOnly, viewer: CesiumTypeOnly.Viewer, style?: GeometryStyle) {
|
constructor(cesium: CesiumTypeOnly, viewer: CesiumTypeOnly.Viewer, style?: GeometryStyle) {
|
||||||
this.cesium = cesium;
|
this.cesium = cesium;
|
||||||
@ -266,15 +267,21 @@ export default class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addFirstLineOfTheArrow() {
|
addTempLine() {
|
||||||
if (!this.lineEntity) {
|
if (!this.tempLineEntity) {
|
||||||
// The line style between the first two points matches the outline style.
|
// The line style between the first two points matches the outline style.
|
||||||
const style = this.style as PolygonStyle;
|
const style = this.style as PolygonStyle;
|
||||||
const lineStyle = {
|
const lineStyle = {
|
||||||
material: style.outlineMaterial,
|
material: style.outlineMaterial,
|
||||||
lineWidth: style.outlineWidth,
|
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);
|
this.points.push(cartesian);
|
||||||
if (this.points.length === 1) {
|
if (this.points.length === 1) {
|
||||||
this.onMouseMove();
|
this.onMouseMove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,8 +35,9 @@ export default class Polygon extends Base {
|
|||||||
const tempPoints = [...this.points, cartesian];
|
const tempPoints = [...this.points, cartesian];
|
||||||
this.setGeometryPoints(tempPoints);
|
this.setGeometryPoints(tempPoints);
|
||||||
if (tempPoints.length === 2) {
|
if (tempPoints.length === 2) {
|
||||||
this.addFirstLineOfTheArrow();
|
this.addTempLine();
|
||||||
} else {
|
} else {
|
||||||
|
this.removeTempLine();
|
||||||
this.drawPolygon();
|
this.drawPolygon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,9 @@ export default class Sector extends Base {
|
|||||||
const tempPoints = [...this.points, cartesian];
|
const tempPoints = [...this.points, cartesian];
|
||||||
this.setGeometryPoints(tempPoints);
|
this.setGeometryPoints(tempPoints);
|
||||||
if (tempPoints.length === 2) {
|
if (tempPoints.length === 2) {
|
||||||
this.addFirstLineOfTheArrow();
|
this.addTempLine();
|
||||||
} else {
|
} else {
|
||||||
|
this.removeTempLine();
|
||||||
const geometryPoints = this.createGraphic(tempPoints);
|
const geometryPoints = this.createGraphic(tempPoints);
|
||||||
this.setGeometryPoints(geometryPoints);
|
this.setGeometryPoints(geometryPoints);
|
||||||
this.drawPolygon();
|
this.drawPolygon();
|
||||||
|
@ -36,8 +36,9 @@ export default class Triangle extends Base {
|
|||||||
const tempPoints = [...this.points, cartesian];
|
const tempPoints = [...this.points, cartesian];
|
||||||
this.setGeometryPoints(tempPoints);
|
this.setGeometryPoints(tempPoints);
|
||||||
if (tempPoints.length === 2) {
|
if (tempPoints.length === 2) {
|
||||||
this.addFirstLineOfTheArrow();
|
this.addTempLine();
|
||||||
} else {
|
} else {
|
||||||
|
this.removeTempLine();
|
||||||
this.drawPolygon();
|
this.drawPolygon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user