viewpoint.js 1.61 KB
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();
    }
}