heightControl.js
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import objectManage from './maputils';
export default class heightControl {
constructor(opt) {
this.handlerPolygon = new Cesium.DrawHandler(objectManage.viewer, Cesium.DrawMode.Polygon);
this.building = objectManage.viewer.scene.layers.find("build1");
this.building1 = objectManage.viewer.scene.layers.find("build2");
this.arr = [];
var i = 0;
while(i < 2000) this.arr.push(i++);
this.handlerPolygon.drawEvt.addEventListener(result => {
var array = [].concat(result.object.positions), positions = [];
var polygon = result.object;
if(!polygon) return;
polygon.show = false;
this.handlerPolygon.polyline.show = false;
for(var i = 0, len = array.length; i < len; i++){
var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
if(positions.indexOf(longitude)===-1&&positions.indexOf(latitude)===-1){
positions.push(longitude);
positions.push(latitude);
}
}
this.addPolygon(Object.assign(opt, {p: positions}));
this.splice(opt.h);
});
}
addPolygon(opt) {
this.polygon = objectManage.viewer.entities.add({
id: 'polygonA',
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray(opt.p),
height: opt.h,
material: new Cesium.Color(1, 1, 0.20, 0.5),
outline: true,
outlineColor: Cesium.Color.RED
}
}).polygon;
}
splice(h) {
this.building.clipLineColor = Cesium.Color.WHITE.withAlpha(0.0);
this.building1.setObjsColor(this.arr, Cesium.Color.DARKORANGE.withAlpha(0.5));
this.building.setCustomClipBox({
dimensions: new Cesium.Cartesian3(5000, 5000, h * 2),
position: Cesium.Cartesian3.fromDegrees(116.44391163897568, 39.922128887755996, h / h - 1),
clipMode: "clip_behind_any_plane"
});
this.building1.setCustomClipBox({
dimensions: new Cesium.Cartesian3(5000, 5000, h * 2),
position: Cesium.Cartesian3.fromDegrees(116.44391163897568, 39.922128887755996, h / h - 1),
clipMode: "clip_behind_all_plane"
});
}
remove() {
objectManage.viewer.entities.removeAll();
this.splice(1000);
}
}