Viewer - Cesium Documentation

# Viewer

#### new Viewer(container, options)

  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.

  Name | Type | Description
  --- | --- | ---
  `container` | Element | String | The DOM element or ID that will contain the widget.

  `options`

  Object

  optional Object with the following properties:

  Name | Type | Default | Description
  --- | --- | --- | ---
  `animation` | Boolean | `true` | optional If set to false, the Animation widget will not be created.
  `baseLayerPicker` | Boolean | `true` | optional If set to false, the BaseLayerPicker widget will not be created.
  `fullscreenButton` | Boolean | `true` | optional If set to false, the FullscreenButton widget will not be created.
  `geocoder` | Boolean | `true` | optional If set to false, the Geocoder widget will not be created.
  `homeButton` | Boolean | `true` | optional If set to false, the HomeButton widget will not be created.
  `infoBox` | Boolean | `true` | optional If set to false, the InfoBox widget will not be created.
  `sceneModePicker` | Boolean | `true` | optional If set to false, the SceneModePicker widget will not be created.
  `selectionIndicator` | Boolean | `true` | optional If set to false, the SelectionIndicator widget will not be created.
  `timeline` | Boolean | `true` | optional If set to false, the Timeline widget will not be created.
  `navigationHelpButton` | Boolean | `true` | optional If set to the false, the navigation help button will not be created.
  `navigationInstructionsInitiallyVisible` | Boolean | `true` | optional True if the navigation instructions should initially be visible, or false if the should not be shown until the user explicitly clicks the button.
  `scene3DOnly` | Boolean | `false` | optional When `true`, each geometry instance will only be rendered in 3D to save GPU memory.
  `clock` | Clock | `new Clock()` | optional The clock to use to control current time.
  `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.<ProviderViewModel> | `createDefaultImageryProviderViewModels()` | optional 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.<ProviderViewModel> | `createDefaultTerrainProviderViewModels()` | optional The array of ProviderViewModels to be selectable from the BaseLayerPicker. This value is only valid if options.baseLayerPicker is set to true.
  `imageryProvider` | ImageryProvider | `new BingMapsImageryProvider()` | optional The imagery provider to use. This value is only valid if options.baseLayerPicker is set to false.
  `terrainProvider` | TerrainProvider | `new EllipsoidTerrainProvider()` | optional The terrain provider to use
  `skyBox` | SkyBox |  | optional The skybox used to render the stars. When `undefined`, the default stars are used.
  `skyAtmosphere` | SkyAtmosphere |  | optional Blue sky, and the glow around the Earth's limb. Set to `false` to turn it off.
  `fullscreenElement` | Element | String | `document.body` | optional The element or id to be placed into fullscreen mode when the full screen button is pressed.
  `useDefaultRenderLoop` | Boolean | `true` | optional True if this widget should control the render loop, false otherwise.
  `targetFrameRate` | Number |  | optional The target frame rate when using the default render loop.
  `showRenderLoopErrors` | Boolean | `true` | optional If true, this widget will automatically display an HTML panel to the user containing the error, if a render loop error occurs.
  `automaticallyTrackDataSourceClocks` | Boolean | `true` | optional 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 Context and WebGL creation properties corresponding to `options` passed to `Scene`.
  `sceneMode` | SceneMode | `SceneMode.SCENE3D` | optional The initial scene mode.
  `mapProjection` | MapProjection | `new GeographicProjection()` | optional The map projection to use in 2D and Columbus View modes.
  `globe` | Globe | `new Globe(mapProjection.ellipsoid)` | optional The globe to use in the scene. If set to `false`, no globe will be added.
  `orderIndependentTranslucency` | Boolean | `true` | optional If true and the configuration supports it, use order independent translucency.
  `creditContainer` | Element | String |  | optional The DOM element or ID that will contain the `CreditDisplay`. If not specified, the credits are added to the bottom of the widget itself.
  `dataSources` | DataSourceCollection | `new DataSourceCollection()` | optional The collection of data sources visualized by the widget. If this parameter is provided, the instance is assumed to be owned by the caller and will not be destroyed when the viewer is destroyed.

  ##### 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 : '//assets.agi.com/stk-terrain/world'
          }),
          //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'
              }
          }),
          // Show Columbus View map with Web Mercator projection
          mapProjection : new Cesium.WebMercatorProjection()
      });

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

      //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);
      });

  ##### Demo:

  - Cesium Sandcastle Hello World Demo

  ##### See:

  - Animation
  - BaseLayerPicker
  - CesiumWidget
  - FullscreenButton
  - HomeButton
  - SceneModePicker
  - Timeline
  - viewerDragDropMixin
  Source: Widgets/Viewer/Viewer.js, line 279

### Members

#### allowDataSourcesToSuspendAnimation :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.
  Source: Widgets/Viewer/Viewer.js, line 951

#### animation :Animation

  Gets the Animation widget.
  Source: Widgets/Viewer/Viewer.js, line 720

#### baseLayerPicker :BaseLayerPicker

  Gets the BaseLayerPicker.
  Source: Widgets/Viewer/Viewer.js, line 709

#### bottomContainer :Element

  Gets the DOM element for the area at the bottom of the window containing the `CreditDisplay` and potentially other things.
  Source: Widgets/Viewer/Viewer.js, line 632

#### readonlycamera :Camera

  Gets the camera.
  Source: Widgets/Viewer/Viewer.js, line 850

#### canvas :Canvas

  Gets the canvas.
  Source: Widgets/Viewer/Viewer.js, line 787

#### cesiumLogo :Element

  Gets the Cesium logo element.
  Source: Widgets/Viewer/Viewer.js, line 798

#### cesiumWidget :CesiumWidget

  Gets the CesiumWidget.
  Source: Widgets/Viewer/Viewer.js, line 643

#### clock :Clock

  Gets the clock.
  Source: Widgets/Viewer/Viewer.js, line 861

#### container :Element

  Gets the parent container.
  Source: Widgets/Viewer/Viewer.js, line 620

#### dataSourceDisplay :DataSourceDisplay

  Gets the display used for `DataSource` visualization.
  Source: Widgets/Viewer/Viewer.js, line 753

#### dataSources :DataSourceCollection

  Gets the set of `DataSource` instances to be visualized.
  Source: Widgets/Viewer/Viewer.js, line 776

#### entities :EntityCollection

  Gets the collection of entities not tied to a particular data source. This is a shortcut to `dataSourceDisplay.defaultDataSource.entities`.
  Source: Widgets/Viewer/Viewer.js, line 765

#### fullscreenButton :FullscreenButton

  Gets the FullscreenButton.
  Source: Widgets/Viewer/Viewer.js, line 742

#### geocoder :Geocoder

  Gets the Geocoder.
  Source: Widgets/Viewer/Viewer.js, line 676

#### homeButton :HomeButton

  Gets the HomeButton.
  Source: Widgets/Viewer/Viewer.js, line 687

#### readonlyimageryLayers :ImageryLayerCollection

  Gets the collection of image layers that will be rendered on the globe.
  Source: Widgets/Viewer/Viewer.js, line 822

#### infoBox :InfoBox

  Gets the info box.
  Source: Widgets/Viewer/Viewer.js, line 665

#### resolutionScale :Number

  Gets or sets a scaling factor for rendering resolution. Values less than 1.0 can improve performance on less powerful devices while values greater than 1.0 will render at a higher resolution and then scale down, resulting in improved visual fidelity. For example, if the widget is laid out at a size of 640x480, setting this value to 0.5 will cause the scene to be rendered at 320x240 and then scaled up while setting it to 2.0 will cause the scene to be rendered at 1280x960 and then scaled down.
  Default Value: `1.0`
  Source: Widgets/Viewer/Viewer.js, line 931

#### scene :Scene

  Gets the scene.
  Source: Widgets/Viewer/Viewer.js, line 809

#### sceneModePicker :SceneModePicker

  Gets the SceneModePicker.
  Source: Widgets/Viewer/Viewer.js, line 698

#### screenSpaceEventHandler :ScreenSpaceEventHandler

  Gets the screen space event handler.
  Source: Widgets/Viewer/Viewer.js, line 872

#### selectedEntity :Entity

  Gets or sets the object instance for which to display a selection indicator.
  Source: Widgets/Viewer/Viewer.js, line 1006

#### selectionIndicator :SelectionIndicator

  Gets the selection indicator.
  Source: Widgets/Viewer/Viewer.js, line 654

#### targetFrameRate :Number

  Gets or sets the target frame rate of the widget when `useDefaultRenderLoop` is true. If undefined, the browser's `requestAnimationFrame` implementation determines the frame rate. This value must be greater than 0 and a value higher than the underlying requestAnimationFrame implementatin will have no effect.
  Source: Widgets/Viewer/Viewer.js, line 887

#### terrainProvider :TerrainProvider

  The terrain provider providing surface geometry for the globe.
  Source: Widgets/Viewer/Viewer.js, line 834

#### timeline :Timeline

  Gets the Timeline widget.
  Source: Widgets/Viewer/Viewer.js, line 731

#### trackedEntity :Entity

  Gets or sets the Entity instance currently being tracked by the camera.
  Source: Widgets/Viewer/Viewer.js, line 965

#### useDefaultRenderLoop :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. If an error occurs during rendering, `Scene`'s `renderError` event will be raised and this property will be set to false. It must be set back to true to continue rendering after the error.
  Source: Widgets/Viewer/Viewer.js, line 910

### Methods

#### destroy()

  Destroys the widget. Should be called if permanently removing the widget from layout.
  Source: Widgets/Viewer/Viewer.js, line 1177

#### extend(mixin, options)

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

  Name | Type | Description
  --- | --- | ---
  `mixin` | Viewer~ViewerMixin | The Viewer mixin to add to this instance.
  `options` | Object | The options object to be passed to the mixin function.

  ##### See:

  - viewerDragDropMixin
  Source: Widgets/Viewer/Viewer.js, line 1054

#### flyTo(target, options) → Promise.<Boolean>

  Flies the camera to the provided entity, entities, or data source. If the data source is still in the process of loading or the visualization is otherwise still loading, this method waits for the data to be ready before performing the flight.

  The offset is heading/pitch/range in the local east-north-up reference frame centered at the center of the bounding sphere. The heading and the pitch angles are defined in the local east-north-up reference frame. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are above the plane. Negative pitch angles are below the plane. The range is the distance from the center. If the range is zero, a range will be computed such that the whole bounding sphere is visible.

  In 2D, there must be a top down view. The camera will be placed above the target looking down. The height above the target will be the range. The heading will be determined from the offset. If the heading cannot be determined from the offset, the heading will be north.

  Name | Type | Description
  --- | --- | ---
  `target` | Entity | Array.<Entity> | EntityCollection | DataSource | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource)> | The entity, array of entities, entity collection or data source to view. You can also pass a promise that resolves to one of the previously mentioned types.

  `options`

  Object

  optional Object with the following properties:

  Name | Type | Default | Description
  --- | --- | --- | ---
  `duration` | Number | `3.0` | optional The duration of the flight in seconds.
  `maximumHeight` | Number |  | optional The maximum height at the peak of the flight.
  `offset` | HeadingPitchRange |  | optional The offset from the target in the local east-north-up reference frame centered at the target.

  ##### Returns:

  A Promise that resolves to true if the flight was successful or false if the entity is not currently visualized in the scene or the flight was cancelled.
  Source: Widgets/Viewer/Viewer.js, line 1471

#### forceResize()

  This forces the widget to re-think its layout, including widget sizes and credit placement.
  Source: Widgets/Viewer/Viewer.js, line 1153

#### isDestroyed() → Boolean

  ##### Returns:

  true if the object has been destroyed, false otherwise.
  Source: Widgets/Viewer/Viewer.js, line 1169

#### render()

  Renders the scene. This function is called automatically unless `useDefaultRenderLoop` is set to false;
  Source: Widgets/Viewer/Viewer.js, line 1162

#### resize()

  Resizes the widget to match the container size. This function is called automatically as needed unless `useDefaultRenderLoop` is set to false.
  Source: Widgets/Viewer/Viewer.js, line 1069

#### zoomTo(target, offset) → Promise.<Boolean>

  Asynchronously sets the camera to view the provided entity, entities, or data source. If the data source is still in the process of loading or the visualization is otherwise still loading, this method waits for the data to be ready before performing the zoom.

  The offset is heading/pitch/range in the local east-north-up reference frame centered at the center of the bounding sphere. The heading and the pitch angles are defined in the local east-north-up reference frame. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are above the plane. Negative pitch angles are below the plane. The range is the distance from the center. If the range is zero, a range will be computed such that the whole bounding sphere is visible.

  In 2D, there must be a top down view. The camera will be placed above the target looking down. The height above the target will be the range. The heading will be determined from the offset. If the heading cannot be determined from the offset, the heading will be north.

  Name | Type | Description
  --- | --- | ---
  `target` | Entity | Array.<Entity> | EntityCollection | DataSource | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource)> | The entity, array of entities, entity collection or data source to view. You can also pass a promise that resolves to one of the previously mentioned types.
  `offset` | HeadingPitchRange | optional The offset from the center of the entity in the local east-north-up reference frame.

  ##### Returns:

  A Promise that resolves to true if the zoom was successful or false if the entity is not currently visualized in the scene or the zoom was cancelled.
  Source: Widgets/Viewer/Viewer.js, line 1445

### Type Definitions

#### ViewerMixin(viewer, options)

  A function that augments a Viewer instance with additional functionality.

  Name | Type | Description
  --- | --- | ---
  `viewer` | Viewer | The viewer instance.
  `options` | Object | Options object to be passed to the mixin function.

  ##### See:

  - Viewer#extend
  Source: Widgets/Viewer/Viewer.js, line 1648