前言
在很多项目中需要标绘一些特殊的符号,如进攻路线,集结地,可以使用军事标绘中的符号来实现。
关键代码
import PlotBase from "../../PlotBase"
import PlotTypes from "../../PlotTypes"
//面标绘 面标绘类是所有面状军事标绘的父类
export default class Polygon extends PlotBase {
constructor(viewer, baseInfo, properties) {
super(viewer, baseInfo, properties);
this.baseInfo.plotName = PlotTypes.POLYGON;
this.generateEntity();
this.minPointCount = 3;
}
//构造Entity
generateEntity() {
this.polygonEntity = this.viewer.entities.add({
plotType: "MilitaryPlot",
plotCode: this.baseInfo.plotCode,
polygon: {
hierarchy: new Cesium.CallbackProperty(e => {
return new Cesium.PolygonHierarchy(this.positions || []);
}, false),
perPositionHeight: true,
extrudedHeight: new Cesium.CallbackProperty(e => {
return this.getHeight() + 0.3
}, false),
material: Cesium.Color.RED //.withAlpha(0.5)
},
});
}
generate() {
var count = this.getPointCount();
if (count < 2) {
return;
}
this.generatePositions(this.points);
}
//移除标绘对象
remove() {
this.viewer.entities.remove(this.polygonEntity);
}
}
详情参见 Cesium实战项目