Maybe we should look into using the widget. I think it will take a bit of work to update all of our code, but it may be worth it. I will look into this.
Below the code we use to set up Cesium (with a few items stripped out)...
The code to load the KMZ is at the bottom.
I'm still getting the error I described in the earlier posts.
var canvas = document.createElement('canvas');
canvas.className = "fullSize";
if (!document.getElementById("divCanvas")) {
var divCesiumContainer = document.createElement("div");
divCesiumContainer.id = "divCanvas";
document.body.appendChild(divCesiumContainer);
}
document.getElementById("divCanvas").appendChild(canvas);
scene = new Cesium.Scene({
canvas: canvas
});
scene.globe = new Cesium.Globe();
scene.globe.baseColor = Cesium.Color.BLACK;
scene.fxaa = true;
scene.skyAtmosphere = new Cesium.SkyAtmosphere();
var skyBoxBaseUrl = "resources/plugins/cesium/Cesium/Assets/Textures/SkyBox/tycho2t3_80";
scene.skyBox = new Cesium.SkyBox({
sources : {
positiveX : skyBoxBaseUrl + '_px.jpg',
negativeX : skyBoxBaseUrl + '_mx.jpg',
positiveY : skyBoxBaseUrl + '_py.jpg',
negativeY : skyBoxBaseUrl + '_my.jpg',
positiveZ : skyBoxBaseUrl + '_pz.jpg',
negativeZ : skyBoxBaseUrl + '_mz.jpg'
}
});
scene.scene3DOnly = true;
// Tile imagery
scene.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({ url:‘http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer’ }));
// Terrain
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url: ‘http://cesiumjs.org/stk-terrain/tilesets/world/tiles’,
credit: ‘’
});
scene.terrainProvider = cesiumTerrainProviderMeshes;
scene.globe.enableLighting = false;
scene.globe.showNight = false;
scene.globe.showDay = false;
scene.globe.affectedByLighting = false;
scene.debugShowFramesPerSecond = false;
if (blnShowFPS) {
var performanceContainer = document.createElement('div');
performanceContainer.className = 'cesium-performanceDisplay';
performanceContainer.style.position = 'absolute';
performanceContainer.style.bottom = '60px';
performanceContainer.style.right = '10px';
document.getElementById("divCanvas").appendChild(performanceContainer);
var performanceDisplay = new Cesium.PerformanceDisplay({container: performanceContainer});
}
var lastCamera = {position: Cesium.Cartesian3.clone(scene.camera.position),
direction: Cesium.Cartesian3.clone(scene.camera.direction),
up: Cesium.Cartesian3.clone(scene.camera.up),
right: Cesium.Cartesian3.clone(scene.camera.right),
transform: Cesium.Matrix4.clone(scene.camera.transform)
};
function animate() {
if (blnShowFPS && Cesium.defined(performanceDisplay)) performanceDisplay.update();
refreshAnimatedObjects();
if (scene.camera) {
if (!scene.camera.position.equals(lastCamera.position) ||
!scene.camera.direction.equals(lastCamera.direction) ||
!scene.camera.up.equals(lastCamera.up) ||
!scene.camera.right.equals(lastCamera.right) ||
!scene.camera.transform.equals(lastCamera.transform)) {
lastCamera = {position: Cesium.Cartesian3.clone(scene.camera.position),
direction: Cesium.Cartesian3.clone(scene.camera.direction),
up: Cesium.Cartesian3.clone(scene.camera.up),
right: Cesium.Cartesian3.clone(scene.camera.right),
transform: Cesium.Matrix4.clone(scene.camera.transform)
};
EVENT_CameraChanged.dispatch();
}
}
}
function tick() {
scene.initializeFrame();
animate();
scene.render();
Cesium.requestAnimationFrame(tick);
}
tick();
// Prevent right-click from opening a context menu.
canvas.oncontextmenu = function() {
return false;
};
// Resize handler
var onResize = function() {
var width = window.innerWidth;
var height = window.innerHeight;
if (canvas.width === width && canvas.height === height) {
return;
}
canvas.width = width;
canvas.height = height;
scene.camera.frustum.aspectRatio = width / height;
};
window.addEventListener('resize', onResize, false);
onResize();
scene.camera.setView({
position : Cesium.Cartesian3.fromDegrees(dblInitLon, dblInitLat, dblInitAlt),
heading : degreesToRadians(0.0), // east, default value is 0.0 (north)
pitch : degreesToRadians(-90), // default value (looking down)
roll : 0.0 // default value
});
// Screen handler
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
// get an array of all primitives at the mouse position
var pickedObjects = scene.pick(movement.position);
if(Cesium.defined(pickedObjects)) {
if (typeof pickedObjects['primitive']['TrackId'] !== 'undefined' && pickedObjects['primitive']['TrackId'] !== null) {
onModelClick(null,pickedObjects['primitive']['TrackId']);
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
scene.screenSpaceCameraController.tiltEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH];
scene.screenSpaceCameraController.zoomEventTypes = [Cesium.CameraEventType.WHEEL, Cesium.CameraEventType.PINCH];
scene.screenSpaceCameraController.enableLook = false;
// *********************************************************************
// Test loading a KMZ file
var dataSources = new Cesium.DataSourceCollection();
var dataSourceDisplay = new Cesium.DataSourceDisplay({
scene: scene,
dataSourceCollection: dataSources
});
//dataSourceDisplay.update needs to be called once a frame after all other updates have been made,
//in this case we call it in the preRender event.
scene.preRender.addEventListener(function(scene, time){
dataSourceDisplay.update(time);
});
//Now that everything is configured, we can load KML and add to list of data sources.
dataSources.add(Cesium.KmlDataSource.load('path_to_kmz'));
// *********************************************************************