From 762f9a732077ef9639cec4bfeef91ef0b5a34fdc Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Thu, 24 Jul 2014 12:05:31 -0400 Subject: [PATCH 1/5] Add Sandcastle.addDefaultToolbarButton Sandcastle.addDefaultToolbarButton excutes and highlights the toolbar immediately, eliminating the need for breaking out an extra function to call (muddying the code in the process). --- Apps/Sandcastle/Sandcastle-header.js | 5 + Apps/Sandcastle/gallery/CZML.html | 151 +++++++++++++-------------- Apps/Sandcastle/gallery/Picking.html | 10 +- 3 files changed, 81 insertions(+), 85 deletions(-) diff --git a/Apps/Sandcastle/Sandcastle-header.js b/Apps/Sandcastle/Sandcastle-header.js index c82a832d66ce..8bf97f8703d9 100644 --- a/Apps/Sandcastle/Sandcastle-header.js +++ b/Apps/Sandcastle/Sandcastle-header.js @@ -28,6 +28,11 @@ button.textContent = text; document.getElementById(toolbarID || 'toolbar').appendChild(button); }, + addDefaultToolbarButton : function(text, onclick, toolbarID) { + window.Sandcastle.addToolbarButton(text, onclick, toolbarID); + window.Sandcastle.highlight(onclick); + onclick(); + }, addToolbarMenu : function(options, onchange, toolbarID) { var menu = document.createElement('select'); menu.className = 'sandcastle-button'; diff --git a/Apps/Sandcastle/gallery/CZML.html b/Apps/Sandcastle/gallery/CZML.html index 1471e80ffef7..9f06382b7be2 100644 --- a/Apps/Sandcastle/gallery/CZML.html +++ b/Apps/Sandcastle/gallery/CZML.html @@ -32,7 +32,7 @@ var viewer = new Cesium.Viewer('cesiumContainer'); viewer.extend(Cesium.viewerEntityMixin); -function czmlSatellites() { +Sandcastle.addDefaultToolbarButton('Satellites', function() { viewer.dataSources.removeAll(); var czmlDataSource = new Cesium.CzmlDataSource(); @@ -40,11 +40,6 @@ viewer.dataSources.add(czmlDataSource); viewer.homeButton.viewModel.command(); }); -} -czmlSatellites(); - -Sandcastle.addToolbarButton('Satellites', function() { - czmlSatellites(); }); Sandcastle.addToolbarButton('Sensors', function() { @@ -67,81 +62,81 @@ }); }); -var builtInCzml = [{ - "id" : "document", - "version" : "1.0" -}, { - "id" : "Vehicle", - "availability" : "2012-08-04T16:00:00Z/2012-08-04T17:04:54Z", - "billboard" : { - "eyeOffset" : { - "cartesian" : [0.0, 0.0, 0.0] - }, - "horizontalOrigin" : "CENTER", - "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEISURBVEhLvVXBDYQwDOuojHKj8LhBbpTbpBCEkZsmIVTXq1RVQGrHiWlLmTTqPiZBlyLgy/KSZQ5JSHDQ/mCYCsC8106kDU0AdwRnvYZArWRcAl0dcYJq1hWCb3hBrumbDAVMwAC82WoRvgMnVMDBnB0nYZFTbE6BBvdUGqVqCbjBIk3PyFFR/NU7EKzru+qZsau3ryPwwCRLKYOzutZuCL6fUmWeJGzNzL/RxAMrUmASSCkkAayk2IxPlwhAAYGpsiHQjbLccfdOY5gKkCXAMi7SscAwbQpAnKyctWyUZ6z8ja3OGMepwD8asz+9FnSvbhU8uVOHFIwQsI3/p0CfhuqCSQuxLqsN6mu8SS+N42MAAAAASUVORK5CYII=", - "pixelOffset" : { - "cartesian2" : [0.0, 0.0] - }, - "scale" : 0.8, - "show" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "boolean" : true - }], - "verticalOrigin" : "BOTTOM" - }, - "label" : { - "fillColor" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "rgba" : [255, 255, 0, 255] - }], - "font" : "bold 10pt Segoe UI Semibold", - "horizontalOrigin" : "LEFT", - "outlineColor" : { - "rgba" : [0, 0, 0, 255] +Sandcastle.addToolbarButton('Built-in CZML', function() { + viewer.dataSources.removeAll(); + + var builtInCzml = [{ + "id" : "document", + "version" : "1.0" + }, { + "id" : "Vehicle", + "availability" : "2012-08-04T16:00:00Z/2012-08-04T17:04:54Z", + "billboard" : { + "eyeOffset" : { + "cartesian" : [0.0, 0.0, 0.0] + }, + "horizontalOrigin" : "CENTER", + "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEISURBVEhLvVXBDYQwDOuojHKj8LhBbpTbpBCEkZsmIVTXq1RVQGrHiWlLmTTqPiZBlyLgy/KSZQ5JSHDQ/mCYCsC8106kDU0AdwRnvYZArWRcAl0dcYJq1hWCb3hBrumbDAVMwAC82WoRvgMnVMDBnB0nYZFTbE6BBvdUGqVqCbjBIk3PyFFR/NU7EKzru+qZsau3ryPwwCRLKYOzutZuCL6fUmWeJGzNzL/RxAMrUmASSCkkAayk2IxPlwhAAYGpsiHQjbLccfdOY5gKkCXAMi7SscAwbQpAnKyctWyUZ6z8ja3OGMepwD8asz+9FnSvbhU8uVOHFIwQsI3/p0CfhuqCSQuxLqsN6mu8SS+N42MAAAAASUVORK5CYII=", + "pixelOffset" : { + "cartesian2" : [0.0, 0.0] + }, + "scale" : 0.8, + "show" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "boolean" : true + }], + "verticalOrigin" : "BOTTOM" }, - "pixelOffset" : { - "cartesian2" : [10.0, 0.0] + "label" : { + "fillColor" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "rgba" : [255, 255, 0, 255] + }], + "font" : "bold 10pt Segoe UI Semibold", + "horizontalOrigin" : "LEFT", + "outlineColor" : { + "rgba" : [0, 0, 0, 255] + }, + "pixelOffset" : { + "cartesian2" : [10.0, 0.0] + }, + "scale" : 1.0, + "show" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "boolean" : true + }], + "style" : "FILL", + "text" : "Vehicle", + "verticalOrigin" : "CENTER" }, - "scale" : 1.0, - "show" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "boolean" : true - }], - "style" : "FILL", - "text" : "Vehicle", - "verticalOrigin" : "CENTER" - }, - "path" : { - "material" : { - "solidColor" : { - "color" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "rgba" : [255, 255, 0, 255] - }] - } + "path" : { + "material" : { + "solidColor" : { + "color" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "rgba" : [255, 255, 0, 255] + }] + } + }, + "width" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "number" : 5.0 + }], + "show" : [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", + "boolean" : true + }] }, - "width" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "number" : 5.0 - }], - "show" : [{ - "interval" : "2012-08-04T16:00:00Z/2012-08-04T18:00:00Z", - "boolean" : true - }] - }, - "position" : { - "interpolationAlgorithm" : "LAGRANGE", - "interpolationDegree" : 1, - "epoch" : "2012-08-04T16:00:00Z", - // Trimmed to just 2 points - "cartesian" : [0.0, -2379754.6637012, -4665332.88013588, 3628133.68924173, - 3894.0, -2291336.52323822, -4682359.21232197, 3662718.52171165] - } -}]; - -Sandcastle.addToolbarButton('Built-in CZML', function() { - viewer.dataSources.removeAll(); - + "position" : { + "interpolationAlgorithm" : "LAGRANGE", + "interpolationDegree" : 1, + "epoch" : "2012-08-04T16:00:00Z", + // Trimmed to just 2 points + "cartesian" : [0.0, -2379754.6637012, -4665332.88013588, 3628133.68924173, + 3894.0, -2291336.52323822, -4682359.21232197, 3662718.52171165] + } + }]; + var czmlDataSource = new Cesium.CzmlDataSource(); czmlDataSource.load(builtInCzml, 'Built-in CZML'); viewer.dataSources.add(czmlDataSource); diff --git a/Apps/Sandcastle/gallery/Picking.html b/Apps/Sandcastle/gallery/Picking.html index 4873155c98fb..4b7bfdf51a87 100644 --- a/Apps/Sandcastle/gallery/Picking.html +++ b/Apps/Sandcastle/gallery/Picking.html @@ -103,7 +103,9 @@ handler = handler && handler.destroy(); } -function pickCartographicPosition() { +Sandcastle.addDefaultToolbarButton('Show Cartographic Position on Mouse Over', function() { + cleanup(); + var ellipsoid = scene.globe.ellipsoid; var labels = new Cesium.LabelCollection(); label = labels.add(); @@ -122,12 +124,6 @@ label.text = ''; } }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); -} -pickCartographicPosition(); - -Sandcastle.addToolbarButton('Show Cartographic Position on Mouse Over', function() { - cleanup(); - pickCartographicPosition(); }); Sandcastle.addToolbarButton('Pick Billboard', function() { From c7445f0c3b3d7147eeb395ffdd612c77259e9c1c Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Thu, 24 Jul 2014 14:33:12 -0400 Subject: [PATCH 2/5] Add Sandcastle.reset When defined by a demo, Sandcastle.reset is called whenever a button or menu selection is main. This allows for the bookeeping/cleanup code to be cleanly abstracted away from the example-specific code that the user is interested in. --- Apps/Sandcastle/Sandcastle-header.js | 12 +- Apps/Sandcastle/gallery/3D Models.html | 47 ++-- Apps/Sandcastle/gallery/Billboards.html | 151 ++++++------ Apps/Sandcastle/gallery/CZML.html | 37 +-- Apps/Sandcastle/gallery/Camera.html | 123 +++++----- Apps/Sandcastle/gallery/Labels.html | 83 +++---- Apps/Sandcastle/gallery/Materials.html | 55 +---- Apps/Sandcastle/gallery/Picking.html | 16 +- Apps/Sandcastle/gallery/Terrain.html | 293 ++++++++++++------------ 9 files changed, 361 insertions(+), 456 deletions(-) diff --git a/Apps/Sandcastle/Sandcastle-header.js b/Apps/Sandcastle/Sandcastle-header.js index 8bf97f8703d9..cbb863105c7c 100644 --- a/Apps/Sandcastle/Sandcastle-header.js +++ b/Apps/Sandcastle/Sandcastle-header.js @@ -22,6 +22,7 @@ var button = document.createElement('button'); button.className = 'sandcastle-button'; button.onclick = function() { + window.Sandcastle.reset(); window.Sandcastle.highlight(onclick); onclick(); }; @@ -33,10 +34,15 @@ window.Sandcastle.highlight(onclick); onclick(); }, - addToolbarMenu : function(options, onchange, toolbarID) { + addToolbarMenu : function(options, toolbarID) { var menu = document.createElement('select'); menu.className = 'sandcastle-button'; - menu.onchange = onchange; + menu.onchange = function() { + window.Sandcastle.reset(); + if (menu.selectedIndex > 0) { + options[menu.selectedIndex].onselect(); + } + }; document.getElementById(toolbarID || 'toolbar').appendChild(menu); for (var i = 0, len = options.length; i < len; ++i) { @@ -45,6 +51,8 @@ option.value = options[i].value; menu.appendChild(option); } + }, + reset : function() { } }; diff --git a/Apps/Sandcastle/gallery/3D Models.html b/Apps/Sandcastle/gallery/3D Models.html index 923029316eaf..13cd30eab088 100644 --- a/Apps/Sandcastle/gallery/3D Models.html +++ b/Apps/Sandcastle/gallery/3D Models.html @@ -34,14 +34,14 @@ height = Cesium.defaultValue(height, 0.0); var modelMatrix = Cesium.Transforms.northUpEastToFixedFrame(Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height)); - + scene.primitives.removeAll(); // Remove previous model var model = scene.primitives.add(Cesium.Model.fromGltf({ url : url, modelMatrix : modelMatrix, minimumPixelSize : 128 })); - + model.readyToRender.addEventListener(function(model) { // Play and loop all animations at half-spead model.activeAnimations.addAll({ @@ -63,38 +63,37 @@ } var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); -handler.setInputAction( - function (movement) { - var pick = scene.pick(movement.endPosition); - if (Cesium.defined(pick) && Cesium.defined(pick.node) && Cesium.defined(pick.mesh)) { - // Output glTF node and mesh under the mouse. - console.log('node: ' + pick.node.name + '. mesh: ' + pick.mesh.name); - } - }, - Cesium.ScreenSpaceEventType.MOUSE_MOVE -); +handler.setInputAction(function(movement) { + var pick = scene.pick(movement.endPosition); + if (Cesium.defined(pick) && Cesium.defined(pick.node) && Cesium.defined(pick.mesh)) { + // Output glTF node and mesh under the mouse. + console.log('node: ' + pick.node.name + '. mesh: ' + pick.mesh.name); + } +}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); /////////////////////////////////////////////////////////////////////////// var options = [{ - text : 'Aircraft', - url : '../../SampleData/models/CesiumAir/Cesium_Air.gltf', - height : 5000.0 +text : 'Aircraft', +onselect : function() { + createModel('../../SampleData/models/CesiumAir/Cesium_Air.gltf', 5000.0); + } }, { - text : 'Ground vehicle', - url : '../../SampleData/models/CesiumGround/Cesium_Ground.gltf' +text : 'Ground vehicle', + onselect : function() { + createModel('../../SampleData/models/CesiumGround/Cesium_Ground.gltf'); + } }, { text : 'Skinned character', - url : '../../SampleData/models/CesiumMan/Cesium_Man.gltf' + onselect : function() { + createModel('../../SampleData/models/CesiumMan/Cesium_Man.gltf'); + } }]; -createModel(options[0].url, options[0].height); -Sandcastle.addToolbarMenu(options, function() { - var option = options[this.selectedIndex]; - createModel(option.url, option.height); -}); +Sandcastle.addToolbarMenu(options); +options[0].onselect(); //Sandcastle_End - Sandcastle.finishedLoading(); +Sandcastle.finishedLoading(); } if (typeof Cesium !== "undefined") { startup(Cesium); diff --git a/Apps/Sandcastle/gallery/Billboards.html b/Apps/Sandcastle/gallery/Billboards.html index 961d564429cb..a18257415107 100644 --- a/Apps/Sandcastle/gallery/Billboards.html +++ b/Apps/Sandcastle/gallery/Billboards.html @@ -31,13 +31,8 @@ var scene = viewer.scene; var primitives = scene.primitives; -function reset() { - primitives.removeAll(); -} - function addBillboard() { Sandcastle.declare(addBillboard); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -58,7 +53,6 @@ function setBillboardProperties() { Sandcastle.declare(setBillboardProperties); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -90,7 +84,6 @@ function changeBillboardProperties() { Sandcastle.declare(changeBillboardProperties); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -118,7 +111,6 @@ function addMultipleBillboards() { Sandcastle.declare(addMultipleBillboards); - reset(); Cesium.when.all([ Cesium.loadImage('../images/Cesium_Logo_overlay.png'), Cesium.loadImage('../images/facility.gif') @@ -160,7 +152,6 @@ function scaleByDistance() { Sandcastle.declare(scaleByDistance); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -182,7 +173,6 @@ function fadeByDistance() { Sandcastle.declare(fadeByDistance); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -204,7 +194,6 @@ function offsetByDistance() { Sandcastle.declare(offsetByDistance); - reset(); Cesium.when.all([ Cesium.loadImage('../images/Cesium_Logo_overlay.png'), Cesium.loadImage('../images/facility.gif') @@ -243,7 +232,6 @@ function addPointBillboards() { Sandcastle.declare(addPointBillboards); - reset(); // A white circle is drawn into a 2D canvas. The canvas is used as // a texture for billboards, each of which applies a different color // and scale to change the point's appearance. @@ -292,7 +280,6 @@ function addMarkerBillboards() { Sandcastle.declare(addMarkerBillboards); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -393,7 +380,6 @@ function inReferenceFrame() { Sandcastle.declare(inReferenceFrame); - reset(); var image = new Image(); image.onload = function() { var billboards = new Cesium.BillboardCollection(); @@ -430,83 +416,76 @@ image.src = '../images/facility.gif'; } -function createUI() { - function selectMenuOption(menu, options) { - options[menu.selectedIndex].onselect(); +Sandcastle.addToolbarMenu([{ + text : 'Add billboard', + onselect : function() { + addBillboard(); + Sandcastle.highlight(addBillboard); } - - var options = [{ - text : 'Add billboard', - onselect : function() { - addBillboard(); - Sandcastle.highlight(addBillboard); - } - }, { - text : 'Set billboard properties at creation', - onselect : function() { - setBillboardProperties(); - Sandcastle.highlight(setBillboardProperties); - } - }, { - text : 'Change billboard properties', - onselect : function() { - changeBillboardProperties(); - Sandcastle.highlight(changeBillboardProperties); - } - }, { - text : 'Add multiple billboards', - onselect : function() { - addMultipleBillboards(); - Sandcastle.highlight(addMultipleBillboards); - } - }, { - text : 'Scale by viewer distance', - onselect : function() { - scaleByDistance(); - Sandcastle.highlight(scaleByDistance); - } - }, { - text : 'Fade by viewer distance', - onselect : function() { - fadeByDistance(); - Sandcastle.highlight(fadeByDistance); - } - }, { - text : 'Offset by viewer distance', - onselect : function() { - offsetByDistance(); - Sandcastle.highlight(offsetByDistance); - } - }, { - text : 'Add point billboards', - onselect : function() { - addPointBillboards(); - Sandcastle.highlight(addPointBillboards); - } - }, { - text : 'Add marker billboards', - onselect : function() { - addMarkerBillboards(); - Sandcastle.highlight(addMarkerBillboards); - } - }, { - text : 'Add billboards in reference frame', - onselect : function() { - inReferenceFrame(); - Sandcastle.highlight(inReferenceFrame); - } - }]; - - Sandcastle.addToolbarMenu(options, function() { - selectMenuOption(this, options); - }); -} +}, { + text : 'Set billboard properties at creation', + onselect : function() { + setBillboardProperties(); + Sandcastle.highlight(setBillboardProperties); + } +}, { + text : 'Change billboard properties', + onselect : function() { + changeBillboardProperties(); + Sandcastle.highlight(changeBillboardProperties); + } +}, { + text : 'Add multiple billboards', + onselect : function() { + addMultipleBillboards(); + Sandcastle.highlight(addMultipleBillboards); + } +}, { + text : 'Scale by viewer distance', + onselect : function() { + scaleByDistance(); + Sandcastle.highlight(scaleByDistance); + } +}, { + text : 'Fade by viewer distance', + onselect : function() { + fadeByDistance(); + Sandcastle.highlight(fadeByDistance); + } +}, { + text : 'Offset by viewer distance', + onselect : function() { + offsetByDistance(); + Sandcastle.highlight(offsetByDistance); + } +}, { + text : 'Add point billboards', + onselect : function() { + addPointBillboards(); + Sandcastle.highlight(addPointBillboards); + } +}, { + text : 'Add marker billboards', + onselect : function() { + addMarkerBillboards(); + Sandcastle.highlight(addMarkerBillboards); + } +}, { + text : 'Add billboards in reference frame', + onselect : function() { + inReferenceFrame(); + Sandcastle.highlight(inReferenceFrame); + } +}]); + +Sandcastle.reset = function () { + primitives.removeAll(); +}; -createUI(); addBillboard(); Sandcastle.highlight(addBillboard); //Sandcastle_End - Sandcastle.finishedLoading(); +Sandcastle.finishedLoading(); } if (typeof Cesium !== "undefined") { startup(Cesium); diff --git a/Apps/Sandcastle/gallery/CZML.html b/Apps/Sandcastle/gallery/CZML.html index 9f06382b7be2..98941c414624 100644 --- a/Apps/Sandcastle/gallery/CZML.html +++ b/Apps/Sandcastle/gallery/CZML.html @@ -23,6 +23,7 @@

Loading...

+ diff --git a/Apps/Sandcastle/gallery/Camera.html b/Apps/Sandcastle/gallery/Camera.html index 1a1e47cd4dc5..caaf94fab96e 100644 --- a/Apps/Sandcastle/gallery/Camera.html +++ b/Apps/Sandcastle/gallery/Camera.html @@ -31,24 +31,8 @@ var scene = viewer.scene; var clock = viewer.clock; -function reset() { - scene.primitives.removeAll(); - scene.tweens.removeAll(); - - scene.camera.setTransform(Cesium.Matrix4.IDENTITY); - - clock.multiplier = 1.0; - scene.preRender.removeEventListener(icrf); - scene.globe.enableLighting = false; -} - -scene.morphComplete.addEventListener(function() { - reset(); -}); - function flyToSanDiego() { Sandcastle.declare(flyToSanDiego); - reset(); scene.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) }); @@ -56,7 +40,6 @@ function flyToLocation() { Sandcastle.declare(flyToLocation); - reset(); // Create callback for browser's geolocation function fly(position) { @@ -71,7 +54,6 @@ function viewRectangle() { Sandcastle.declare(viewRectangle); - reset(); var west = -77.0; var south = 38.0; @@ -95,7 +77,6 @@ function flyToRectangle() { Sandcastle.declare(flyToRectangle); - reset(); var west = -90.0; var south = 38.0; @@ -121,7 +102,6 @@ function setReferenceFrame() { Sandcastle.declare(setReferenceFrame); - reset(); var center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883); var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center); @@ -157,7 +137,6 @@ function viewInICRF() { Sandcastle.declare(viewInICRF); - reset(); var vm = viewer.homeButton.viewModel; vm.duration = 0.0; @@ -169,60 +148,60 @@ scene.globe.enableLighting = true; } -function createUI() { - function selectMenuOption(menu, options) { - if (menu.selectedIndex > 0) { - options[menu.selectedIndex].onselect(); - } - menu.selectedIndex = 0; +Sandcastle.addToolbarMenu([{ + text : 'Camera Options' +}, { + text : 'Fly to San Diego', + onselect : function() { + flyToSanDiego(); + Sandcastle.highlight(flyToSanDiego); } - - var options = [{ - text : 'Camera Options' - }, { - text : 'Fly to San Diego', - onselect : function() { - flyToSanDiego(); - Sandcastle.highlight(flyToSanDiego); - } - }, { - text : 'Fly to My Location', - onselect : function() { - flyToLocation(); - Sandcastle.highlight(flyToLocation); - } - }, { - text : 'Fly to Rectangle', - onselect : function() { - flyToRectangle(); - Sandcastle.highlight(flyToRectangle); - } - }, { - text : 'View a Rectangle', - onselect : function() { - viewRectangle(); - Sandcastle.highlight(viewRectangle); - } - }, { - text : 'Set camera reference frame', - onselect : function() { - setReferenceFrame(); - Sandcastle.highlight(setReferenceFrame); - } - }, { - text : 'View in ICRF', - onselect : function() { - viewInICRF(); - Sandcastle.highlight(viewInICRF); - } - }]; - - Sandcastle.addToolbarMenu(options, function() { - selectMenuOption(this, options); - }); +}, { + text : 'Fly to My Location', + onselect : function() { + flyToLocation(); + Sandcastle.highlight(flyToLocation); + } +}, { + text : 'Fly to Rectangle', + onselect : function() { + flyToRectangle(); + Sandcastle.highlight(flyToRectangle); + } +}, { + text : 'View a Rectangle', + onselect : function() { + viewRectangle(); + Sandcastle.highlight(viewRectangle); + } +}, { + text : 'Set camera reference frame', + onselect : function() { + setReferenceFrame(); + Sandcastle.highlight(setReferenceFrame); + } +}, { + text : 'View in ICRF', + onselect : function() { + viewInICRF(); + Sandcastle.highlight(viewInICRF); + } +}]); + +Sandcastle.reset = function() { + scene.primitives.removeAll(); + scene.tweens.removeAll(); + + scene.camera.setTransform(Cesium.Matrix4.IDENTITY); + + clock.multiplier = 1.0; + scene.preRender.removeEventListener(icrf); + scene.globe.enableLighting = false; } -createUI(); +scene.morphComplete.addEventListener(function() { + Sandcastle.reset(); +}); //Sandcastle_End Sandcastle.finishedLoading(); } diff --git a/Apps/Sandcastle/gallery/Labels.html b/Apps/Sandcastle/gallery/Labels.html index 1e5517892fb2..5660d9b28df0 100644 --- a/Apps/Sandcastle/gallery/Labels.html +++ b/Apps/Sandcastle/gallery/Labels.html @@ -149,55 +149,44 @@ scene.primitives.add(labels); } -function createUI() { - function selectMenuOption(menu, options) { - options[menu.selectedIndex].onselect(); +Sandcastle.addToolbarMenu([{ + text : 'Add label', + onselect : function() { + addLabel(); + Sandcastle.highlight(addLabel); } - - var options = [{ - text : 'Add label', - onselect : function() { - addLabel(); - Sandcastle.highlight(addLabel); - } - }, { - text : 'Set font', - onselect : function() { - setFont(); - Sandcastle.highlight(setFont); - } - }, { - text : 'Set properties', - onselect : function() { - setProperties(); - Sandcastle.highlight(setProperties); - } - }, { - text : 'Add labels in reference frame', - onselect : function() { - inReferenceFrame(); - Sandcastle.highlight(inReferenceFrame); - } - }, { - text : 'Offset label by distance', - onselect : function() { - offsetByDistance(); - Sandcastle.highlight(offsetByDistance); - } - }, { - text : 'Fade label by distance', - onselect : function() { - fadeByDistance(); - Sandcastle.highlight(fadeByDistance); - } - }]; - - Sandcastle.addToolbarMenu(options, function() { - selectMenuOption(this, options); - }); -} +}, { + text : 'Set font', + onselect : function() { + setFont(); + Sandcastle.highlight(setFont); + } +}, { + text : 'Set properties', + onselect : function() { + setProperties(); + Sandcastle.highlight(setProperties); + } +}, { + text : 'Add labels in reference frame', + onselect : function() { + inReferenceFrame(); + Sandcastle.highlight(inReferenceFrame); + } +}, { + text : 'Offset label by distance', + onselect : function() { + offsetByDistance(); + Sandcastle.highlight(offsetByDistance); + } +}, { + text : 'Fade label by distance', + onselect : function() { + fadeByDistance(); + Sandcastle.highlight(fadeByDistance); + } +}]); -createUI(); addLabel(scene); Sandcastle.highlight(addLabel); //Sandcastle_End diff --git a/Apps/Sandcastle/gallery/Materials.html b/Apps/Sandcastle/gallery/Materials.html index 68b3232ef9cd..bd6519790a81 100644 --- a/Apps/Sandcastle/gallery/Materials.html +++ b/Apps/Sandcastle/gallery/Materials.html @@ -296,14 +296,7 @@ rectangle.show = false; } - function selectMenuOption(menu, options) { - if (menu.selectedIndex > 0) { - options[menu.selectedIndex].onselect(); - } - menu.selectedIndex = 0; - } - - var commonMaterialOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Common materials' }, { text : 'Color', @@ -319,13 +312,9 @@ applyImageMaterial(rectangle, scene); Sandcastle.highlight(applyImageMaterial); } - }]; - - Sandcastle.addToolbarMenu(commonMaterialOptions, function() { - selectMenuOption(this, commonMaterialOptions); - }); + }]); - var proceduralTextureOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Procedural textures' }, { text : 'Checkerboard', @@ -355,13 +344,9 @@ applyStripeMaterial(rectangle, scene); Sandcastle.highlight(applyStripeMaterial); } - }]; - - Sandcastle.addToolbarMenu(proceduralTextureOptions, function() { - selectMenuOption(this, proceduralTextureOptions); - }); + }]); - var baseMaterialOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Base materials' }, { text : 'Alpha Map', @@ -405,13 +390,9 @@ applySpecularMapMaterial(rectangle, scene); Sandcastle.highlight(applySpecularMapMaterial); } - }]; + }]); - Sandcastle.addToolbarMenu(baseMaterialOptions, function() { - selectMenuOption(this, baseMaterialOptions); - }); - - var miscMaterialOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Misc materials' }, { text : 'Rim Lighting', @@ -427,13 +408,9 @@ applyWaterMaterial(worldRectangle, scene); Sandcastle.highlight(applyWaterMaterial); } - }]; - - Sandcastle.addToolbarMenu(miscMaterialOptions, function() { - selectMenuOption(this, miscMaterialOptions); - }); + }]); - var compositeMaterialOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Example composite materials' }, { text : 'Composite Example', @@ -442,13 +419,9 @@ applyCompositeMaterial(worldRectangle, scene); Sandcastle.highlight(applyCompositeMaterial); } - }]; + }]); - Sandcastle.addToolbarMenu(compositeMaterialOptions, function() { - selectMenuOption(this, compositeMaterialOptions); - }); - - var polylineMaterialOptions = [{ + Sandcastle.addToolbarMenu([{ text : 'Polyline materials' }, { text : 'Polyline Arrow', @@ -471,11 +444,7 @@ applyPolylineOutlineMaterial(polyline, scene); Sandcastle.highlight(applyPolylineOutlineMaterial); } - }]; - - Sandcastle.addToolbarMenu(polylineMaterialOptions, function() { - selectMenuOption(this, polylineMaterialOptions); - }); + }]); document.getElementById('toolbar').style.width = '10%'; } diff --git a/Apps/Sandcastle/gallery/Picking.html b/Apps/Sandcastle/gallery/Picking.html index 4b7bfdf51a87..54f8517e3cb4 100644 --- a/Apps/Sandcastle/gallery/Picking.html +++ b/Apps/Sandcastle/gallery/Picking.html @@ -98,14 +98,7 @@ greenPolygon.picked = false; } -function cleanup() { - scene.primitives.removeAll(); - handler = handler && handler.destroy(); -} - Sandcastle.addDefaultToolbarButton('Show Cartographic Position on Mouse Over', function() { - cleanup(); - var ellipsoid = scene.globe.ellipsoid; var labels = new Cesium.LabelCollection(); label = labels.add(); @@ -127,8 +120,6 @@ }); Sandcastle.addToolbarButton('Pick Billboard', function() { - cleanup(); - addBillboard(scene); // If the mouse is over the billboard, change its scale and color @@ -152,8 +143,6 @@ var originalColor = {}; Sandcastle.addToolbarButton('Drill-Down Picking', function() { - cleanup(); - var primitives = scene.primitives; addOverlappingPolygons(scene); @@ -199,6 +188,11 @@ } }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); }); + +Sandcastle.reset = function() { + scene.primitives.removeAll(); + handler = handler && handler.destroy(); +}; //Sandcastle_End Sandcastle.finishedLoading(); } diff --git a/Apps/Sandcastle/gallery/Terrain.html b/Apps/Sandcastle/gallery/Terrain.html index e22b9649bae7..621003591a9c 100644 --- a/Apps/Sandcastle/gallery/Terrain.html +++ b/Apps/Sandcastle/gallery/Terrain.html @@ -31,143 +31,6 @@ function startup(Cesium) { "use strict"; //Sandcastle_Begin -function createTerrainMenu(terrainProviders) { - var terrainProviderOptions = terrainProviders.map(function(terrainProvider) { - return { - text : terrainProvider.name - }; - }); - - Sandcastle.addToolbarMenu(terrainProviderOptions, function() { - scene.terrainProvider = terrainProviders[this.selectedIndex].provider; - }, 'terrainMenu'); - - Sandcastle.addToolbarButton('Mount Everest', function() { - var eye, target, up; - - if (scene.mode === Cesium.SceneMode.SCENE3D) { - eye = new Cesium.Cartesian3(294572.0645397696, 5637826.573008351, 2978624.6868285); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9028130862217908, -0.42449297750082904, -0.06880583840911567), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(0.40668971896562117, 0.790807045510862, 0.45741413322152297); - scene.camera.lookAt(eye, target, up); - } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { - eye = new Cesium.Cartesian3(9684590.891310014, 3114799.076252769, 9849.375792522824); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.8929328433855669, -0.00005779973945286486, -0.45018988645076763), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(-0.4501898855076042, -0.0000291369789812141, 0.8929328452557279); - scene.camera.lookAt(eye, target, up); - } else { - scene.camera.viewRectangle(new Cesium.Rectangle(1.516102969, 0.48744464, 1.518102969, 0.48944464)); - } - }, 'zoomButtons'); - - Sandcastle.addToolbarButton('Half Dome', function() { - var eye, target, up; - - if (scene.mode === Cesium.SceneMode.SCENE3D) { - eye = new Cesium.Cartesian3(-2496304.1498512086, -4391818.97382059, 3884176.4503971986); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9279518715011381, -0.29488412129953234, -0.22792252890604328), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(-0.11836693744723503, -0.8130611584421428, 0.5700182635106171); - scene.camera.lookAt(eye, target, up); - } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { - eye = new Cesium.Cartesian3(-13314946.646404704, 4200941.442507448, 2468.225945515426); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9624895834866811, 0.04124314776883213, -0.26816562874787864), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(0.2679197697914868, 0.011480478929947842, 0.9633728227203466); - scene.camera.lookAt(eye, target, up); - } else { - scene.camera.viewRectangle(new Cesium.Rectangle(-2.08724538, 0.6577939, -2.08524538, 0.6597939)); - } - }, 'zoomButtons'); - - Sandcastle.addToolbarButton('San Francisco Bay', function() { - var eye, target, up; - - if (scene.mode === Cesium.SceneMode.SCENE3D) { - eye = new Cesium.Cartesian3(-2674718.9291375633, -4332137.224608461, 3888180.6614196445); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.40034097132786534, 0.9155843741828319, 0.03784653786617176), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(-0.6502679490649945, -0.3129458646313862, 0.6922546353438556); - scene.camera.lookAt(eye, target, up); - } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { - eye = new Cesium.Cartesian3(-13562569.113918452, 4176598.9965795614, 37656.37201701476); - target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.8108519561707095, 0.4023795334200999, -0.42498213639958615), new Cesium.Cartesian3()); - up = new Cesium.Cartesian3(-0.3806859699462094, 0.18891270085627615, 0.905201736488051); - scene.camera.lookAt(eye, target, up); - } else { - scene.camera.viewRectangle(new Cesium.Rectangle(-2.147621889, 0.64829691, -2.125621889, 0.67029691)); - } - }, 'zoomButtons'); - - var terrainSamplePositions; - var billboards; - var labels; - - function sampleTerrainSuccess() { - var ellipsoid = Cesium.Ellipsoid.WGS84; - - if (typeof billboards === 'undefined') { - billboards = new Cesium.BillboardCollection(); - - Cesium.when(Cesium.loadImage('../images/facility.gif'), function(image) { - var textureAtlas = new Cesium.TextureAtlas({ - scene : scene, - images : [image] - }); - billboards.textureAtlas = textureAtlas; - }); - } else { - billboards.removeAll(); - } - - if (typeof labels === 'undefined') { - labels = new Cesium.LabelCollection(); - } else { - labels.removeAll(); - } - - for( var i = 0; i < terrainSamplePositions.length; ++i ){ - var position = terrainSamplePositions[i]; - billboards.add({ - position : ellipsoid.cartographicToCartesian(position), - verticalOrigin : Cesium.VerticalOrigin.BOTTOM, - scale : 0.7, - imageIndex : 0 - }); - - labels.add({ - position : ellipsoid.cartographicToCartesian(position), - text : position.height.toFixed(1), - horizontalOrigin : Cesium.HorizontalOrigin.CENTER, - scale : 0.3, - pixelOffset : new Cesium.Cartesian2(0,-14), - fillColor : new Cesium.Color(1,0,0), - outlineColor : Cesium.Color.WHITE - }); - - } - scene.primitives.add(billboards); - scene.primitives.add(labels); - } - - Sandcastle.addToolbarButton('Sample Everest Terrain', function() { - var gridWidth = 41; - var gridHeight = 41; - var everestLatitude = Cesium.Math.toRadians(27.988257); - var everestLongitude = Cesium.Math.toRadians(86.925145); - var rectangleHalfSize = 0.005; - var e = new Cesium.Rectangle(everestLongitude - rectangleHalfSize,everestLatitude - rectangleHalfSize,everestLongitude + rectangleHalfSize,everestLatitude + rectangleHalfSize); - terrainSamplePositions = []; - for (var y = 0; y < gridHeight; ++y) { - for (var x = 0; x < gridWidth; ++x) { - var longitude = Cesium.Math.lerp(e.west, e.east, x / (gridWidth - 1)); - var latitude = Cesium.Math.lerp(e.south, e.north, y / (gridHeight - 1)); - var position = new Cesium.Cartographic(longitude, latitude); - terrainSamplePositions.push(position); - } - } - - Cesium.when(Cesium.sampleTerrain(scene.terrainProvider, 9, terrainSamplePositions), sampleTerrainSuccess); - }, 'sampleButtons'); -} - var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.scene; @@ -190,18 +53,156 @@ credit : 'Terrain data courtesy VT MÄK' }); -var terrainProviders = [ - { name : 'CesiumTerrainProvider - STK World Terrain meshes', provider : cesiumTerrainProviderMeshes }, - { name : 'CesiumTerrainProvider - Small Terrain heightmaps and water mask', provider : cesiumTerrainProviderHeightmaps }, - { name : 'EllipsoidTerrainProvider', provider : ellipsoidProvider }, - { name : 'VRTheWorldTerrainProvider', provider : vrTheWorldProvider } -]; - scene.terrainProvider = cesiumTerrainProviderMeshes; -createTerrainMenu(terrainProviders); +Sandcastle.addToolbarMenu([{ + text : 'CesiumTerrainProvider - STK World Terrain meshes', + onselect : function() { + scene.terrainProvider = cesiumTerrainProviderMeshes; + } +}, { + text : 'CesiumTerrainProvider - Small Terrain heightmaps and water mask', + onselect : function() { + scene.terrainProvider = cesiumTerrainProviderHeightmaps; + } +}, { + text : 'EllipsoidTerrainProvider', + onselect : function() { + scene.terrainProvider = ellipsoidProvider; + } +}, { + text : 'VRTheWorldTerrainProvider', + onselect : function() { + scene.terrainProvider = vrTheWorldProvider; + } +}], 'terrainMenu'); + +Sandcastle.addToolbarButton('Mount Everest', function() { + var eye, target, up; + + if (scene.mode === Cesium.SceneMode.SCENE3D) { + eye = new Cesium.Cartesian3(294572.0645397696, 5637826.573008351, 2978624.6868285); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9028130862217908, -0.42449297750082904, -0.06880583840911567), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(0.40668971896562117, 0.790807045510862, 0.45741413322152297); + scene.camera.lookAt(eye, target, up); + } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { + eye = new Cesium.Cartesian3(9684590.891310014, 3114799.076252769, 9849.375792522824); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.8929328433855669, -0.00005779973945286486, -0.45018988645076763), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(-0.4501898855076042, -0.0000291369789812141, 0.8929328452557279); + scene.camera.lookAt(eye, target, up); + } else { + scene.camera.viewRectangle(new Cesium.Rectangle(1.516102969, 0.48744464, 1.518102969, 0.48944464)); + } +}, 'zoomButtons'); + +Sandcastle.addToolbarButton('Half Dome', function() { + var eye, target, up; + + if (scene.mode === Cesium.SceneMode.SCENE3D) { + eye = new Cesium.Cartesian3(-2496304.1498512086, -4391818.97382059, 3884176.4503971986); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9279518715011381, -0.29488412129953234, -0.22792252890604328), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(-0.11836693744723503, -0.8130611584421428, 0.5700182635106171); + scene.camera.lookAt(eye, target, up); + } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { + eye = new Cesium.Cartesian3(-13314946.646404704, 4200941.442507448, 2468.225945515426); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9624895834866811, 0.04124314776883213, -0.26816562874787864), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(0.2679197697914868, 0.011480478929947842, 0.9633728227203466); + scene.camera.lookAt(eye, target, up); + } else { + scene.camera.viewRectangle(new Cesium.Rectangle(-2.08724538, 0.6577939, -2.08524538, 0.6597939)); + } +}, 'zoomButtons'); + +Sandcastle.addToolbarButton('San Francisco Bay', function() { + var eye, target, up; + + if (scene.mode === Cesium.SceneMode.SCENE3D) { + eye = new Cesium.Cartesian3(-2674718.9291375633, -4332137.224608461, 3888180.6614196445); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.40034097132786534, 0.9155843741828319, 0.03784653786617176), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(-0.6502679490649945, -0.3129458646313862, 0.6922546353438556); + scene.camera.lookAt(eye, target, up); + } else if (scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) { + eye = new Cesium.Cartesian3(-13562569.113918452, 4176598.9965795614, 37656.37201701476); + target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(-0.8108519561707095, 0.4023795334200999, -0.42498213639958615), new Cesium.Cartesian3()); + up = new Cesium.Cartesian3(-0.3806859699462094, 0.18891270085627615, 0.905201736488051); + scene.camera.lookAt(eye, target, up); + } else { + scene.camera.viewRectangle(new Cesium.Rectangle(-2.147621889, 0.64829691, -2.125621889, 0.67029691)); + } +}, 'zoomButtons'); + +var terrainSamplePositions; +var billboards; +var labels; + +function sampleTerrainSuccess() { + var ellipsoid = Cesium.Ellipsoid.WGS84; + + if (typeof billboards === 'undefined') { + billboards = new Cesium.BillboardCollection(); + + Cesium.when(Cesium.loadImage('../images/facility.gif'), function(image) { + var textureAtlas = new Cesium.TextureAtlas({ + scene : scene, + images : [image] + }); + billboards.textureAtlas = textureAtlas; + }); + } else { + billboards.removeAll(); + } + + if (typeof labels === 'undefined') { + labels = new Cesium.LabelCollection(); + } else { + labels.removeAll(); + } + + for (var i = 0; i < terrainSamplePositions.length; ++i) { + var position = terrainSamplePositions[i]; + billboards.add({ + position : ellipsoid.cartographicToCartesian(position), + verticalOrigin : Cesium.VerticalOrigin.BOTTOM, + scale : 0.7, + imageIndex : 0 + }); + + labels.add({ + position : ellipsoid.cartographicToCartesian(position), + text : position.height.toFixed(1), + horizontalOrigin : Cesium.HorizontalOrigin.CENTER, + scale : 0.3, + pixelOffset : new Cesium.Cartesian2(0, -14), + fillColor : new Cesium.Color(1, 0, 0), + outlineColor : Cesium.Color.WHITE + }); + + } + scene.primitives.add(billboards); + scene.primitives.add(labels); +} + +Sandcastle.addToolbarButton('Sample Everest Terrain', function() { + var gridWidth = 41; + var gridHeight = 41; + var everestLatitude = Cesium.Math.toRadians(27.988257); + var everestLongitude = Cesium.Math.toRadians(86.925145); + var rectangleHalfSize = 0.005; + var e = new Cesium.Rectangle(everestLongitude - rectangleHalfSize, everestLatitude - rectangleHalfSize, everestLongitude + rectangleHalfSize, everestLatitude + rectangleHalfSize); + terrainSamplePositions = []; + for (var y = 0; y < gridHeight; ++y) { + for (var x = 0; x < gridWidth; ++x) { + var longitude = Cesium.Math.lerp(e.west, e.east, x / (gridWidth - 1)); + var latitude = Cesium.Math.lerp(e.south, e.north, y / (gridHeight - 1)); + var position = new Cesium.Cartographic(longitude, latitude); + terrainSamplePositions.push(position); + } + } + + Cesium.when(Cesium.sampleTerrain(scene.terrainProvider, 9, terrainSamplePositions), sampleTerrainSuccess); +}, 'sampleButtons'); //Sandcastle_End - Sandcastle.finishedLoading(); +Sandcastle.finishedLoading(); } if (typeof Cesium !== "undefined") { startup(Cesium); From 394ab4c85cdc7aebc8f8760a0836c04244d1136d Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Thu, 24 Jul 2014 14:47:02 -0400 Subject: [PATCH 3/5] Add missing semicolor. --- Apps/Sandcastle/gallery/Camera.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/Sandcastle/gallery/Camera.html b/Apps/Sandcastle/gallery/Camera.html index caaf94fab96e..d0695ae61d9c 100644 --- a/Apps/Sandcastle/gallery/Camera.html +++ b/Apps/Sandcastle/gallery/Camera.html @@ -197,7 +197,7 @@ clock.multiplier = 1.0; scene.preRender.removeEventListener(icrf); scene.globe.enableLighting = false; -} +}; scene.morphComplete.addEventListener(function() { Sandcastle.reset(); From e04f02740e4e75b218ef91c9a1b0bb872241a0cd Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 25 Jul 2014 10:19:41 -0400 Subject: [PATCH 4/5] Update GeoJSON example to use new helper functions Also changed logic to defer execution of the default action until loading is finsihed; this way we can run the reset function before the default action. --- Apps/Sandcastle/Sandcastle-header.js | 12 ++++++-- .../gallery/GeoJSON and TopoJSON.html | 30 +++++++------------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Apps/Sandcastle/Sandcastle-header.js b/Apps/Sandcastle/Sandcastle-header.js index cbb863105c7c..87c63cd1bceb 100644 --- a/Apps/Sandcastle/Sandcastle-header.js +++ b/Apps/Sandcastle/Sandcastle-header.js @@ -1,6 +1,7 @@ (function() { "use strict"; + var defaultAction; var bucket = window.location.href; var pos = bucket.lastIndexOf('/'); if (pos > 0 && pos < (bucket.length - 1)) { @@ -15,6 +16,14 @@ }, registered : [], finishedLoading : function() { + window.Sandcastle.reset(); + + if(defaultAction) { + window.Sandcastle.highlight(defaultAction); + defaultAction(); + defaultAction = undefined; + } + document.body.className = document.body.className.replace(/(?:\s|^)sandcastle-loading(?:\s|$)/, ' '); }, addToolbarButton : function(text, onclick, toolbarID) { @@ -31,8 +40,7 @@ }, addDefaultToolbarButton : function(text, onclick, toolbarID) { window.Sandcastle.addToolbarButton(text, onclick, toolbarID); - window.Sandcastle.highlight(onclick); - onclick(); + defaultAction = onclick; }, addToolbarMenu : function(options, toolbarID) { var menu = document.createElement('select'); diff --git a/Apps/Sandcastle/gallery/GeoJSON and TopoJSON.html b/Apps/Sandcastle/gallery/GeoJSON and TopoJSON.html index 683da0e92e5b..8cd964d5fbd4 100644 --- a/Apps/Sandcastle/gallery/GeoJSON and TopoJSON.html +++ b/Apps/Sandcastle/gallery/GeoJSON and TopoJSON.html @@ -27,28 +27,20 @@ function startup(Cesium) { "use strict"; //Sandcastle_Begin -var usStates = '../../SampleData/ne_10m_us_states.json'; - +//Create the viewer var viewer = new Cesium.Viewer('cesiumContainer'); Cesium.viewerEntityMixin(viewer); -//Load a GeoJSON or TopoJSON file with default settings. -function basicLoading(){ +//Example 1: Load a GeoJSON or TopoJSON file with default settings. +Sandcastle.addDefaultToolbarButton('Basic loading', function() { var dataSource = new Cesium.GeoJsonDataSource(); viewer.dataSources.add(dataSource); - dataSource.loadUrl(usStates); -} - -//Add button to run the basic loading example. -Sandcastle.addToolbarButton('Basic loading', function() { - resetDemo(); - basicLoading(); + dataSource.loadUrl('../../SampleData/ne_10m_us_states.json'); }); -//Apply custom graphics to a GeoJSON or TopoJSON file based -//on the metadata contained in the file. +//Example 2: Apply custom graphics to a GeoJSON or TopoJSON file +//based on the metadata contained in the file. Sandcastle.addToolbarButton('Custom Graphics', function() { - resetDemo(); //Seed the random number generator for repeatable results. Cesium.Math.setRandomNumberSeed(0); @@ -56,8 +48,8 @@ var dataSource = new Cesium.GeoJsonDataSource(); viewer.dataSources.add(dataSource); - //Load the document and then set custom graphics - dataSource.loadUrl(usStates).then(function() { + //Load the document into the data source and then set custom graphics + dataSource.loadUrl('../../SampleData/ne_10m_us_states.json').then(function() { //Get the array of entities var entities = dataSource.entities.entities; @@ -88,7 +80,7 @@ }); //Reset the scene when switching demos. -function resetDemo() { +Sandcastle.reset = function() { viewer.dataSources.removeAll(); //Set the camera to a US centered tilted view. @@ -96,9 +88,7 @@ camera.constrainedAxis = Cesium.Cartesian3.UNIT_Z; camera.transform = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-97.5, 38)); camera.lookAt(new Cesium.Cartesian3(0.0, -5000000.0, 4000000.0), Cesium.Cartesian3.ZERO, Cesium.Cartesian3.UNIT_Z); -} -resetDemo(); -basicLoading(); +}; //Sandcastle_End Sandcastle.finishedLoading(); } From bad094a5ee7e10b72edfffd34ac04a7988fc295e Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 25 Jul 2014 14:27:39 -0400 Subject: [PATCH 5/5] Better `onselect` behavior in Sandcastle. --- Apps/Sandcastle/Sandcastle-header.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Apps/Sandcastle/Sandcastle-header.js b/Apps/Sandcastle/Sandcastle-header.js index 87c63cd1bceb..0cc3c28fb31a 100644 --- a/Apps/Sandcastle/Sandcastle-header.js +++ b/Apps/Sandcastle/Sandcastle-header.js @@ -47,8 +47,9 @@ menu.className = 'sandcastle-button'; menu.onchange = function() { window.Sandcastle.reset(); - if (menu.selectedIndex > 0) { - options[menu.selectedIndex].onselect(); + var item = options[menu.selectedIndex]; + if (item && typeof item.onselect === 'function') { + item.onselect(); } }; document.getElementById(toolbarID || 'toolbar').appendChild(menu);