Skip to content

KBE3D / KBCore / Cesium / Viewer

类: Viewer

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.

示例

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

参数

The DOM element or ID that will contain the widget.

参数

Object describing initialization options

属性

container

readonly container: Element

Gets the parent container.


creditDisplay

creditDisplay: CreditDisplay

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


bottomContainer

readonly bottomContainer: Element

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


cesiumWidget

readonly cesiumWidget: CesiumWidget

Gets the CesiumWidget.


selectionIndicator

readonly selectionIndicator: SelectionIndicator

Gets the selection indicator.


infoBox

readonly infoBox: InfoBox

Gets the info box.


geocoder

readonly geocoder: Geocoder

Gets the Geocoder.


homeButton

readonly homeButton: HomeButton

Gets the HomeButton.


sceneModePicker

readonly sceneModePicker: SceneModePicker

Gets the SceneModePicker.


projectionPicker

readonly projectionPicker: ProjectionPicker

Gets the ProjectionPicker.


baseLayerPicker

readonly baseLayerPicker: BaseLayerPicker

Gets the BaseLayerPicker.


readonly navigationHelpButton: NavigationHelpButton

Gets the NavigationHelpButton.


animation

readonly animation: Animation

Gets the Animation widget.


timeline

readonly timeline: Timeline

Gets the Timeline widget.


fullscreenButton

readonly fullscreenButton: FullscreenButton

Gets the FullscreenButton.


vrButton

readonly vrButton: VRButton

Gets the VRButton.


dataSourceDisplay

readonly dataSourceDisplay: DataSourceDisplay

Gets the display used for DataSource visualization.


entities

readonly entities: EntityCollection

Gets the collection of entities not tied to a particular data source. This is a shortcut to [dataSourceDisplay.defaultDataSource.entities]Viewer#dataSourceDisplay.


dataSources

readonly dataSources: DataSourceCollection

Gets the set of DataSource instances to be visualized.


canvas

readonly canvas: HTMLCanvasElement

Gets the canvas.


scene

readonly scene: Scene

Gets the scene.


shadows

shadows: boolean

Determines if shadows are cast by light sources.


terrainShadows

terrainShadows: ShadowMode

Determines if the terrain casts or shadows from light sources.


shadowMap

readonly shadowMap: ShadowMap

Get the scene's shadow map


imageryLayers

readonly imageryLayers: ImageryLayerCollection

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


terrainProvider

terrainProvider: TerrainProvider

The terrain provider providing surface geometry for the globe.


camera

readonly camera: Camera

Gets the camera.


ellipsoid

readonly ellipsoid: Ellipsoid

Gets the default ellipsoid for the scene.


postProcessStages

readonly postProcessStages: PostProcessStageCollection

Gets the post-process stages.


clock

readonly clock: Clock

Gets the clock.


clockViewModel

readonly clockViewModel: ClockViewModel

Gets the clock view model.


screenSpaceEventHandler

readonly screenSpaceEventHandler: ScreenSpaceEventHandler

Gets the screen space event handler.


targetFrameRate

targetFrameRate: number

Gets or sets the target frame rate of the widget when <code>useDefaultRenderLoop</code> 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.


useDefaultRenderLoop

useDefaultRenderLoop: boolean

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 <code>resize</code>, <code>render</code> methods as part of a custom render loop. If an error occurs during rendering, Scene's <code>renderError</code> 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.


resolutionScale

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.


useBrowserRecommendedResolution

useBrowserRecommendedResolution: boolean

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.


allowDataSourcesToSuspendAnimation

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.


trackedEntity

trackedEntity: Entity | undefined

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


selectedEntity

selectedEntity: Entity | undefined

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.


selectedEntityChanged

readonly selectedEntityChanged: Event

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


trackedEntityChanged

readonly trackedEntityChanged: Event

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


clockTrackedDataSource

clockTrackedDataSource: DataSource

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

方法

extend()

extend(mixin: ViewerMixin, options?: any): void

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

参数

mixin

ViewerMixin

The Viewer mixin to add to this instance.

options?

any

The options object to be passed to the mixin function.

返回

void


resize()

resize(): void

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

返回

void


forceResize()

forceResize(): void

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

返回

void


render()

render(): void

Renders the scene. This function is called automatically unless <code>useDefaultRenderLoop</code> is set to false;

返回

void


isDestroyed()

isDestroyed(): boolean

返回

boolean

true if the object has been destroyed, false otherwise.


destroy()

destroy(): void

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

返回

void


zoomTo()

zoomTo(target: Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | Promise<Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | VoxelPrimitive>, offset?: HeadingPitchRange): 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.

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

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

参数

target

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.

Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | Promise<Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | VoxelPrimitive>

offset?

HeadingPitchRange

The offset from the center of the entity in the local east-north-up reference frame.

返回

Promise<boolean>

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.


flyTo()

flyTo(target: Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | Promise<Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | VoxelPrimitive>, options?: { duration?: number; maximumHeight?: number; offset?: HeadingPitchRange; }): 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.

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

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

参数

target

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.

Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | Promise<Entity | DataSource | EntityCollection | Entity[] | Cesium3DTileset | ImageryLayer | TimeDynamicPointCloud | VoxelPrimitive>

options?

Object with the following properties:

duration?

number

The duration of the flight in seconds.

maximumHeight?

number

The maximum height at the peak of the flight.

offset?

HeadingPitchRange

The offset from the target in the local east-north-up reference frame centered at the target.

返回

Promise<boolean>

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

构造函数

构造函数

new Viewer(container: string | Element, options?: ConstructorOptions): Viewer

参数

container

string | Element

options?

ConstructorOptions

返回

Viewer

KBE3D @3.0.0 Copyright © 2024-present KBE3D