Advertisement
Guest User

Cesium

a guest
Jun 12th, 2013
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     "use strict";
  3.     var widgetNode;
  4.     var canvas = createCanvas();  
  5.     var scene = new Cesium.Scene(canvas);
  6.     var ellipsoid = Cesium.Ellipsoid.WGS84;
  7.     var centralBody = new Cesium.CentralBody(ellipsoid);
  8.     var primitives = scene.getPrimitives();
  9.     primitives.setCentralBody(centralBody);
  10.     var transitioner = new Cesium.SceneTransitioner(scene);    
  11.     var clock = new Cesium.Clock();
  12.     var visualizers;
  13.     var timeline;
  14.  
  15.     init();
  16.  
  17.     function init(){
  18.         addLogo();
  19.         addControls();
  20.         createTimeLine();
  21.         createBackground();
  22.         addLayers();
  23.         loadData("./res/lib/js/cesium-git/Apps/CesiumViewer/Gallery/simple.czml");
  24.         render();
  25.         window.addEventListener('resize', resize, false);  
  26.     }
  27.  
  28.     function render() {    
  29.        
  30.         scene.initializeFrame();
  31.         animate();     
  32.         scene.render();
  33.         Cesium.requestAnimationFrame(render);
  34.         resize();
  35.     }  
  36.    
  37.     function addControls(){
  38.         //SceneMod
  39.         var sceneModePicker = new Cesium.SceneModePicker('sceneModePickerContainer', transitioner);
  40.         //Fullscreen
  41.         var fullscreen = new Cesium.FullscreenButton("fullscreenContainer");
  42.         //home button
  43.         var homeButton = new Cesium.HomeButton("homeButton", scene, transitioner, ellipsoid);
  44.     }
  45.  
  46.     function addLayers(){
  47.         var layers = centralBody.getImageryLayers();
  48.         layers.removeAll();
  49.  
  50.         var bingLayer = new Cesium.BingMapsImageryProvider({
  51.             url : 'http://dev.virtualearth.net',
  52.             mapStyle : Cesium.BingMapsStyle.ORDNANCE_SURVEY_BART
  53.         });
  54.         layers.addImageryProvider(bingLayer);
  55.  
  56.         var terrainProvider = new Cesium.CesiumTerrainProvider({
  57.             url: "http://cesium.agi.com/smallterrain"      
  58.         });
  59.         centralBody.terrainProvider = terrainProvider;
  60.  
  61.         var layerGrid = new Cesium.GridImageryProvider();
  62.         layers.addImageryProvider(layerGrid);      
  63.     }
  64.  
  65.     function createBackground(){       
  66.         scene.skyAtmosphere = new Cesium.SkyAtmosphere();
  67.         var imageryUrl = './res/lib/js/cesium-git/Source/Assets/Textures/';
  68.         var skyBoxBaseUrl = imageryUrl + 'SkyBox/tycho2t3_80';
  69.         scene.skyBox = new Cesium.SkyBox({
  70.             positiveX : skyBoxBaseUrl + '_px.jpg',
  71.             negativeX : skyBoxBaseUrl + '_mx.jpg',
  72.             positiveY : skyBoxBaseUrl + '_py.jpg',
  73.             negativeY : skyBoxBaseUrl + '_my.jpg',
  74.             positiveZ : skyBoxBaseUrl + '_pz.jpg',
  75.             negativeZ : skyBoxBaseUrl + '_mz.jpg'
  76.         });
  77.         scene.sun = new Cesium.Sun();
  78.     }
  79.  
  80.     function createTimeLine(){     
  81.         var clockViewModel = new Cesium.ClockViewModel();
  82.         clockViewModel.shouldAnimate = true;
  83.         var animationViewModel = new Cesium.AnimationViewModel(clockViewModel);
  84.         //var clock = animationViewModel.clockViewModel.clock;
  85.         var currentTime = new Cesium.JulianDate();
  86.         var clock = new Cesium.Clock({
  87.             startTime : currentTime.addDays(-0.5),
  88.             stopTime : currentTime.addDays(0.5),
  89.             currentTime : currentTime,
  90.             clockStep : Cesium.ClockStep.SYSTEM_CLOCK_DEPENDENT,
  91.             multiplier: 1
  92.         });
  93.         timeline = new Cesium.Timeline("timelineContainer", clock);
  94.         var animation = new Cesium.Animation("animationContainer", animationViewModel);
  95.     }
  96.  
  97.     var dynamicObjectCollection = new Cesium.DynamicObjectCollection();
  98.    
  99.     function loadData(filePath){
  100.         Cesium.loadJson(filePath).then(function(czml) {
  101.                 console.log("******************************");         
  102.                 Cesium.processCzml(czml, dynamicObjectCollection, filePath);       
  103.                 visualizers = Cesium.VisualizerCollection.createCzmlStandardCollection(scene, dynamicObjectCollection);
  104.                 var availability = dynamicObjectCollection.computeAvailability();
  105.                 if (availability.start.equals(Cesium.Iso8601.MINIMUM_VALUE)) {
  106.                      clock.startTime = new JulianDate();
  107.                      clock.stopTime = clock.startTime.addDays(1);
  108.                      clock.clockRange = Cesium.ClockRange.UNBOUNDED;
  109.                 } else {
  110.                      clock.startTime = availability.start;
  111.                      clock.stopTime = availability.stop;
  112.                      clock.clockRange = Cesium.ClockRange.LOOP;
  113.                 }              
  114.                 clock.currentTime = clock.startTime;
  115.                 timeline.zoomTo(clock.startTime, clock.stopTime);
  116.                 var extent = new Cesium.Extent(-2.056, 0.587, -2.010, 0.633);
  117.                 scene.getCamera().controller.viewExtent(extent);   
  118.                        
  119.                 console.log("******************************");
  120.             }, function (e) {
  121.                 console.error(e);
  122.         });
  123.     }
  124.    
  125.     function createCanvas(){
  126.         //cesium div
  127.         var container = document.getElementById("cesiumContainer");
  128.         widgetNode = document.createElement('div');
  129.         widgetNode.className = 'cesium-widget';
  130.         container.appendChild(widgetNode); 
  131.         var canvas = document.createElement('canvas');
  132.         canvas.className = "fullSize"; 
  133.         widgetNode.appendChild(canvas);
  134.  
  135.         //prevent right-click from opening a context menu.
  136.         canvas.oncontextmenu = function () {
  137.             return false;
  138.         };
  139.         return canvas;
  140.     }
  141.  
  142.     function addLogo(){
  143.         //logo div
  144.         var munLogo = document.createElement('a');
  145.         munLogo.href = 'http://www.mun.ca/';
  146.         munLogo.target = '_blank';
  147.         munLogo.className = 'mun-logo';
  148.         widgetNode.appendChild(munLogo);
  149.         var marinegeomaticslab = document.createElement('a');
  150.         marinegeomaticslab.className = 'marinegeomaticslab';
  151.         widgetNode.appendChild(marinegeomaticslab);
  152.     }
  153.  
  154.     function resize() {
  155.         var width = canvas.clientWidth;
  156.         var height = canvas.clientHeight;
  157.  
  158.         if (canvas.width === width && canvas.height === height) {
  159.             return;
  160.         }
  161.  
  162.         canvas.width = width;
  163.         canvas.height = height;
  164.         scene.getCamera().frustum.aspectRatio = width / height;
  165.     }
  166.  
  167.     function animate() {
  168.         // INSERT CODE HERE to update primitives based on changes to animation time, camera parameters, etc.
  169.     }
  170. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement