viewpoint.js
1.61 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
export default class viewpoint {
constructor(viewer) {
this.viewer = viewer;
this.sightline = new Cesium.Sightline(viewer.scene);
this.sightline.couldRemove = false;
this.sightline.build();
this.handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
this.handlerPoint.drawEvt.addEventListener(result => {
var point = result.object;
point.show = false;
var position = result.object.position;
//将获取的点的位置转化成经纬度
var cartographic = Cesium.Cartographic.fromCartesian(position);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;
if(viewer.scene.viewFlag) {
this.sightline.viewPosition = [longitude, latitude, height];
viewer.scene.viewFlag = false;
this.addPoint();
}else {
this.sightline.addTargetPoint({
position : [longitude, latitude, height],
name : "point" + new Date()
});
this.sightline.couldRemove = true;
}
});
}
chooseView() {
if(this.handlerPoint.active) return;
this.viewer.scene.viewFlag = true;
this.viewer.entities.removeAll();
this.sightline.removeAllTargetPoint();
this.handlerPoint.activate();
}
addPoint() {
this.viewer.scene.viewFlag = false;
this.handlerPoint.activate();
}
}