// 单个czml加载小车
var scene = viewer.scene;
var entity;
var positionProperty;
var clock = new Cesium.Clock({
startTime: Cesium.JulianDate.fromIso8601("2012-08-04T16:00:00Z"),
currentTime: Cesium.JulianDate.fromIso8601("2012-08-04T16:00:00Z"),
stopTime: Cesium.JulianDate.fromIso8601("2012-08-04T16:03:00Z"),
clockRange: Cesium.ClockRange.LOOP_STOP,
clockStep: Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER
});
var tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: 'http://192.168.1.1/3dmodel/3dtile/tileset.json'
})
);
const czmlPath = "http://192.168.1.1/carModel/path/czmlPath.czml"
var dataSourcePromise = Cesium.CzmlDataSource.load(czmlPath);
var that = this;
viewer.dataSources.add(dataSourcePromise, that).then(function (dataSource) {
entity = dataSource.entities.getById('Vehicle');
viewer.trackedEntity = entity;
positionProperty = entity.position;
if (positionProperty != undefined) {
entity.orientation = new Cesium.VelocityOrientationProperty(positionProperty);
}
});
if (scene.clampToHeightSupported) {
tileset.initialTilesLoaded.addEventListener(start2);
} else {
console.log('This browser does not support clampToHeight.');
}
function start2() {
var objectsToExclude = [entity];
scene.postRender.addEventListener(function () {
var position = positionProperty.getValue(viewer.clock.currentTime);
if (position != undefined) {
entity.position = scene.clampToHeight(position, objectsToExclude);
}
});
}
// viewer.trackedEntity = entity;
设置视角
carEntity.viewFrom = new Cesium.Cartesian3(15, 15, 6);