cesium 常用方法

1、查看视角

const getInfo = (viewer) => {
    let pos = viewer.camera.position;
    let direction = viewer.camera.direction;
    let up = viewer.camera.up;
    let pitch = viewer.camera.pitch;
    let roll = viewer.camera.roll;
    let heading = viewer.camera.heading;
    let obj =
    {
        "position": [pos.x, pos.y, pos.z],
        "direction": [direction.x, direction.y, direction.z],
        "up": [up.x, up.y, up.z],
        "pitch": pitch,
        "roll": roll,
        "heading": heading
      }
      return JSON.stringify(obj)
}
getInfo(vieweryanshi)

2、切换到某个视角

  vieweryanshi.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(130.78, 28.36, 19000000),
    });

3、赋值cesium开始时间并且暂停

T_Viewer.clock.multiplier = 1;
T_Viewer.clock.currentTime = Cesium.JulianDate.fromIso8601(new Date(event.data.time).toISOString());
T_Viewer.clock.shouldAnimate = false;

4、查看所有实体

vieweryanshi.dataSources.get(0).entities.values

5、查看所有连线

vieweryanshi.entities.values
vieweryanshi.entities.getById("rightArea")

6、删除所有实体

entities.removeAll(true);
vieweryanshi.entities.removeAll(true);

7、添加区域

 let leftPositionArray = ref([110.0, 30.0]);
 vieweryanshi.entities.add({
        id: 'leftArea',
        polygon: {
            show: true,
            hierarchy: new Cesium.CallbackProperty(function () {
                let arrPoint = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(leftPositionArray.value));
                return arrPoint;
            }, false),
            material: Cesium.Color.CYAN.withAlpha(0.5),
            fill: false,
            perPositionHeight: true,
            outline: true,
            outlineColor: Cesium.Color.CYAN.withAlpha(0.5), // 边界线颜色
            width: 5, // 边界线宽度
        },
    });

8、实时获取舰船实体经纬度

const setTabelDate = (arr) => {
    return arr.map((item) => {
        //QZJ6和 QZJ7信息不更新
        if (item.id !== "Ship/QZJ6" && item.id !== "Ship/QZJ7") {
            let entiy = entities.getById(item.id);
            let position = entiy.position.getValue(vieweryanshi.clock.currentTime);
            item.time = timeInfo.value;
            let { longitude, latitude } = getLLH(position);
            item.lon = longitude.toFixed(6);
            item.lat = latitude.toFixed(6);
        }
        return item;
    });
};

const getLLH = (position) => {
    let llh = {
        longitude: "",
        latitude: "",
        height: "",
    };
    let cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position); // 获取经度、纬度和高度
    llh.longitude = Cesium.Math.toDegrees(cartographic.longitude);
    llh.latitude = Cesium.Math.toDegrees(cartographic.latitude);
    llh.height = cartographic.height; // console.log('经度: ' + llh.longitude); // console.log('纬度: ' + llh.latitude); // console.log('高度: ' + llh.height);

    return llh;
};

9、判断演示时间是否在区间之内

/**
 *
 * @param {String} startTime 开始时间
 * @param {String} endTime 结束时间
 * @param {Boolean} flag 是否判断
 */

const isTimeRange = (startTime, endTime, flag = true) => {
    if (
        new Date(startTime).getTime() <=
        Cesium.JulianDate.toDate(
            vieweryanshi.clock.currentTime
        ).getTime() &&
        new Date(endTime).getTime() >=
        Cesium.JulianDate.toDate(
            vieweryanshi.clock.currentTime
        ).getTime() &&
        flag
    ) {
        return true;
    } else {
        return false;
    }
};

10、控制实体label显示隐藏

const setLabelStatus = (id, option) => {
    // 获取刚刚加载的实体
    let entity = entities.getById(id);
    if (entity && entity.label) {
        entity.label.show = option.show; // 设置标签的显示状态
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值