viewpoint.js 1.72 KB

import objectManage from './maputils';
export default class viewpoint {
    constructor() {
        console.log(Cesium.Sightline);
        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();
    }
}