cesium实现3D历史轨迹播放

如题所述

第1个回答  2022-07-28
这个是我根据API及示例整理的历史轨迹播放的demo,其中重要的参数都做了注释,可以直接粘贴到cesium的模拟其中验证或做修改

//设定模拟时间的界限

var start = Cesium.JulianDate.fromDate(new Date(2021, 3, 2, 23,50,20));//朱利安时间=UTC=北京时间-8 2021-03-02 15:50:20

var stop = Cesium.JulianDate.fromDate(new Date(2021, 3, 2, 23,56,20));

//确保查看器在想要的时间

viewer.clock.startTime = start.clone();

viewer.clock.stopTime = stop.clone();

viewer.clock.currentTime = start.clone();

viewer.clock.clockRange = Cesium.ClockRange.CLAMPED; //达到终止时间后停止,LOOP_STOP:达到终止时间后重新循环,UNBOUNDED:达到终止时间后继续读秒

viewer.clock.multiplier = 10;//初始运行速度

//将时间轴设置为模拟边界

viewer.timeline.zoomTo(start, stop);

//生成一个一条线

function computeCirclularFlight() {

  var property = new Cesium.SampledPositionProperty();

  var dataSource = [{

  'id':1,

  'time':new Date(2021, 3, 2, 23,50,20),

  'lng':120.43413519859315,

  'lat':30.238649673375463,

  },{

  'id':2,

  'time':new Date(2021, 3, 2, 23,51,20),

  'lng':120.4343605041504,

  'lat':30.23831135356134,

  },{

  'id':3,

  'time':new Date(2021, 3, 2, 23,52,20),

  'lng':120.43460726737977,

  'lat':30.237908148974306,

  },{

  'id':4,

  'time':new Date(2021, 3, 2, 23,53,20),

  'lng':120.43478429317476,

  'lat':30.237602268529127,

  },{

  'id':5,

  'time':new Date(2021, 3, 2, 23,54,20),

  'lng':120.4349720478058,

  'lat':30.237282483409622,

  },{

  'id':6,

  'time':new Date(2021, 3, 2, 23,55,20),

  'lng':120.4351720478058,

  'lat':30.236882483409622,

  },{

  'id':7,

  'time':new Date(2021, 3, 2, 23,56,20),

  'lng':120.4353720478058,

  'lat':30.236482483409622,

  }

  ];

  for (var i = 0; i < 7; i ++) {

    var time = Cesium.JulianDate.fromDate(dataSource[i].time);//每个点对应的时间

    var position = Cesium.Cartesian3.fromDegrees(dataSource[i].lng,dataSource[i].lat,100);

    property.addSample(time, position);

  }

  return property;

}

//Compute the entity position property.

var position = computeCirclularFlight();

//Actually create the entity

var entity = viewer.entities.add({

  //Set the entity availability to the same interval as the simulation time.

  availability: new Cesium.TimeIntervalCollection([

    new Cesium.TimeInterval({

      start: start,

      stop: stop,

    }),

  ]),

  //Use our computed positions

  position: position,

  //Automatically compute orientation based on position movement.

  orientation: new Cesium.VelocityOrientationProperty(position),

  //Load the Cesium plane model to represent the entity

  model: {

    uri: "../SampleData/models/CesiumAir/Cesium_Air.glb",//模型地址

    minimumPixelSize: 64,

  },

  //Show the path as a pink line sampled in 1 second increments.

  path: {

    resolution: 1,

    material: new Cesium.PolylineGlowMaterialProperty({

      glowPower: 0.1,

      color: Cesium.Color.YELLOW,

    }),

    width: 10,

  },

});

//添加按钮从顶部查看路径

Sandcastle.addDefaultToolbarButton("View Top Down", function () {

  viewer.trackedEntity = undefined;

  viewer.zoomTo(

    viewer.entities,

    new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90))

  );

});

//添加按钮从侧面查看路径

Sandcastle.addToolbarButton("View Side", function () {

  viewer.trackedEntity = undefined;

  viewer.zoomTo(

    viewer.entities,

    new Cesium.HeadingPitchRange(

      Cesium.Math.toRadians(-90),

      Cesium.Math.toRadians(-15),

      7500

    )

  );

});

//添加按钮来跟踪实体的移动

Sandcastle.addToolbarButton("View Aircraft", function () {

  viewer.trackedEntity = entity;

});

//添加一个组合框来选择每个插值模式.

Sandcastle.addToolbarMenu(

  [

    {

      text: "Interpolation: Linear Approximation",

      onselect: function () {

        entity.position.setInterpolationOptions({

          interpolationDegree: 1,

          interpolationAlgorithm: Cesium.LinearApproximation,

        });

      },

    },

    {

      text: "Interpolation: Lagrange Polynomial Approximation",

      onselect: function () {

        entity.position.setInterpolationOptions({

          interpolationDegree: 5,

          interpolationAlgorithm:

            Cesium.LagrangePolynomialApproximation,

        });

      },

    },

    {

      text: "Interpolation: Hermite Polynomial Approximation",

      onselect: function () {

        entity.position.setInterpolationOptions({

          interpolationDegree: 2,

          interpolationAlgorithm: Cesium.HermitePolynomialApproximation,

        });

      },

    },

  ],

  "interpolationMenu"

);
相似回答