(function () {
"use strict";
var widgetNode;
var canvas = createCanvas();
var scene = new Cesium.Scene(canvas);
var ellipsoid = Cesium.Ellipsoid.WGS84;
var centralBody = new Cesium.CentralBody(ellipsoid);
var primitives = scene.getPrimitives();
primitives.setCentralBody(centralBody);
var transitioner = new Cesium.SceneTransitioner(scene);
var clock = new Cesium.Clock();
var visualizers;
var timeline;
init();
function init(){
addLogo();
addControls();
createTimeLine();
createBackground();
addLayers();
loadData("./res/lib/js/cesium-git/Apps/CesiumViewer/Gallery/simple.czml");
render();
window.addEventListener('resize', resize, false);
}
function render() {
scene.initializeFrame();
animate();
scene.render();
Cesium.requestAnimationFrame(render);
resize();
}
function addControls(){
//SceneMod
var sceneModePicker = new Cesium.SceneModePicker('sceneModePickerContainer', transitioner);
//Fullscreen
var fullscreen = new Cesium.FullscreenButton("fullscreenContainer");
//home button
var homeButton = new Cesium.HomeButton("homeButton", scene, transitioner, ellipsoid);
}
function addLayers(){
var layers = centralBody.getImageryLayers();
layers.removeAll();
var bingLayer = new Cesium.BingMapsImageryProvider({
url : 'http://dev.virtualearth.net',
mapStyle : Cesium.BingMapsStyle.ORDNANCE_SURVEY_BART
});
layers.addImageryProvider(bingLayer);
var terrainProvider = new Cesium.CesiumTerrainProvider({
url: "http://cesium.agi.com/smallterrain"
});
centralBody.terrainProvider = terrainProvider;
var layerGrid = new Cesium.GridImageryProvider();
layers.addImageryProvider(layerGrid);
}
function createBackground(){
scene.skyAtmosphere = new Cesium.SkyAtmosphere();
var imageryUrl = './res/lib/js/cesium-git/Source/Assets/Textures/';
var skyBoxBaseUrl = imageryUrl + 'SkyBox/tycho2t3_80';
scene.skyBox = new Cesium.SkyBox({
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.sun = new Cesium.Sun();
}
function createTimeLine(){
var clockViewModel = new Cesium.ClockViewModel();
clockViewModel.shouldAnimate = true;
var animationViewModel = new Cesium.AnimationViewModel(clockViewModel);
//var clock = animationViewModel.clockViewModel.clock;
var currentTime = new Cesium.JulianDate();
var clock = new Cesium.Clock({
startTime : currentTime.addDays(-0.5),
stopTime : currentTime.addDays(0.5),
currentTime : currentTime,
clockStep : Cesium.ClockStep.SYSTEM_CLOCK_DEPENDENT,
multiplier: 1
});
timeline = new Cesium.Timeline("timelineContainer", clock);
var animation = new Cesium.Animation("animationContainer", animationViewModel);
}
var dynamicObjectCollection = new Cesium.DynamicObjectCollection();
function loadData(filePath){
Cesium.loadJson(filePath).then(function(czml) {
console.log("******************************");
Cesium.processCzml(czml, dynamicObjectCollection, filePath);
visualizers = Cesium.VisualizerCollection.createCzmlStandardCollection(scene, dynamicObjectCollection);
var availability = dynamicObjectCollection.computeAvailability();
if (availability.start.equals(Cesium.Iso8601.MINIMUM_VALUE)) {
clock.startTime = new JulianDate();
clock.stopTime = clock.startTime.addDays(1);
clock.clockRange = Cesium.ClockRange.UNBOUNDED;
} else {
clock.startTime = availability.start;
clock.stopTime = availability.stop;
clock.clockRange = Cesium.ClockRange.LOOP;
}
clock.currentTime = clock.startTime;
timeline.zoomTo(clock.startTime, clock.stopTime);
var extent = new Cesium.Extent(-2.056, 0.587, -2.010, 0.633);
scene.getCamera().controller.viewExtent(extent);
console.log("******************************");
}, function (e) {
console.error(e);
});
}
function createCanvas(){
//cesium div
var container = document.getElementById("cesiumContainer");
widgetNode = document.createElement('div');
widgetNode.className = 'cesium-widget';
container.appendChild(widgetNode);
var canvas = document.createElement('canvas');
canvas.className = "fullSize";
widgetNode.appendChild(canvas);
//prevent right-click from opening a context menu.
canvas.oncontextmenu = function () {
return false;
};
return canvas;
}
function addLogo(){
//logo div
var munLogo = document.createElement('a');
munLogo.href = 'http://www.mun.ca/';
munLogo.target = '_blank';
munLogo.className = 'mun-logo';
widgetNode.appendChild(munLogo);
var marinegeomaticslab = document.createElement('a');
marinegeomaticslab.className = 'marinegeomaticslab';
widgetNode.appendChild(marinegeomaticslab);
}
function resize() {
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (canvas.width === width && canvas.height === height) {
return;
}
canvas.width = width;
canvas.height = height;
scene.getCamera().frustum.aspectRatio = width / height;
}
function animate() {
// INSERT CODE HERE to update primitives based on changes to animation time, camera parameters, etc.
}
}());