Viewer

Viewer

new

A base widget for building applications. It composites all of the standard Cesium widgets into one reusable package. The widget can always be extended by using mixins, which add functionality useful for a variety of applications.

Parameters:
Name Type Argument Description
container Element | String The DOM element or ID that will contain the widget.
options Object <optional>
Configuration options for the widget.
Properties
Name Type Argument Default Description
animation Boolean <optional>
true If set to false, the Animation widget will not be created.
baseLayerPicker Boolean <optional>
true If set to false, the BaseLayerPicker widget will not be created.
fullscreenButton Boolean <optional>
true If set to false, the FullscreenButton widget will not be created.
geocoder Boolean <optional>
true If set to false, the Geocoder widget will not be created.
homeButton Boolean <optional>
true If set to false, the HomeButton widget will not be created.
infoBox Boolean <optional>
true If set to false, the InfoBox widget will not be created.
sceneModePicker Boolean <optional>
true If set to false, the SceneModePicker widget will not be created.
selectionIndicator Boolean <optional>
true If set to false, the SelectionIndicator widget will not be created.
timeline Boolean <optional>
true If set to false, the Timeline widget will not be created.
navigationHelpButton Boolean <optional>
true If set to the false, the navigation help button will not be created.
navigationInstructionsInitiallyVisible Boolean <optional>
true True if the navigation instructions should initially be visible, or false if the should not be shown until the user explicitly clicks the button.
selectedImageryProviderViewModel ProviderViewModel <optional>
The view model for the current base imagery layer, if not supplied the first available base layer is used. This value is only valid if options.baseLayerPicker is set to true.
imageryProviderViewModels Array <optional>
createDefaultImageryProviderViewModels() The array of ProviderViewModels to be selectable from the BaseLayerPicker. This value is only valid if options.baseLayerPicker is set to true.
selectedTerrainProviderViewModel ProviderViewModel <optional>
The view model for the current base terrain layer, if not supplied the first available base layer is used. This value is only valid if options.baseLayerPicker is set to true.
terrainProviderViewModels Array <optional>
createDefaultTerrainProviderViewModels() The array of ProviderViewModels to be selectable from the BaseLayerPicker. This value is only valid if options.baseLayerPicker is set to true.
imageryProvider ImageryProvider <optional>
new BingMapsImageryProvider() The imagery provider to use. This value is only valid if options.baseLayerPicker is set to false.
terrainProvider TerrainProvider <optional>
new EllipsoidTerrainProvider() The terrain provider to use
skyBox SkyBox <optional>
The skybox used to render the stars. When undefined, the default stars are used.
fullscreenElement Element <optional>
document.body The element to make full screen when the full screen button is pressed.
useDefaultRenderLoop Boolean <optional>
true True if this widget should control the render loop, false otherwise.
showRenderLoopErrors Boolean <optional>
true If true, this widget will automatically display an HTML panel to the user containing the error, if a render loop error occurs.
automaticallyTrackDataSourceClocks Boolean <optional>
true If true, this widget will automatically track the clock settings of newly added DataSources, updating if the DataSource's clock changes. Set this to false if you want to configure the clock independently.
contextOptions Object <optional>
undefined Context and WebGL creation properties corresponding to Context#options.
sceneMode SceneMode <optional>
SceneMode.SCENE3D The initial scene mode.
Throws:
  • DeveloperError : Element with id "container" does not exist in the document.
  • DeveloperError : options.imageryProvider is not available when using the BaseLayerPicker widget, specify options.selectedImageryProviderViewModel instead.
  • DeveloperError : options.terrainProvider is not available when using the BaseLayerPicker widget, specify options.selectedTerrainProviderViewModel instead.
  • DeveloperError : options.selectedImageryProviderViewModel is not available when not using the BaseLayerPicker widget, specify options.imageryProvider instead.
  • DeveloperError : options.selectedTerrainProviderViewModel is not available when not using the BaseLayerPicker widget, specify options.terrainProvider instead.
Example
//Initialize the viewer widget with several custom options and mixins.
var viewer = new Cesium.Viewer('cesiumContainer', {
    //Start in Columbus Viewer
    sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
    //Use standard Cesium terrain
    terrainProvider : new Cesium.CesiumTerrainProvider({
        url : '//cesiumjs.org/smallterrain',
        credit : 'Terrain data courtesy Analytical Graphics, Inc.'
    }),
    //Hide the base layer picker
    baseLayerPicker : false,
    //Use OpenStreetMaps
    imageryProvider : new Cesium.OpenStreetMapImageryProvider({
        url : '//a.tile.openstreetmap.org/'
    }),
    // Use high-res stars downloaded from https://github.com/AnalyticalGraphicsInc/cesium-assets
    skyBox : new Cesium.SkyBox({
        sources : {
          positiveX : 'stars/TychoSkymapII.t3_08192x04096_80_px.jpg',
          negativeX : 'stars/TychoSkymapII.t3_08192x04096_80_mx.jpg',
          positiveY : 'stars/TychoSkymapII.t3_08192x04096_80_py.jpg',
          negativeY : 'stars/TychoSkymapII.t3_08192x04096_80_my.jpg',
          positiveZ : 'stars/TychoSkymapII.t3_08192x04096_80_pz.jpg',
          negativeZ : 'stars/TychoSkymapII.t3_08192x04096_80_mz.jpg'
        }
    })
});

//Add basic drag and drop functionality
viewer.extend(Cesium.viewerDragDropMixin);

//Allow users to zoom and follow objects loaded from CZML by clicking on it.
viewer.extend(Cesium.viewerDynamicObjectMixin);

//Show a pop-up alert if we encounter an error when processing a dropped file
viewer.dropError.addEventListener(function(dropHandler, name, error) {
    console.log(error);
    window.alert(error);
});
See:
Source:

Members

:Boolean

Gets or sets whether or not data sources can temporarily pause animation in order to avoid showing an incomplete picture to the user. For example, if asynchronous primitives are being processed in the background, the clock will not advance until the geometry is ready.

:Animation

Gets the Animation widget.

:BaseLayerPicker

Gets the BaseLayerPicker.

:Canvas

Gets the canvas.
Gets the Cesium logo element.

:CesiumWidget

Gets the CesiumWidget.

:Clock

Gets the clock.

:DataSource

Gets or sets the data source to track with the viewer's clock.

:Element

Gets the parent container.

:DataSourceDisplay

Gets the display used for DataSource visualization.

:DataSourceCollection

Gets the set of DataSource instances to be visualized.

:FullscreenButton

Gets the FullscreenButton.

:Geocoder

Gets the Geocoder.

:HomeButton

Gets the HomeButton.

:InfoBox

Gets the info box.

:Event

Gets the event that will be raised when an error is encountered during the default render loop. The widget instance and the generated exception are the only two parameters passed to the event handler. useDefaultRenderLoop will be set to false whenever an exception is generated and must be set back to true to continue rendering after an exception.

:Event

Gets the event that will be raised when an error is encountered during the default render loop. The viewer instance and the generated exception are the only two parameters passed to the event handler. useDefaultRenderLoop will be set to false whenever an exception is generated and must be set back to true to continue rendering after an exception.

:Scene

Gets the scene.

:SceneModePicker

Gets the SceneModePicker.

:ScreenSpaceEventHandler

Gets the screen space event handler.

:SelectionIndicator

Gets the selection indicator.

:Timeline

Gets the Timeline widget.

:Boolean

Gets or sets whether or not this widget should control the render loop. If set to true the widget will use requestAnimationFrame to perform rendering and resizing of the widget, as well as drive the simulation clock. If set to false, you must manually call the resize, render methods as part of a custom render loop.

Methods

Destroys the widget. Should be called if permanently removing the widget from layout.

Extends the base viewer functionality with the provided mixin. A mixin may add additional properties, functions, or other behavior to the provided viewer instance.

Parameters:
Name Type Description
mixin The Viewer mixin to add to this instance.
options The options object to be passed to the mixin function.
See:

Returns:
Boolean true if the object has been destroyed, false otherwise.

Renders the scene. This function is called automatically unless useDefaultRenderLoop is set to false;

Resizes the widget to match the container size. This function is called automatically as needed unless useDefaultRenderLoop is set to false.