viewpoint.js
1.68 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
import objectManage from './maputils';
export default class viewpoint {
constructor() {
this.sightline = new Cesium.Sightline(objectManage.viewer.scene);
this.sightline.couldRemove = false;
this.sightline.build();
this.handlerPoint = new Cesium.DrawHandler(objectManage.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(objectManage.viewer.scene.viewFlag) {
this.sightline.viewPosition = [longitude, latitude, height];
objectManage.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;
objectManage.viewer.scene.viewFlag = true;
objectManage.viewer.entities.removeAll();
this.sightline.removeAllTargetPoint();
this.handlerPoint.activate();
}
addPoint() {
objectManage.viewer.scene.viewFlag = false;
this.handlerPoint.activate();
}
}