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
Configuration options for the widget.
|
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:
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.
-
animation :Animation
-
Gets the Animation widget.
-
baseLayerPicker :BaseLayerPicker
-
Gets the BaseLayerPicker.
-
canvas :Canvas
-
Gets the canvas.
-
cesiumLogo :Element
-
Gets the Cesium logo element.
-
cesiumWidget :CesiumWidget
-
Gets the CesiumWidget.
-
clock :Clock
-
Gets the clock.
-
clockTrackedDataSource :DataSource
-
Gets or sets the data source to track with the viewer's clock.
-
container :Element
-
Gets the parent container.
-
dataSourceDisplay :DataSourceDisplay
-
Gets the display used for
DataSource
visualization. -
dataSources :DataSourceCollection
-
Gets the set of
DataSource
instances to be visualized. -
fullscreenButton :FullscreenButton
-
Gets the FullscreenButton.
-
geocoder :Geocoder
-
Gets the Geocoder.
-
homeButton :HomeButton
-
Gets the HomeButton.
-
infoBox :InfoBox
-
Gets the info box.
-
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
-
scene :Scene
-
Gets the scene.
-
sceneModePicker :SceneModePicker
-
Gets the SceneModePicker.
-
screenSpaceEventHandler :ScreenSpaceEventHandler
-
Gets the screen space event handler.
-
selectionIndicator :SelectionIndicator
-
Gets the selection indicator.
-
targetFrameRate :Number
-
Gets or sets the target frame rate of the widget when
useDefaultRenderLoop
is true. If undefined, the browser'srequestAnimationFrame
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. -
timeline :Timeline
-
Gets the Timeline widget.
-
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 theresize
,render
methods as part of a custom render loop. If an error occurs during rendering,Scene
'srenderError
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.
Methods
-
destroy()
-
Destroys the widget. Should be called if permanently removing the widget from layout.
-
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
function The Viewer mixin to add to this instance. options
Object The options object to be passed to the mixin function. -
isDestroyed() → Boolean
-
Returns:
true if the object has been destroyed, false otherwise. -
render()
-
Renders the scene. This function is called automatically unless
useDefaultRenderLoop
is set to false; -
resize()
-
Resizes the widget to match the container size. This function is called automatically as needed unless
useDefaultRenderLoop
is set to false.