new Viewer(container)
Viewer is the fundamental component used to build applications, which combines all standard Cesium components into a reusable package. Viewer widgets can often be extended using mixins to add useful functionality for various applications.
| Name | Type | Default | Description |
|---|---|---|---|
container |
Element | String |
Specify the Document Object Model (DOM) or ID of the HTML element that accommodates the viewer component. |
|
options.clock |
Clock | new Clock() |
optional
The clock used to control the current time. |
options.selectedImageryProviderViewModel |
ProviderViewModel |
optional
If the view model of the current base image layer is not provided, the first available base layer will be used. This value is only valid when options.baseLayerPicker is set to true. |
|
options.imageryProviderViewModels |
Array.<ProviderViewModel> | createDefaultImageryProviderViewModels() |
optional
The ExtendeViewModels array can be selected from BaseLayerPicker. This value is only valid when options.baseLayerPicker is set to true. |
options.selectedTerrainProviderViewModel |
ProviderViewModel |
optional
If the view model of the current basic terrain layer is not provided, the first available basic layer will be used. This value is only valid when options.baseLayerPicker is set to true. |
|
options.terrainProviderViewModels |
Array.<ProviderViewModel> | createDefaultTerrainProviderViewModels() |
optional
The ExtendeViewModels array can be selected from BaseLayerPicker. This value is only valid when options.baseLayerPicker is set to true. |
options.imageryProvider |
ImageryProvider | new BingMapsImageryProvider() |
optional
The image provider used. This value is only valid when options.baseLayerPicker is set to false. |
options.terrainProvider |
TerrainProvider | new EllipsoidTerrainProvider() |
optional
The terrain provider used. |
options.skyBox |
SkyBox |
optional
The sky box used to render stars, when undefined, uses the default star effect. |
|
options.skyAtmosphere |
SkyAtmosphere |
optional
The blue sky and halo effect surrounding the edge of the Earth can be turned off by setting it to false. |
|
options.useDefaultRenderLoop |
Boolean | true |
optional
If this component can control the rendering loop, set it to true, otherwise set it to false. |
options.targetFrameRate |
Number |
optional
The target frame rate when using the default rendering loop. |
|
options.showRenderLoopErrors |
Boolean | true |
optional
If set to true, an HTML panel containing error information will be automatically displayed to the user when a rendering loop error occurs. |
options.automaticallyTrackDataSourceClocks |
Boolean | true |
optional
If set to true, the clock settings of newly added data sources will be automatically tracked and updated if the clock of the data source changes. If you need to set the clock separately, please set this option to false. |
options.contextOptions |
ContextType |
optional
Context and WebGL create attributes and pass them to Scene matching options. Add hardware anti aliasing function, the anti aliasing coefficient msalevel uses integer values from 1 to 8 (1, 2, 4, 8 when selecting WebGL2.0, and 1, 4 when selecting WebGPU), with a default value of 1. The larger the value, the better the anti aliasing effect (because WebGL2.0 features are used, so the requestWebgl2 parameter is set to true). |
|
options.mapProjection |
MapProjection | new GeographicProjection() |
optional
Map projection used in 2D and Columbus view modes. |
options.globe |
Globe | new Globe(mapProjection.ellipsoid) |
optional
If this option is set to false for the Earth in the scene, no spherical object will be added. |
options.orderIndependentTranslucency |
Boolean | true |
optional
If this option is set to true and supported by the device, order independent semi transparency will be used. |
options.creditContainer |
Element | String |
optional
Specify the DOM element or ID that contains CreditDisplay information. If not specified, credit information will be added to the bottom of the component. |
|
options.dataSources |
DataSourceCollection | new DataSourceCollection() |
optional
Specify the collection of data sources to be visualized by the viewer component. If this parameter is provided, the instance will be owned by the caller and will not be destroyed when the viewer is destroyed. |
options.terrainExaggeration |
Number | 1.0 |
optional
A scalar used to exaggerate terrain. Please note that setting terrain exaggeration will not modify any other data. |
options.shadows |
Boolean | false |
optional
Whether to enable shadows. |
options.terrainShadows |
ShadowMode | ShadowMode.RECEIVE_ONLY |
optional
Determine whether the terrain casts or receives shadows from the sun. |
options.mapMode2D |
MapMode2D | MapMode2D.INFINITE_SCROLL |
optional
Determine whether the two-dimensional map is rotatable or can scroll infinitely in the horizontal direction. |
options.navigation |
Boolean | true |
optional
Whether to display the navigation compass control, default display. To hide, please set this option to false. |
options.PerformancePreferenceMode |
PerformancePreferenceMode |
optional
Performance preference mode allows for setting performance or effect priority when loading various types of data. |
- See:
Throws:
-
-
There is no 'container' element with this identifier in the document.
- Type
- DeveloperError
-
-
-
When using the BaseLayerPicker widget, options.imageryProvider is not available. Please change it to specify options.selectedImageryLayoutVNet.
- Type
- DeveloperError
-
-
-
When using the BaseLayerPicker component, options.trrainProvider is not available. Please change to specifying options.selelectedRrrainLayoutVNet.
- Type
- DeveloperError
-
-
-
When using the BaseLayerPicker component, the options.selectedImageryLayoutVNet are not available. Please change to specifying options.imageryProvider.
- Type
- DeveloperError
-
-
-
When using the BaseLayerPicker component, the options.selectedTerrainDataModel is not available. Please change it to specify options.trrainProvider.
- Type
- DeveloperError
-
Example
// Initialize the viewer widget
var viewer = new SuperMap3D.Viewer('Container', {
// Use STK World Terrain
terrainProvider : new SuperMap3D.SuperMapTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/world'
}),
// Use OpenStreetMaps
imageryProvider : SuperMap3D.createOpenStreetMapImageryProvider({
url : 'https://a.tile.openstreetmap.org/'
}),
});
// Add basic drag-and-drop functionality
viewer.extend(SuperMap3D.viewerDragDropMixin);
// Handle errors when deleting files and show a pop-up warning.
viewer.dropError.addEventListener(function(dropHandler, name, error) {
console.log(error);
window.alert(error);
});
Members
-
_connectWithViewerContextType
-
Use version when setting or getting initialization, default to WebGL2
Example
如设置使用版本为WebGL2 var viewer = new SuperMap3D.Viewer('Container', { contextOptions:{ contextType:SuperMap3D.ContextType.WebGL1 } }); -
allowDataSourcesToSuspendAnimationBoolean
-
Can the data source temporarily pause the animation to avoid displaying incomplete images to the user. For example, if the backend is processing asynchronous functions, the clock will not move forward until the geometry is ready.
-
readonly animationAnimation
-
Obtain animation components.
-
readonly baseLayerPickerBaseLayerPicker
-
Get the BaseLayerPicker object.
-
readonly bottomContainerElement
-
Retrieve DOM elements at the bottom of the window that contain CreditDisplay and other potential information.
-
readonly cameraCamera
-
Retrieve the camera object.
-
readonly canvasCanvas
-
Retrieve the canvas object.
-
readonly cesiumLogoElement
-
Obtain the logo elements of Cesium.
-
readonly clockClock
-
Retrieve the clock object.
-
clockTrackedDataSourceDataSource
-
Get or set the data source for tracking the viewer clock.
-
readonly clockViewModelClockViewModel
-
Obtain the clock view model.
-
readonly containerElement
-
Retrieve the parent container.
-
readonly dataSourceDisplayDataSourceDisplay
-
Get the display for the Data Source.
-
readonly dataSourcesDataSourceCollection
-
Get or set the collection of DataSource instances that will be visualized.
-
readonly entitiesEntityCollection
-
Retrieve a collection of entities that are independent of a specific data source. This is a shortcut to access dataSourceDisplay. defaultDataSource.Entities.
-
readonly fullscreenButton
-
Retrieve the FullscreenButton object.
-
readonly geocoderGeocoder
-
Retrieve the Geoencoder object.
-
readonly homeButton
-
Retrieve the HomeButton object.
-
readonly imageryLayersImageryLayerCollection
-
Get the collection of image layers to be rendered on Earth.
-
readonly navigationHelpButton
-
Retrieve the NavigationHelpButton object.
-
readonly postProcessStagesPostProcessStageCollection
-
Obtain post-processing stage.
-
readonly projectionPickerProjectionPicker
-
Obtain the projection picker.
-
resolutionScaleNumber
-
Get or set the scaling factor for rendering resolution. When the value is less than 1.0, it can improve performance on less powerful devices; On the contrary, when the value is greater than 1.0, it will be rendered at a higher resolution and then scaled down proportionally to improve visual fidelity. For example, if the widget is set to a size of 640x480 and this attribute is set to 0.5, it will cause the scene to be rendered at a resolution of 320x240 and scaled up proportionally, while setting it to 2.0 will cause the scene to be rendered at 1280x960 and scaled down proportionally.
- Default Value: 1.0
readonly sceneScene
Retrieve scene objects.
readonly sceneModePickerSceneModePicker
Retrieve the SceneModePicker object.
readonly screenSpaceEventHandlerScreenSpaceEventHandler
Get the screen space event handler.
selectedEntityEntity
Get or set the object instance that displays the selection indicator.
readonly selectedEntityChangedEvent
Get the event triggered when the selected entity object changes.
readonly selectionIndicatorSelectionIndicator
Retrieve the SelectionIndicator object.
readonly shadowMapShadowMap
Obtain the shadow map of the scene.
shadowsBoolean
Get or set shadow effects.
targetFrameRateNumber
When useDefaultRenderLoop is set to true, it retrieves or sets the target frame rate of the component. If this property is not defined, the frame rate is determined by the browser's requestAnimationFrame implementation; If this property has already been defined, the value should be greater than 0, and values greater than the underlying requestAnimationFrame will have no effect.
terrainProviderTerrainProvider
TerrainProvider object that provides surface geometry for the Earth.
terrainShadowsShadowMode
Determine whether the terrain casts or receives shadows from the sun.
readonly timelineTimeline
Retrieve the Timeline component.
trackedEntityEntity
Get or set the entity instance currently tracked by the camera.
readonly trackedEntityChangedEvent
Retrieve events triggered when tracking changes in physical objects.
useDefaultRenderLoopBoolean
Gets or sets whether the component can control the rendering loop. When set to true, the component will use requestAnimationFrame to perform rendering, resize the component, and drive clock simulation; When set to false, the render and resize methods must be manually called as part of the custom loop rendering. If an error occurs during rendering, the renderError event of the Scene will be triggered, and this property will be changed to false. After the error occurs, this property must be changed back to true to continue rendering.
readonly vrButton
Get VRButton object.
readonly webSceneWebScene
Retrieve the webscene object of the current scene
readonly Widget
Retrieve the Widget object.
Methods
-
destroy()
-
Release the resources occupied by the object.
-
extend(mixin, options)
-
Use the provided mixin to extend the basic viewer functionality. Mixins can add additional properties, functionalities, or other behaviors to the provided viewer instance.
Name Type Description mixinViewer~ViewerMixin Specify the Viewer mixin object to be added to the instance.
optionsObject optional Specify the options object passed to the mixin function.
- See:
-
flyTo(target){Promise.<Boolean>}
-
The camera flies towards the designated entity, entity set, or data source. If the data source is still loading or the visualization is still in progress, this method needs to wait for the data to be ready before executing the flight.
The offset variable is represented by the "azimuth/elevation/range" in the local "northeast up" reference frame (with the center point being the center of the enclosing sphere). The angles of azimuth and elevation are defined in the local "East North Up" reference frame. The azimuth heading is the angle value that starts from the y-axis and increases towards the x-axis. Pitch is the rotational angle starting from the xy plane, where a positive pitch indicates being above the plane and a negative pitch indicates being below the plane. The distance range represents the distance from the center point. If the range is 0, a range will be calculated to make the entire enclosing sphere visible.
There must be a top-down view in two dimensions. The camera is located above the overhead target. Range is the height above the target; The heading is determined by the offset, and if the azimuth cannot be determined based on the offset, the heading is in the north direction.
Name Type Default Description targetEntity | Array.<Entity> | EntityCollection | DataSource | ImageryLayer | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer)> Specify the entity, entity set, data source, or image layer to view. You can also specify a promise to resolve one of the aforementioned types.
options.durationNumber 3.0 optional Flight duration (in seconds).
options.maximumHeightNumber optional The maximum altitude during flight.
options.offsetHeadingPitchRange optional The offset from the target in the local "East North Up" reference frame centered on the target.
Returns:
Type Description Promise.<Boolean> When the flight is successful, the promise is parsed as true; If the entity is not visualized in the scene or the flight is cancelled, the promise is parsed as false. -
forceResize()
-
Forcefully readjust, causing the components to reconsider layout including component size, credit placement, etc.
-
isDestroyed(){Boolean}
-
Return whether to release the resources occupied by the object.
Returns:
Type Description Boolean True indicates that the occupied resources have been released, otherwise return false. -
render()
-
Rendering the scene. Unless useDefaultRenderLoop is set to false, this function will be automatically called.
-
resize()
-
Adjust the size of the components to match the container. This function will be automatically called as needed, unless useDefaultRenderLoop is set to false.
-
zoomTo(target, offset){Promise.<Boolean>}
-
Asynchronous camera setup to view specified entities, entity sets, or data sources. If the data source is still loading or visualization is still in progress, this method needs to wait for the data to be ready before performing scaling.
The offset variable is represented by the "azimuth/elevation/range" in the local "northeast up" reference frame (with the center point being the center of the enclosing sphere). The angles of azimuth and elevation are defined in the local "East North Up" reference frame. The azimuth heading is the angle value that starts from the y-axis and increases towards the x-axis. Pitch is the rotational angle starting from the xy plane, where a positive pitch indicates being above the plane and a negative pitch indicates being below the plane. The distance range represents the distance from the center point. If the range is 0, a range will be calculated to make the entire enclosing sphere visible.
There must be a top-down view in two dimensions. The camera is located above the overhead target. Range is the height above the target; The heading is determined by the offset, otherwise the azimuth cannot be determined based on the offset. The heading is in the north direction.
Name Type Description targetEntity | Array.<Entity> | EntityCollection | DataSource | ImageryLayer | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer)> Specify the entity, entity set, data source, or image layer to view. You can also specify a promise to resolve one of the aforementioned types.
offsetHeadingPitchRange optional Specify the offset from the center of the local "East North Up" reference frame.
Returns:
Type Description Promise.<Boolean> When scaling is successful, the promise is parsed as true; If the entity is not visualized or scaled in the scene, the promise is parsed as false.
Type Definitions
-
ViewerMixin(viewer, options)
-
Add functions for Viewer instances with additional features.
Name Type Description viewerViewer Viewer instance object.
optionsObject The options object passed to the mixin function.
- See: