Commit be9b10a4 by jlc

update:动目标船案例的修改

parent 23e89783
src/assets/Ship.png

54.2 KB | W: | H:

src/assets/Ship.png

531 KB | W: | H:

src/assets/Ship.png
src/assets/Ship.png
src/assets/Ship.png
src/assets/Ship.png
  • 2-up
  • Swipe
  • Onion skin
export function addShip(viewer) { export function addShip(viewer) {
const czml = [ let start = Cesium.JulianDate.fromDate(new Date()); // 设置时间轴当前时间为开始时间
{ start = Cesium.JulianDate.addHours(start, 8, new Cesium.JulianDate()); // 开始时间加8小时改为北京时间
id: "document", let stop = Cesium.JulianDate.addSeconds(start, 400, new Cesium.JulianDate()); // 设置结束时间为开始时间加400秒
name: "Ship",
version: "1.0", viewer.clock.startTime = start.clone(); // 设置时钟开始时间
clock: { viewer.clock.currentTime = start.clone(); // 设置时钟当前时间
interval: "2019-08-28T04:00:00Z/2019-08-28T04:20:00Z", viewer.clock.stopTime = stop.clone(); // 设置时钟结束时间
currentTime: "2019-08-28T04:00:00.00Z", viewer.clock.multiplier = 1; // 设置时间倍数
multiplier: 1, viewer.timeline.zoomTo(start, stop); // 时间轴绑定到viewer上去
range: "LOOP_STOP", viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; // 循环执行,到达终止时间,重新从起点时间开始
step: "SYSTEM_CLOCK_MULTIPLIER"
// 生成路径
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].latitude, source[i].height);
// 添加位置,和时间对应
property.addSample(time, position);
} }
}, return property;
{
id: "path",
name: "path for Ship",
description: "<p>this is a ship</p>",
availability: "2019-08-28T04:00:00Z/2019-08-28T04:20:00Z",
path: {
material: {
polylineOutline: {
color: {
rgba: [255, 0, 255, 255],
},
outlineColor: {
rgba: [0, 255, 255, 255],
},
outlineWidth: 5
},
},
width: 8, // 折线宽度
leadTime: 5,
trailTime: 50000,
resolution: 5,
},
orientation: {
"velocityReference": "#position"
},
model: {
gltf: 'https://raw.githubusercontent.com/jinlinchao123/Cesium-assets/main/3Dmodel/ship.glb',
minimumPixelSize: 128,
},
position: {
epoch: "2019-08-28T04:00:00.00Z",
cartographicDegrees: [
0, 140, 30, 0,
1200, 143, 30, 0
]
} }
},
];
var dataSourcePromise = viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); let data = [
dataSourcePromise.then(function (dataSource) { { longitude: 121, latitude: 33, height: 0, time: 0 },
// 根据模型所在的实体去进行加载 { longitude: 123, latitude: 32, height: 0, time: 180 },
viewer.trackedEntity = dataSource.entities.getById('path'); { longitude: 122, latitude: 31, height: 0, time: 400 }
}).catch(function (error) { ]
console.error(error); let property = computeFlight(data);
let entity = viewer.entities.add({
availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start: start,
stop: stop
})]),
position: property,
orientation: new Cesium.VelocityOrientationProperty(property), // 根据速度计算方向角
model: {
uri: 'https://raw.githubusercontent.com/jinlinchao123/Cesium-assets/main/3Dmodel/ship.glb', //gltf文件的URL
scale: 0.05, // 放大倍数
silhouetteColor: Cesium.Color.fromCssColorString('rgba(0, 255, 0, 1)'), // 船模型边框颜色
silhouetteSize: 1, // 船模型边框宽度
minimumPixelSize: 128
},
path: { // 船路径
resolution: 1,
material: new Cesium.PolylineGlowMaterialProperty({
glowPower: 0.1, // 颜色透明度
color: Cesium.Color.fromCssColorString('rgba(0, 253, 239, 0.5)') // 路线颜色
}),
width: 2 // 路线的显示宽度
}
}); });
viewer.trackedEntity = entity; // 视角跟随模型
} }
\ No newline at end of file
...@@ -15,8 +15,19 @@ onMounted(() => { ...@@ -15,8 +15,19 @@ onMounted(() => {
window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE' window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE'
viewer = new window.Cesium.Viewer('cesiumContainer', { viewer = new window.Cesium.Viewer('cesiumContainer', {
infoBox: false, baseLayerPicker: false, // 影像切换
shouldAnimate: true animation: true, //是否显示动画控件
timeline: false, //是否显示时间线控件
infoBox: false, //是否显示点击要素之后显示的信息
geocoder: false, //是否显示地名查找控件
timeline: true, //是否启用时间线控件
fullscreenButton: false,
shouldAnimate: true,
navigationHelpButton: false, //是否显示帮助信息控件
terrainProvider: Cesium.createWorldTerrain({
requestWaterMask: true, // required for water effects
requestVertexNormals: true // required for terrain lighting
})
}); });
addShip(viewer) addShip(viewer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment