cesium定位到实体车辆trackedEntity,设置垂直于正后方

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cesium.com/downloads/cesiumjs/releases/1.102/Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet"
        href="https://cesium.com/downloads/cesiumjs/releases/1.102/Build/Cesium/Widgets/widgets.css" />
    <script src="https://cdn.bootcdn.net/ajax/libs/Turf.js/6.5.0/turf.min.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/@dvgis/cesium-map/dist/cesium.map.min.js"></script> -->
    <title>Document</title>
    <style>
        body,
        html {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        .lonLat {
            position: fixed;
            width: 100%;
            top: 0;
            /* left: 50%; */
            color: aliceblue;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="cesiumContainer"></div>
    <div class="lonLat">

    </div>
    <script>
       
        let divEle = document.createElement('div')
        var viewer = new Cesium.Viewer("cesiumContainer", {
            timeline: false, // 底部时间线
            homeButton: false, // 视角返回初始位置
            fullscreenButton: false, // 全屏
            animation: false, // 左下角仪表盘(动画器件)
            sceneModePicker: false, // 选择视角的模式(球体、平铺、斜视平铺)
            navigationHelpButton: false, //导航帮助按钮
            // targetFrameRate: 30,
            geocoder: false, // 位置查找工具
            baseLayerPicker: false,
            // requestRenderMode: true,
            creditContainer: divEle,
            // shadows:true,
            // imageryProvider: new Cesium.SingleTileImageryProvider({
            //     url: "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",
            //     // url: "./earth.webp",
            //     // rectangle: Cesium.Rectangle.fromDegrees(-180, -90, 180, 90),
            // }),
        });

        viewer.scene.globe.eableLighting = true;

        viewer.scene.debugShowFramesPerSecond = true;

        viewer.clockViewModel.currentTime = Cesium.JulianDate.fromDate(new Date(2022, 2, 25, 12));

        addModel('./xiaobache.glb', 0)
        function addModel(url, height) {
            viewer.entities.removeAll();
            let p = 120.059
            let position = Cesium.Cartesian3.fromDegrees(
                p,
                36.328,
                height
            );
            setTimeout(() => {
                setInterval(() => {
                    p = p + 0.00001
                    position = Cesium.Cartesian3.fromDegrees(
                        // 120.059,
                        p,
                        36.328,
                        height
                    )
                }, 10);
            }, 3000);
            const heading = Cesium.Math.toRadians(0);
            const pitch = 0;
            const roll = 0;
            const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
            const orientation = Cesium.Transforms.headingPitchRollQuaternion(
                position,
                hpr
            );
            const entity = viewer.entities.add({
                name: url,
                position: new Cesium.CallbackProperty(() => {
                    return position
                }),
                orientation: orientation,
                model: {
                    uri: url,
                    scale: 10,
                    minimumPixelSize: 128,
                    maximumScale: 20000,
                    
                },
            });
            var heading1 = heading + Cesium.Math.toRadians(90.0);
            var pitch1 = Cesium.Math.toRadians(-50.0);

            viewer.flyTo(
                entity,
                {
                    duration: 1, maximumHeight: 10, offset: new Cesium.HeadingPitchRange(heading1, pitch1, 250)
                },
            );
            setTimeout(() => {
                viewer.trackedEntity = entity;
            }, 1 * 1000)
            // var center = Cesium.Cartesian3.fromDegrees(120.059, 36.328);
            // var heading1 = heading + Cesium.Math.toRadians(90.0);
            // var range1 = 100.0;
            // viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading1, pitch1, 250));

        }
    </script>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值