cesium實現(xiàn)3D歷史軌跡播放

這個是我根據(jù)API及示例整理的歷史軌跡播放的demo,其中重要的參數(shù)都做了注釋,可以直接粘貼到cesium的模擬其中驗證或做修改

//設(shè)定模擬時間的界限

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:達到終止時間后重新循環(huán),UNBOUNDED:達到終止時間后繼續(xù)讀秒

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

//將時間軸設(shè)置為模擬邊界

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))

? );

});

//添加按鈕從側(cè)面查看路徑

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"

);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容