Cesium.Ion.defaultAccessToken='你的token';
var view = new Cesium.Viewer('cesiumContainer',{
baseLayerPicker:false,
timeline:true,
homeButton:false,
fullscreenButton:false,
infoBox:false,
sceneModePicker:false,
navigationInstructionsInitiallyVisible:false,
navigationHelpButton:false,
shouldAnimate : true
});
view.scene.globe.enableLighting = true;
let data = [];
data[0] = [{longitude:116.405419, dimension:39.918034, height:0, time:0},{longitude:116.2821, dimension:39.918145, height:0, time:40},{longitude:115.497402, dimension:39.344641, height:70000, time:100},{longitude:107.942392, dimension:29.559967, height:70000, time:280}, {longitude:106.549265, dimension:29.559967, height:0, time:360}];
data[1] = [{longitude:116.405419, dimension:39.918034, height:0, time:0},{longitude:117.034586, dimension:39.881202, height:0, time:40},{longitude:116.340088, dimension:38.842224, height:70000, time:100},{longitude:113.489176, dimension:23.464017, height:70000, time:280}, {longitude:113.262084, dimension:23.13901, height:0, time:360}];
data[2] = [{longitude:118.838979, dimension:32.073514, height:0, time:0},{longitude:118.438838, dimension:32.03777, height:0, time:40},{longitude:117.802406, dimension:31.91231, height:70000, time:100},{longitude:104.043645, dimension:35.993845, height:70000, time:280}, {longitude:101.807224, dimension:36.660972, height:0, time:360}];
// 起始時間
let start = Cesium.JulianDate.fromDate(new Date(2017,7,11));
// 結束時間
let stop = Cesium.JulianDate.addSeconds(start, 360, new Cesium.JulianDate());
// 設置始時鐘始時間
view.clock.startTime = start.clone();
// 設置時鐘當前時間
view.clock.currentTime = start.clone();
// 設置始終停止時間
view.clock.stopTime = stop.clone();
// 時間速率,數字越大時間過的越快
view.clock.multiplier = 10;
// 時間軸
view.timeline.zoomTo(start,stop);
// 循環執行,即爲2,到達終止時間,重新從起點時間開始
view.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
// view.camera.flyTo({
// destination:Cesium.Cartesian3.fromDegrees(116.405419,32.073514,20000)
// })
for(let j=0; j<data.length; j++){
let property = computeFlight(data[j]);
//console.log(property)
// 添加模型
let planeModel = view.entities.add({
// 和時間軸關聯
availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start : start,
stop : stop
})]),
position: property,
// 根據所提供的速度計算模型的朝向
orientation: new Cesium.VelocityOrientationProperty(property),
// 模型數據
model: {
uri: './Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
minimumPixelSize:128
}
});
}
/**
* 計算飛行
* @param source 數據座標
* @returns {SampledPositionProperty|*}
*/
function computeFlight(source) {
// 取樣位置 相當於一個集合
let property = new Cesium.SampledPositionProperty();
for(let i=0; i<source.length; i++){
let time = Cesium.JulianDate.addSeconds(start, source[i].time, new Cesium.JulianDate);
let position = Cesium.Cartesian3.fromDegrees(source[i].longitude, source[i].dimension, source[i].height);
// 添加位置,和時間對應
property.addSample(time, position);
}
return property;
}
cesium按路徑飛
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.