cesium实现轨迹回放镜头跟踪

cesium实现轨迹回放镜头跟踪

适用于贴地运动的情况

实现轨迹回放物体运动

通过构造property让entity运动

构造模型entity

                this.model = this.billboardCollection.entities.add(
                    {
                        position: this.modelProperty,
                        // 根据所提供的速度计算模型的朝向
                        orientation: new Cesium.VelocityOrientationProperty(this.modelProperty),
                        // 模型数据
                        model: {
                            uri: this.markerPath,
                            minimumPixelSize: 50,
                            scale: 0.5,
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
                        },
                        polyline: {
                            positions: this.cartesian3ModelPositions,
                            material: Cesium.Color.fromCssColorString(this.initRouteColor),
                            clampToGround: true,
                            width: this.routeWidth
                        },
                        viewFrom: this.viewFrom
                    });


### 构造entity的property
```javascript
 // 构造entity的property
    /** 开始运动*/
    computeFlight() {
        let times = 0;
        let cartographicModelPoints = []
        var stopTime
        var p
        // 转换坐标的格式为Cartographic
        for (let i = 0; i < this.routecoords.length; i++) {
            cartographicModelPoints[i] = new Cesium.Cartographic.fromDegrees(this.routecoords[i][0], this.routecoords[i][1])
        }

        let computeModelHeightPromise = Cesium.sampleTerrainMostDetailed(this.terrain, cartographicModelPoints);
        Cesium.when.all([computeModelHeightPromise], () => {

            this.getSpaceDistance(cartographicModelPoints)
            this.timeArray.push(0)
            for (let i = 0; i < this.distanceArray.length; i++) {
                p = (this.distanceArray[i] * 0.001) / 111
                let time = (this.timeInterval / this.sampleInterval) * (p)
                this.timeArray.push(time)
            }

            for (let i = 0; i < cartographicModelPoints.length; i++) {
                let Cartesian3ModelPoints = Cesium.Cartesian3.fromRadians(cartographicModelPoints[i].longitude,
                    cartographicModelPoints[i].latitude, cartographicModelPoints[i].height)
                times = times + this.timeArray[i]
                let time = Cesium.JulianDate.addSeconds(this.start, times, new Cesium.JulianDate);
                this.timeList.push(time)
                this.modelProperty.addSample(time, Cartesian3ModelPoints);
                this.cartesian3ModelPositions.push(Cartesian3ModelPoints)
            }
            
            stopTime = this.timeList[this.timeList.length - 1]
            this.viewer.timeline.zoomTo(this.start, stopTime)
            this.viewer.clock.stopTime = stopTime

            this.viewFrom = new Cesium.Cartesian3(this.cartesian3ModelPositions[0].x,
                this.cartesian3ModelPositions[0].y,
                Math.abs(60))
            this.addModel()
        })

    }

实现镜头跟踪

设置this.viewer.trackedEntity = this.model

该方式在运动过程中鼠标可以改变镜头的heading、pitch、roll

自定义视角跟踪

通过构造相机的property,构造方式跟模型property一样,思路构造一条相机的运动路线,与模型保持相对运动,但是在运动过程中鼠标无法改变相机的参数。

tracking() {
        let that = this
        let lookHeight = this.cameraHeight
        this.cameraListener = function () {
            var cameraCartesian3 = that.cameraProperty.getValue(that.viewer.clock.currentTime)
            var modelCartesian3 = that.model.position.getValue(that.viewer.clock.currentTime);
            if (cameraCartesian3 !== undefined && that.viewer.clock.shouldAnimate && modelCartesian3 !== undefined) {
                var cameraCartographic = Cesium.Cartographic.fromCartesian(cameraCartesian3)
                var newCameraCartesian3 = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cameraCartographic.longitude), Cesium.Math.toDegrees(cameraCartographic.latitude), cameraCartographic.height + lookHeight)

                let heading = that.getHeading(newCameraCartesian3, modelCartesian3)
                let pitch = that.getPitch(newCameraCartesian3, modelCartesian3)
                that.viewer.camera.setView({
                    destination: newCameraCartesian3,
                    orientation: {
                        heading: heading,
                        pitch: pitch,
                        roll: 0.0,
                    }
                })

            }
        }
        that.viewer.scene.postRender.addEventListener(this.cameraListener);
    }

效果展示

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值