Cesium对viewer对象初始化(包括项目初始视角设置以及去除Cesium版权信息等)

Cesium对viewer对象初始化(包括项目初始视角设置以及去除Cesium版权信息等)

import * as Cesium from 'cesium';
import "cesium/Build/Cesium/Widgets/widgets.css";
import store from '@/store/index'

// Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1OWM2YjZkZS0yMTNhLTQzM2EtYWQ5Yy1jZTFkMzdkYjI5OTUiLCJpZCI6NDYwMjQsImlhdCI6MTYxNTc4MzA5NH0.GWgvqcvO8FZni-Crmkg472lIPm1xCUxmFqW7szqyBuE';

const skyBoxUrl = '/img/sky-box/';

export default function cesiumInstance(boxId: string) {
	// 对cesium项目初始视角进行设置
    // const rectangleCoord: any = store.state.rectangle;
    // const position = Cesium.Rectangle.fromCartesianArray([
    //     Cesium.Cartesian3.fromDegrees(rectangleCoord[0].Latitude, rectangleCoord[0].Longitude + 30, rectangleCoord[0].Altitude),
    //     Cesium.Cartesian3.fromDegrees(rectangleCoord[1].Latitude, rectangleCoord[1].Longitude + 30, rectangleCoord[1].Altitude),
    //     Cesium.Cartesian3.fromDegrees(rectangleCoord[2].Latitude, rectangleCoord[2].Longitude - 30, rectangleCoord[2].Altitude),
    //     Cesium.Cartesian3.fromDegrees(rectangleCoord[3].Latitude, rectangleCoord[3].Longitude - 30, rectangleCoord[3].Altitude),
    // ]);
    
    // 自定义位置
    // Cesium.Camera.DEFAULT_VIEW_RECTANGLE = position;
    
    // 默认中国上空
    // Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);
    
    const cesium: any = new Cesium.Viewer(boxId, {
        animation: false,
        homeButton: false,
        baseLayerPicker: false,
        fullscreenButton: false,
        geocoder: false,
        infoBox: false,
        timeline: false,
        sceneModePicker: false,
        navigationHelpButton: false,
        selectionIndicator: false,
        // 是否渲染地形
        // terrainProvider: Cesium.createWorldTerrain(),
        // 地球新皮肤设置,若不设置则为默认皮肤
        imageryProvider: new Cesium.SingleTileImageryProvider({
            url: '/img/layer/earth-1.jpg'
        }),
    
    	// 天空盒设置
        skyBox: new Cesium.SkyBox({
            sources: {
                positiveX: `${skyBoxUrl}left.png`,
                negativeX: `${skyBoxUrl}right.png`,
        
                positiveY: `${skyBoxUrl}down.png`,
                negativeY: `${skyBoxUrl}up.png`,
        
                positiveZ: `${skyBoxUrl}front.png`,
                negativeZ: `${skyBoxUrl}back.png`
            }
        })
    });

    viewer._cesiumWidget._creditContainer.style.display = 'none';//去除cesium版权信息
    viewer.clock.clockRange = Cesium.ClockRange.CLAMPED;// 时间轴执行完后停止(LOOP_STOP为循环,UNBOUNDED为继续读秒)
    
    // 设置场景的开始结束时间(当前时刻到明天的当前时刻)
	const nowDate = new Date();
    viewer.clock.startTime = Cesium.JulianDate.fromDate(nowDate);
    viewer.clock.stopTime = Cesium.JulianDate.fromDate(new Date(nowDate.setDate(nowDate.getDate() + 1)));
    viewer.clock.currentTime = Cesium.JulianDate.fromDate(nowDate);
    viewer.clock.multiplier = 1;
    viewer.clock.shouldAnimate = true;

    return cesium;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值