# Viewer

#### new Cesium.Viewer(container, options)
widgets/Source/Viewer/Viewer.js 396

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` | Viewer.ConstructorOptions | optional Object describing initialization options

##### Throws:

- DeveloperError : Element with id "container" does not exist in the document.
- DeveloperError : options.selectedImageryProviderViewModel is not available when not using the BaseLayerPicker widget, specify options.baseLayer 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.
    try {
      const viewer = new Cesium.Viewer("cesiumContainer", {
        // Start in Columbus Viewer
        sceneMode: Cesium.SceneMode.COLUMBUS_VIEW,
        // Use Cesium World Terrain
        terrain: Cesium.Terrain.fromWorldTerrain(),
        // Hide the base layer picker
        baseLayerPicker: false,
        // Use OpenStreetMaps
        baseLayer: new Cesium.ImageryLayer(new Cesium.OpenStreetMapImageryProvider({
          url: "https://tile.openstreetmap.org/"
        })),
        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()
      });
    } catch (error) {
      console.log(error);
    }

    // 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

### Members

#### allowDataSourcesToSuspendAnimation : boolean
widgets/Source/Viewer/Viewer.js 1424

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.

#### readonly animation : Animation
widgets/Source/Viewer/Viewer.js 1084

Gets the Animation widget.

#### readonly baseLayerPicker : BaseLayerPicker
widgets/Source/Viewer/Viewer.js 1060

Gets the BaseLayerPicker.

#### readonly bottomContainer : Element
widgets/Source/Viewer/Viewer.js 964

Gets the DOM element for the area at the bottom of the window containing the `CreditDisplay` and potentially other things.

#### readonly camera : Camera
widgets/Source/Viewer/Viewer.js 1262

Gets the camera.

#### readonly canvas : HTMLCanvasElement
widgets/Source/Viewer/Viewer.js 1169

Gets the canvas.

#### readonly cesiumWidget : CesiumWidget
widgets/Source/Viewer/Viewer.js 976

Gets the CesiumWidget.

#### readonly clock : Clock
widgets/Source/Viewer/Viewer.js 1301

Gets the clock.

#### clockTrackedDataSource : DataSource
widgets/Source/Viewer/Viewer.js 1504

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

#### readonly clockViewModel : ClockViewModel
widgets/Source/Viewer/Viewer.js 1313

Gets the clock view model.

#### readonly container : Element
widgets/Source/Viewer/Viewer.js 939

Gets the parent container.

#### creditDisplay : CreditDisplay
widgets/Source/Viewer/Viewer.js 951

Manages the list of credits to display on screen and in the lightbox.

#### readonly dataSourceDisplay : DataSourceDisplay
widgets/Source/Viewer/Viewer.js 1132

Gets the display used for `DataSource` visualization.

#### readonly dataSources : DataSourceCollection
widgets/Source/Viewer/Viewer.js 1157

Gets the set of `DataSource` instances to be visualized.

#### readonly ellipsoid : Ellipsoid
widgets/Source/Viewer/Viewer.js 1276

Gets the default ellipsoid for the scene.

Default Value: `Ellipsoid.default`

#### readonly entities : EntityCollection
widgets/Source/Viewer/Viewer.js 1145

Gets the collection of entities not tied to a particular data source. This is a shortcut to `dataSourceDisplay.defaultDataSource.entities`.

#### readonly fullscreenButton : FullscreenButton
widgets/Source/Viewer/Viewer.js 1108

Gets the FullscreenButton.

#### readonly geocoder : Geocoder
widgets/Source/Viewer/Viewer.js 1012

Gets the Geocoder.

#### readonly homeButton : HomeButton
widgets/Source/Viewer/Viewer.js 1024

Gets the HomeButton.

#### readonly imageryLayers : ImageryLayerCollection
widgets/Source/Viewer/Viewer.js 1234

Gets the collection of image layers that will be rendered on the globe.

#### readonly infoBox : InfoBox
widgets/Source/Viewer/Viewer.js 1000

Gets the info box.

#### readonly navigationHelpButton : NavigationHelpButton
widgets/Source/Viewer/Viewer.js 1072

Gets the NavigationHelpButton.

#### readonly postProcessStages : PostProcessStageCollection
widgets/Source/Viewer/Viewer.js 1289

Gets the post-process stages.

#### readonly projectionPicker : ProjectionPicker
widgets/Source/Viewer/Viewer.js 1048

Gets the ProjectionPicker.

#### resolutionScale : number
widgets/Source/Viewer/Viewer.js 1384

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`

#### readonly scene : Scene
widgets/Source/Viewer/Viewer.js 1181

Gets the scene.

#### readonly sceneModePicker : SceneModePicker
widgets/Source/Viewer/Viewer.js 1036

Gets the SceneModePicker.

#### readonly screenSpaceEventHandler : ScreenSpaceEventHandler
widgets/Source/Viewer/Viewer.js 1325

Gets the screen space event handler.

#### selectedEntity : Entity|undefined
widgets/Source/Viewer/Viewer.js 1455

Gets or sets the object instance for which to display a selection indicator. If a user interactively picks a Cesium3DTilesFeature instance, then this property will contain a transient Entity instance with a property named "feature" that is the instance that was picked.

#### readonly selectedEntityChanged : Event
widgets/Source/Viewer/Viewer.js 1483

Gets the event that is raised when the selected entity changes.

#### readonly selectionIndicator : SelectionIndicator
widgets/Source/Viewer/Viewer.js 988

Gets the selection indicator.

#### readonly shadowMap : ShadowMap
widgets/Source/Viewer/Viewer.js 1221

Get the scene's shadow map

#### shadows : boolean
widgets/Source/Viewer/Viewer.js 1192

Determines if shadows are cast by light sources.

#### targetFrameRate : number
widgets/Source/Viewer/Viewer.js 1340

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. If defined, this value must be greater than 0. A value higher than the underlying requestAnimationFrame implementation will have no effect.

#### terrainProvider : TerrainProvider
widgets/Source/Viewer/Viewer.js 1246

The terrain provider providing surface geometry for the globe.

#### terrainShadows : ShadowMode
widgets/Source/Viewer/Viewer.js 1206

Determines if the terrain casts or shadows from light sources.

#### readonly timeline : Timeline
widgets/Source/Viewer/Viewer.js 1096

Gets the Timeline widget.

#### trackedEntity : Entity|undefined
widgets/Source/Viewer/Viewer.js 1438

Gets or sets the Entity instance currently being tracked by the camera.

#### readonly trackedEntityChanged : Event
widgets/Source/Viewer/Viewer.js 1494

Gets the event that is raised when the tracked entity changes.

#### useBrowserRecommendedResolution : boolean
widgets/Source/Viewer/Viewer.js 1405

Boolean flag indicating if the browser's recommended resolution is used. If true, the browser's device pixel ratio is ignored and 1.0 is used instead, effectively rendering based on CSS pixels instead of device pixels. This can improve performance on less powerful devices that have high pixel density. When false, rendering will be in device pixels. `Viewer#resolutionScale` will still take effect whether this flag is true or false.

Default Value: `true`

#### useDefaultRenderLoop : boolean
widgets/Source/Viewer/Viewer.js 1363

Gets or sets whether or not this widget should control the render loop. If 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.

#### readonly vrButton : VRButton
widgets/Source/Viewer/Viewer.js 1120

Gets the VRButton.

### Methods

#### destroy()
widgets/Source/Viewer/Viewer.js 1675

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

#### extend(mixin, options)
widgets/Source/Viewer/Viewer.js 1527

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 | optional The options object to be passed to the mixin function.

##### See:

- viewerDragDropMixin

#### flyTo(target, options) → Promise.<boolean>
widgets/Source/Viewer/Viewer.js 2017

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 | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud|VoxelPrimitive)> | The entity, array of entities, entity collection, data source, Cesium3DTileset, point cloud, or imagery layer 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 target is not currently visualized in the scene or the flight was cancelled. //TODO: Cleanup entity mentions

#### forceResize()
widgets/Source/Viewer/Viewer.js 1651

This forces the widget to re-think its layout, including widget sizes and credit placement.

#### isDestroyed() → boolean
widgets/Source/Viewer/Viewer.js 1667

##### Returns:

true if the object has been destroyed, false otherwise.

#### render()
widgets/Source/Viewer/Viewer.js 1660

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

#### resize()
widgets/Source/Viewer/Viewer.js 1542

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

#### zoomTo(target, offset) → Promise.<boolean>
widgets/Source/Viewer/Viewer.js 1991

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 | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud|VoxelPrimitive)> | The entity, array of entities, entity collection, data source, Cesium3DTileset, point cloud, or imagery layer 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 target is not currently visualized in the scene or the zoom was cancelled.

### Type Definitions

#### Cesium.Viewer.ConstructorOptions
widgets/Source/Viewer/Viewer.js 275

Initialization options for the Viewer constructor

##### Properties:

Name | Type | Attributes | 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.
`vrButton` | boolean | <optional> | false | If set to true, the VRButton widget will be created.
`geocoder` | boolean | IonGeocodeProviderType | Array.<GeocoderService> | <optional> | IonGeocodeProviderType.DEFAULT | The geocoding service or services to use when searching with the Geocoder widget. 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 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.
`scene3DOnly` | boolean | <optional> | false | When `true`, each geometry instance will only be rendered in 3D to save GPU memory.
`shouldAnimate` | boolean | <optional> | false | `true` if the clock should attempt to advance simulation time by default, `false` otherwise. This option takes precedence over setting `Viewer#clockViewModel`.
`clockViewModel` | ClockViewModel | <optional> | new ClockViewModel(clock) | The clock view model 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 `baseLayerPicker` is set to true.
`imageryProviderViewModels` | Array.<ProviderViewModel> | <optional> | createDefaultImageryProviderViewModels() | The array of ProviderViewModels to be selectable from the BaseLayerPicker. This value is only valid if `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 `baseLayerPicker` is set to true.
`terrainProviderViewModels` | Array.<ProviderViewModel> | <optional> | createDefaultTerrainProviderViewModels() | The array of ProviderViewModels to be selectable from the BaseLayerPicker. This value is only valid if `baseLayerPicker` is set to true.
`baseLayer` | ImageryLayer | false | <optional> | ImageryLayer.fromWorldImagery() | The bottommost imagery layer applied to the globe. If set to `false`, no imagery provider will be added. This value is only valid if `baseLayerPicker` is set to false. Cannot be used when `globe` is set to false.
`ellipsoid` | Ellipsoid | <optional> | Ellipsoid.default | The default ellipsoid.
`terrainProvider` | TerrainProvider | <optional> | new EllipsoidTerrainProvider() | The terrain provider to use
`terrain` | Terrain | <optional> |  | A terrain object which handles asynchronous terrain provider. Can only specify if options.terrainProvider is undefined.
`skyBox` | SkyBox | false | <optional> |  | The skybox used to render the stars. When `undefined` and the WGS84 ellipsoid used, the default stars are used. If set to `false`, no skyBox, Sun, or Moon will be added.
`skyAtmosphere` | SkyAtmosphere | false | <optional> |  | Blue sky, and the glow around the Earth's limb. Enabled when the WGS84 ellipsoid used. Set to `false` to turn it off.
`fullscreenElement` | Element | string | <optional> | document.body | The element or id to be placed into fullscreen mode when the full screen button is pressed.
`useDefaultRenderLoop` | boolean | <optional> | true | 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 | <optional> | true | If true, this widget will automatically display an HTML panel to the user containing the error, if a render loop error occurs.
`useBrowserRecommendedResolution` | boolean | <optional> | true | If true, render at the browser's recommended resolution and ignore `window.devicePixelRatio`.
`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` | ContextOptions | <optional> |  | Context and WebGL creation properties passed to `Scene`.
`sceneMode` | SceneMode | <optional> | SceneMode.SCENE3D | The initial scene mode.
`mapProjection` | MapProjection | <optional> | new GeographicProjection(options.ellipsoid) | The map projection to use in 2D and Columbus View modes.
`globe` | Globe | false | <optional> | new Globe(options.ellipsoid) | The globe to use in the scene. If set to `false`, no globe will be added and the sky atmosphere will be hidden by default.
`orderIndependentTranslucency` | boolean | <optional> | true | 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.
`creditViewport` | Element | string | <optional> |  | The DOM element or ID that will contain the credit pop up created by the `CreditDisplay`. If not specified, it will appear over the widget itself.
`dataSources` | DataSourceCollection | <optional> | new DataSourceCollection() | 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.
`shadows` | boolean | <optional> | false | Determines if shadows are cast by light sources.
`terrainShadows` | ShadowMode | <optional> | ShadowMode.RECEIVE_ONLY | Determines if the terrain casts or receives shadows from light sources.
`mapMode2D` | MapMode2D | <optional> | MapMode2D.INFINITE_SCROLL | Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
`projectionPicker` | boolean | <optional> | false | If set to true, the ProjectionPicker widget will be created.
`blurActiveElementOnCanvasFocus` | boolean | <optional> | true | If true, the active element will blur when the viewer's canvas is clicked. Setting this to false is useful for cases when the canvas is clicked only for retrieving position or an entity data without actually meaning to set the canvas to be the active element.
`requestRenderMode` | boolean | <optional> | false | If true, rendering a frame will only occur when needed as determined by changes within the scene. Enabling reduces the CPU/GPU usage of your application and uses less battery on mobile, but requires using `Scene#requestRender` to render a new frame explicitly in this mode. This will be necessary in many cases after making changes to the scene in other parts of the API. See Improving Performance with Explicit Rendering.
`maximumRenderTimeChange` | number | <optional> | 0.0 | If requestRenderMode is true, this value defines the maximum change in simulation time allowed before a render is requested. See Improving Performance with Explicit Rendering.
`depthPlaneEllipsoidOffset` | number | <optional> | 0.0 | Adjust the DepthPlane to address rendering artefacts below ellipsoid zero elevation.
`msaaSamples` | number | <optional> | 4 | If provided, this value controls the rate of multisample antialiasing. Typical multisampling rates are 2, 4, and sometimes 8 samples per pixel. Higher sampling rates of MSAA may impact performance in exchange for improved visual quality. This value only applies to WebGL2 contexts that support multisample render targets. Set to 1 to disable MSAA.

#### Cesium.Viewer.ViewerMixin(viewer, options)
widgets/Source/Viewer/Viewer.js 2021

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

Need help? The fastest way to get answers is from the community and team on the Cesium Forum.