Cesium 事件详解(鼠标事件、相机事件、键盘事件、场景触发事件)

Cesium 事件详解(鼠标事件、相机事件、键盘事件、场景触发事件)

1 Cesium中的事件

根据使用情况,我把Cesium中的事件大体分为三种,即屏幕空间事件处理程序,屏幕空间相机控制器,场景触发事件。以下逐个解释,建议收藏。

1.1 屏幕空间事件处理程序(Screen Space Event Handler)

屏幕空间事件处理程序,对应API中的 Cesium.ScreenSpaceEventHandler 。官方解释是,处理用户输入事件,可以添加自定义函数,以便在用户输入时执行。可以理解为我们常说的鼠标事件(或键盘事件),是与鼠标和键盘输入相关的事件处理程序。
使用时,我们需要先对 ScreenSpaceEventHandler 类进行实例化,再注册事件或注销事件。

1.1.1 屏幕空间事件类型:(ScreenSpaceEventType)
名称描述
LEFT_DOWNRepresents a mouse left button down event.表示鼠标左键按下事件。
LEFT_UPRepresents a mouse left button up event.表示鼠标左键弹起事件。
LEFT_CLICKRepresents a mouse left click event.表示鼠标左键点击事件。
LEFT_DOUBLE_CLICKRepresents a mouse left double click event.表示鼠标左键双击事件。
RIGHT_DOWNRepresents a mouse left button down event.表示鼠标右键按下事件。
RIGHT_UPRepresents a mouse right button up event.表示鼠标右键弹起事件。
RIGHT_CLICKRepresents a mouse right click event.表示鼠标右键单击事件。
MIDDLE_DOWNRepresents a mouse middle button down event.表示鼠标中键按下事件。
MIDDLE_UPRepresents a mouse middle button up event.表示鼠标中键弹起事件。
MIDDLE_CLICKRepresents a mouse middle click event.表示鼠标中键点击事件。
MOUSE_MOVERepresents a mouse move event.表示鼠标移动事件。
WHEELRepresents a mouse wheel event.表示鼠标滚轮滚动事件。
PINCH_STARTRepresents the start of a two-finger event on a touch surface.表示触控屏上双指开始事件。
PINCH_ENDRepresents the end of a two-finger event on a touch surface.表示触控屏上双指结束事件。
PINCH_MOVERepresents a change of a two-finger event on a touch surface.表示触控屏上双指移动事件。
1.1.2 键盘修饰符类型(KeyboardEventModifier)
名称描述
SHIFTRepresents the shift key being held down.表示shift键被按住。
CTRLRepresents the control key being held down.表示ctrl键被按住。
ALTRepresents the alt key being held down.表示alt键被按住。

*键盘修饰符不可以单独使用,需要配合鼠标输入事件使用。

1.1.3 代码示例
// 绑定屏幕空间事件
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(event){
    console.log('shift + 左键单击', event.position);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK, Cesium.KeyboardEventModifier.SHIFT);
// 移除屏幕空间事件
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK, Cesium.KeyboardEventModifier.SHIFT);

1.2 屏幕空间相机控制器(Screen Space Camera Controller)

根据在画布上的鼠标输入修改摄像机的位置和方向。可以理解为我们常说的相机事件,是与相机控制相关的事件处理程序。
Cesium在 Viewer 类的实例化过程中,也实例化了其他很多类,其中就包括 ScreenSpaceCameraController 类,并把实例化结果赋给了 viewer.scene.screenSpaceCameraController ,所以我们在使用时可以直接操作 viewer.scene.screenSpaceCameraController
另外,我们可以更改默认操作模式。

1.2.1 相机事件类型(CameraEventType)
名称描述
LEFT_DRAGA left mouse button press followed by moving the mouse and releasing the button.鼠标左键按住,然后移动鼠标并松开按键。
RIGHT_DRAGA right mouse button press followed by moving the mouse and releasing the button.鼠标右键按住,然后移动鼠标并松开按键。
MIDDLE_DRAGA middle mouse button press followed by moving the mouse and releasing the button.鼠标中键按住,然后移动鼠标并松开按键。
WHEELScrolling the middle mouse button.滚动鼠标中键滚轮。
PINCHA two-finger touch on a touch surface.双指触控屏幕。
1.2.2 默认操作模式
操作3D视图2.5D视图2D视图
LEFT_DRAG绕地球旋转地图上平移地图上平移
RIGHT_DRAG地图缩放地图缩放地图缩放
MIDDLE_DRAG倾斜地球倾斜地图
WHEEL地图缩放地图缩放地图缩放
PINCH倾斜地球倾斜地图
CTRL + LEFT_DRAG倾斜地球倾斜地图
CTRL + RIGHT_DRAG倾斜地球倾斜地图
1.2.3 修改默认操作模式

如果需要改变默认操作模式,可以在初始化地球之后,通过改变 ScreenSpaceCameraController 的几个属性来实现。

属性名属性描述
lookEventTypes3D视图、2.5D视图改变相机观察方向
rotateEventTypes3D视图相机绕地球旋转
tiltEventTypes3D视图、2.5D视图倾斜视角
translateEventTypes2.5D视图、2D视图地图上平移
zoomEventTypes地图缩放

示例:

viewer.scene.screenSpaceCameraController.tiltEventTypes = [
    Cesium.CameraEventType.RIGHT_DRAG,
    Cesium.CameraEventType.PINCH,
    {
        eventType: Cesium.CameraEventType.LEFT_DRAG,
        modifier: Cesium.KeyboardEventModifier.CTRL,
    },
    {
        eventType: Cesium.CameraEventType.RIGHT_DRAG,
        modifier: Cesium.KeyboardEventModifier.CTRL,
    },
];
viewer.scene.screenSpaceCameraController.zoomEventTypes = [
    Cesium.CameraEventType.MIDDLE_DRAG,
    Cesium.CameraEventType.WHEEL,
    Cesium.CameraEventType.PINCH,
];

1.3 场景触发事件

场景中一些变化触发的监听事件,随着Cesium中一些对象实例化而产生的事件。
常用的场景触发事件有:

  • Camera.changed:相机发生变化时触发
  • Camera.moveEnd:相机停止移动时触发
  • Camera.moveStart:相机开始移动时触发
  • Scene.preUpdate:场景更新之前触发
  • Scene.postUpdate:场景更新之后立即触发
  • Scene.preRender:场景更新之后渲染之前触发
  • Scene.postRender:场景渲染之后触发
  • Scene.terrainProviderChanged:地形提供器发生变化时触发
  • Viewer.trackedEntityChanged:entity的属性发生变化时触发
  • Cesium3DTileset.allTilesLoaded:所有3dtiles数据加载完成以后触发
  • Cesium3DTileset.loadProgress:3dtiles初始化加载过程中触发
  • Cesium3DTileset.tileFailed:3dtiles瓦片加载失败时触发
  • Globe.imageryLayersUpdatedEvent:地球加载图层更新时触发

另外,我已经将官方API中几乎所有触发事件整理到下面,请自行查看。
示例:

// 需要回调的函数 
function callbackFunc(event){
    cosnole.log(event)
}
// 渲染之前执行
viewer.scene.preRender.addEventListener(callbackFunc);
viewer.scene.preRender.removeEventListener(callbackFunc);

// 更新之前执行
viewer.scene.preUpdate.addEventListener(callbackFunc);
viewer.scene.preUpdate.removeEventListener(callbackFunc);

// 实时渲染执行
viewer.scene.postRender.addEventListener(callbackFunc);
viewer.scene.postRender.removeEventListener(callbackFunc);

// 实时更新执行
viewer.scene.postUpdate.addEventListener(callbackFunc);
viewer.scene.postUpdate.removeEventListener(callbackFunc);

2 Cesium API 中的场景触发事件

2.1 属性:Camera-changed(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised when the camera has changed by percentageChanged.
【中文翻译】
获取当相机(camera)被 percentageChanged 改变时触发的事件。简言之,就是当相机发生变化时触发的事件。

2.2 属性:Camera-moveStart(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised at when the camera starts to move.
【中文翻译】
获取当相机(camera)开始移动时被触发的事件。

2.3 属性:Camera-moveEnd(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised when the camera has stopped moving.
【中文翻译】
获取当相机(camera)停止移动时被触发的事件。

2.4 属性:Cesium3DTileset-allTilesLoaded(常用)

【类型】
Event
【官方解释】
The event fired to indicate that all tiles that meet the screen space error this frame are loaded. The tileset is completely loaded for this view.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
此事件触发以指示此帧的所有满足屏幕空间误差的瓦片已加载完毕。此视图的瓦片集(tileset)已完全加载。
此事件在场景渲染后的帧末尾触发。
示例:

tileset.allTilesLoaded.addEventListener(function() {
    console.log('All tiles are loaded');
});

2.5 属性:Cesium3DTileset-initialTilesLoaded(常用)

【类型】
Event
【官方解释】
The event fired to indicate that all tiles that meet the screen space error this frame are loaded. This event is fired once when all tiles in the initial view are loaded.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
此事件触发以指示此帧的所有满足屏幕空间误差的瓦片已加载完毕。一旦初始视图加载完成,此事件就被触发。
此事件在场景渲染后的帧末尾触发。
示例:

tileset.initialTilesLoaded.addEventListener(function() {
    console.log('Initial tiles are loaded');
});

2.6 属性:Cesium3DTileset-loadProgress(常用)

【类型】
Event
【官方解释】
The event fired to indicate progress of loading new tiles. This event is fired when a new tile is requested, when a requested tile is finished downloading, and when a downloaded tile has been processed and is ready to render.
The number of pending tile requests, numberOfPendingRequests, and number of tiles processing, numberOfTilesProcessing are passed to the event listener.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
此事件触发以指示加载新瓦片(tiles)的进度。此事件在请求新瓦片时,请求的瓦片结束下载时,下载好的瓦片处理完成时和瓦片准备好要渲染时触发。
挂起的瓦片请求数量(numberOfPendingRequests)和处理中的瓦片数量(numberOfTilesProcessing)被传递给事件监听器。
此事件在场景渲染后的帧末尾触发。
示例:

tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberOfTilesProcessing) {
    if ((numberOfPendingRequests === 0) && (numberOfTilesProcessing === 0)) {
        console.log('Stopped loading');
        return;
    }

    console.log('Loading: requests: ' + numberOfPendingRequests + ', processing: ' + numberOfTilesProcessing);
});

2.7 属性:Cesium3DTileset-tileFailed(常用)

【类型】
Event
【官方解释】
The event fired to indicate that a tile’s content failed to load.
If there are no event listeners, error messages will be logged to the console.
The error object passed to the listener contains two properties:
url: the url of the failed tile.
message: the error message.
If the 3DTILES_multiple_contents extension is used, this event is raised once per inner content with errors.
【中文翻译】
此事件触发以指示一个瓦片内容加载失败。如果没有事件监听器,控制台会打印错误消息。传递给事件监听器的错误对象包含两个属性:
url:加载失败的瓦片的url链接地址。
message:错误消息。
如果使用3DTILES_multiple_contents扩展名,则每个内部报错的内容都会触发此事件。
示例:

tileset.tileFailed.addEventListener(function(error) {
    console.log('An error occurred loading tile: ' + error.url);
    console.log('Error: ' + error.message);
});

2.8 属性:Cesium3DTileset-tileLoad(常用)

【类型】
Event
【官方解释】
The event fired to indicate that a tile’s content was loaded.
The loaded Cesium3DTile is passed to the event listener.
This event is fired during the tileset traversal while the frame is being rendered so that updates to the tile take effect in the same frame. Do not create or modify Cesium entities or primitives during the event listener.
【中文翻译】
此事件触发以指示一个瓦片内容已加载。
已加载的Cesium3D瓦片传递给了事件监听器。
在渲染帧时,此事件在遍历瓦片集(tileset)期间被触发,以便对瓦片的更新在同一帧生效。不要在事件监听器期间创建或修改Cesium实体(entity)或原始对象(primitives)。
示例:

tileset.tileLoad.addEventListener(function(tile) {
    console.log('A tile was loaded.');
});

2.9 属性:Cesium3DTileset-tileUnload(常用)

【类型】
Event
【官方解释】
The event fired to indicate that a tile’s content was unloaded.
The unloaded Cesium3DTile is passed to the event listener.
This event is fired immediately before the tile’s content is unloaded while the frame is being rendered so that the event listener has access to the tile’s content. Do not create or modify Cesium entities or primitives during the event listener.
【中文翻译】
此事件触发以指示一个瓦片内容已卸载。
已卸载的Cesium3D瓦片传递给了事件监听器。
在渲染帧时,此事件在瓦片内容被卸载前立即触发,以便事件监听器能够访问瓦片内容(tile’s content)。不要在事件监听器期间创建或修改Cesium实体(entity)或原始对象(primitives)。
示例:

tileset.tileUnload.addEventListener(function(tile) {
    console.log('A tile was unloaded from the cache.');
});

2.10 属性:Cesium3DTileset-tileVisible(常用)

【类型】
Event
【官方解释】
This event fires once for each visible tile in a frame. This can be used to manually style a tileset.
The visible Cesium3DTile is passed to the event listener.
This event is fired during the tileset traversal while the frame is being rendered so that updates to the tile take effect in the same frame. Do not create or modify Cesium entities or primitives during the event listener.
【中文翻译】
此事件为帧中的每一个可见瓦片都触发一次。这可以用于手动设置瓦片集(tileset)的样式。
可见Cesium3D瓦片传递给了事件监听器。
在渲染帧时,此事件在遍历瓦片集(tileset)期间被触发,以便对瓦片的更新在同一帧生效。不要在事件监听器期间创建或修改Cesium实体(entity)或原始对象(primitives)。
示例:

tileset.tileVisible.addEventListener(function(tile) {
    if (tile.content instanceof Cesium.Batched3DModel3DTileContent) {
        console.log('A Batched 3D Model tile is visible.');
    }
});
// Apply a red style and then manually set random colors for every other feature when the tile becomes visible.
tileset.style = new Cesium.Cesium3DTileStyle({
    color : 'color("red")'
});
tileset.tileVisible.addEventListener(function(tile) {
    var content = tile.content;
    var featuresLength = content.featuresLength;
    for (var i = 0; i < featuresLength; i+=2) {
        content.getFeature(i).color = Cesium.Color.fromRandom();
    }
});

2.11 属性:Clock-onStop

【类型】
Event
【官方解释】
An Event that is fired whenever Clock#stopTime is reached.
【中文翻译】
当时间到达 Clock#stopTime 时触发的事件。

2.12 属性:Clock-onTick

【类型】
Event
【官方解释】
An Event that is fired whenever Clock#tick is called.
【中文翻译】
Clock#tick 函数被调用时触发的事件。Viewer初始化时会绑定clock.onTick事件,确保每一帧都会调用。

2.13 属性:DataSource-changedEvent

【类型】
Event
【官方解释】
Gets an event that will be raised when the underlying data changes.
【中文翻译】
获取在底层数据更改时触发的事件。

2.14 属性:DataSource-errorEvent

【类型】
Event
【官方解释】
Gets an event that will be raised if an error is encountered during processing.
【中文翻译】
获取在处理过程中遇到错误时触发的事件。

2.15 属性:DataSource-loadingEvent

【类型】
Event
【官方解释】
Gets an event that will be raised when the value of isLoading changes.
【中文翻译】
获取在 isLoading 值发生变化时触发的事件。

2.16 属性:DataSourceClock-definitionChanged(只读)

【类型】
Event
【官方解释】
Gets the event that is raised whenever a new property is assigned.
【中文翻译】
获取每当分配新属性时触发的事件。

2.17 属性:DataSourceCollection-dataSourceAdded(只读)

【类型】
Event
【官方解释】
An event that is raised when a data source is added to the collection. Event handlers are passed the data source that was added.
【中文翻译】
获取当添加一个数据源(data source)到集合中时触发的事件。被添加的数据源传递给里事件处理程序。

2.18 属性:DataSourceCollection-dataSourceMoved(只读)

【类型】
Event
【官方解释】
An event that is raised when a data source changes position in the collection. Event handlers are passed the data source that was moved, its new index after the move, and its old index prior to the move.
【中文翻译】
获取当改变一个数据源(data source)的位置时触发的事件。被移动的数据源,移动后的新索引(index)和移动前的旧索引传递给里事件处理程序。

2.19 属性:DataSourceCollection-dataSourceRemoved(只读)

【类型】
Event
【官方解释】
An event that is raised when a data source is removed from the collection. Event handlers are passed the data source that was removed.
【中文翻译】
获取当移除一个数据源(data source)到集合中时触发的事件。被移除的数据源传递给里事件处理程序。

2.20 属性:Entity-definitionChanged(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that is raised whenever a property or sub-property is changed or modified.
【中文翻译】
获取每当更改或修改属性或子属性时触发的事件。

2.21 属性:EntityCluster-clusterEvent

【类型】
Event
【官方解释】
Gets the event that will be raised when a new cluster will be displayed. The signature of the event listener is EntityCluster.newClusterCallback.
【中文翻译】
获取当一个新的集群要显示时触发的事件。事件监听器的签名是 EntityCluster.newClusterCallback

2.22 属性:EntityCollection-collectionChanged(只读)

【类型】
Event
【官方解释】
Gets the event that is fired when entities are added or removed from the collection. The generated event is a EntityCollection.collectionChangedEventCallback.
【中文翻译】
获取在从集合中添加或删除实体时触发的事件。生成的事件是一个 EntityCollection.collectionChangedEventCallback

2.23 属性:FrameRateMonitor-lowFrameRate

【类型】
Event
【官方解释】
Gets the event that is raised when a low frame rate is detected. The function will be passed the Scene instance as its first parameter and the average number of frames per second over the sampling window as its second parameter.
【中文翻译】
获取检测到低帧速率时触发的事件。函数接收到的第一个参数是场景实例(Scene instance),第二个参数是采样窗口每秒帧数的平均值。

2.24 属性:FrameRateMonitor-nominalFrameRate

【类型】
Event
【官方解释】
Gets the event that is raised when the frame rate returns to a normal level after having been low. The function will be passed the Scene instance as its first parameter and the average number of frames per second over the sampling window as its second parameter.
【中文翻译】
获取当帧率在降低后返回到正常水平时引发的事件。函数接收到的第一个参数是场景实例(Scene instance),第二个参数是采样窗口每秒帧数的平均值。

2.25 属性:Globe-imageryLayersUpdatedEvent(只读)

【类型】
Event
【官方解释】
Gets an event that’s raised when an imagery layer is added, shown, hidden, moved, or removed.
【中文翻译】
获取在添加、显示、隐藏、移动或删除影像图层(imagery layer)时触发的事件。

2.26 属性:Globe-terrainProviderChanged(只读)

【类型】
Event
【官方解释】
Gets an event that’s raised when the terrain provider is changed.
【中文翻译】
获取在地形提供者发生变化时触发的事件。

2.27 属性:ImageryProvider-errorEvent(只读)

【类型】
Event
【官方解释】
Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing to the event, you will be notified of the error and can potentially recover from it. Event listeners are passed an instance of TileProviderError.

【中文翻译】
获取当影像提供者(imagery provider)遇到异步错误时触发的事件。通过订阅此事件,您将收到错误通知,并有可能从中恢复。一个瓦片提供者错误(TileProviderError)实例传递给了事件监听器。

2.28 属性:ModelAnimation-start

【类型】
Event
【官方解释】
The event fired when this animation is started. This can be used, for example, to play a sound or start a particle system, when the animation starts.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
获取在动画开始时触发的事件。比如说,可以用在动画开始时需要播放声音或启动粒子系统。此事件在帧末尾场景(scene)渲染之后触发。
示例:

animation.stop.addEventListener(function(model, animation) {
  console.log('Animation stopped: ' + animation.name);
});

2.29 属性:ModelAnimation-stop

【类型】
Event
【官方解释】
The event fired when this animation is stopped. This can be used, for example, to play a sound or start a particle system, when the animation stops.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
获取在动画结束时触发的事件。比如说,可以用在动画结束时需要播放声音或启动粒子系统。此事件在帧末尾场景(scene)渲染之后触发。
示例:

animation.start.addEventListener(function(model, animation) {
  console.log('Animation started: ' + animation.name);
});

2.30 属性:ModelAnimation-update

【类型】
Event
【官方解释】
The event fired when on each frame when this animation is updated. The current time of the animation, relative to the glTF animation time span, is passed to the event, which allows, for example, starting new animations at a specific time relative to a playing animation.
This event is fired at the end of the frame after the scene is rendered.
【中文翻译】
获取在每一帧当动画更新时触发的事件。动画的当前时间(相对于glTF动画时间范围)传递给了事件。例如,我们可以在相对于动画播放的特定时间启动新的动画。
示例:

animation.update.addEventListener(function(model, animation, time) {
  console.log('Animation updated: ' + animation.name + '. glTF animation time: ' + time);
});

2.31 属性:ModelAnimationCollection-animationAdded

【类型】
Event
【官方解释】
The event fired when an animation is added to the collection. This can be used, for example, to keep a UI in sync.
【中文翻译】
获取在将动画添加到集合时触发的事件。比如说,可以用在保持UI的同步。
示例:

model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
  console.log('Animation added: ' + animation.name);
});

2.32 属性:ModelAnimationCollection-animationRemoved

【类型】
Event
【官方解释】
The event fired when an animation is removed from the collection. This can be used, for example, to keep a UI in sync.
【中文翻译】
获取在将动画从集合中移除时触发的事件。比如说,可以用在保持UI的同步。
示例:

model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
  console.log('Animation removed: ' + animation.name);
});

2.33 属性:ParticleSystem-complete

【类型】
Event
【官方解释】
Fires an event when the particle system has reached the end of its lifetime.
【中文翻译】
获取在粒子系统到达它的生命周期结束时触发的事件。

2.34 属性:Property-definitionChanged(只读)

【类型】
Event
【官方解释】
Gets the event that is raised whenever the definition of this property changes. The definition is changed whenever setCallback is called.
【中文翻译】
获取当此属性定义发生变化时触发的事件。每当调用 setCallback 函数时定义就会发生变化。

2.35 属性:PropertyArray-definitionChanged(只读)

【类型】
Event
【官方解释】
Gets the event that is raised whenever the definition of this property changes. The definition is changed whenever setValue is called with data different than the current value or one of the properties in the array also changes.
【中文翻译】
获取当此属性定义发生变化时触发的事件。每当调用 setValue 函数时,如果调用的数据与当前值不同,或者数组中的一个属性也发生了变化,则定义就会发生变化。

2.36 属性:PropertyBag-definitionChanged(只读)

【类型】
Event
【官方解释】
Gets the event that is raised whenever the set of properties contained in this object changes, or one of the properties itself changes.
【中文翻译】
获取当此对象中包含的属性集更改或其中一个属性本身发生变化时触发的事件。

2.37 属性:Scene-morphStart(常用)

【类型】
Event
【官方解释】
The event fired at the beginning of a scene transition.
【中文翻译】
事件发生在一个场景过渡的开始。

2.38 属性:Scene-morphComplete(常用)

【类型】
Event
【官方解释】
The event fired at the completion of a scene transition.
【中文翻译】
事件发生在一个场景过渡完成后。

2.39 属性:Scene-preUpdate(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised before the scene is updated or rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
【中文翻译】
获取在场景(scene)更新和场景渲染之前触发的事件。事件的订阅者接收到的第一个参数为场景(Scene)实例,第二个参数为当前时间作。

2.40 属性:Scene-postUpdate(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised immediately after the scene is updated and before the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
【中文翻译】
获取在场景(scene)更新后和场景渲染之前立即触发的事件。事件的订阅者接收到的第一个参数为场景(Scene)实例,第二个参数为当前时间作。

2.41 属性:Scene-preRender(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised after the scene is updated and immediately before the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
【中文翻译】
获取在场景(scene)更新后和场景渲染之前触发的事件。事件的订阅者接收到的第一个参数为场景(Scene)实例,第二个参数为当前时间作。

2.42 属性:Scene-postRender(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised immediately after the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
【中文翻译】
获取在场景(scene)渲染后立即引发的事件。事件的订阅者接收到的第一个参数为场景(Scene)实例,第二个参数为当前时间作。

2.43 属性:Scene-renderError(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that will be raised when an error is thrown inside the render function. The Scene instance and the thrown error are the only two parameters passed to the event handler. By default, errors are not rethrown after this event is raised, but that can be changed by setting the rethrowRenderErrors property.
【中文翻译】
获取当 render 函数中报错时触发的事件。场景实例(scene instance)和抛出的错误是传递给事件处理程序的仅有的两个参数。默认情况下,事件触发后错误会再次抛出,我们也可以通过设置 Scene#rethrowRenderErrors 属性来改变。

2.44 属性:Scene-terrainProviderChanged(只读)(常用)

【类型】
Event
【官方解释】
Gets an event that’s raised when the terrain provider is changed.
【中文翻译】
获取当地形提供者(terrain provider)变化时触发的事件。

2.45 属性:TerrainProvider-errorEvent(只读)

【类型】
Event
【官方解释】
Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing to the event, you will be notified of the error and can potentially recover from it. Event listeners are passed an instance of TileProviderError.
【中文翻译】
获取当地形提供者(terrain provider)遇到异步错误时触发的事件。通过订阅此事件,您将收到错误通知,并有可能从中恢复。一个瓦片提供者错误(TileProviderError)实例传递给了事件监听器。

2.46 属性:Viewer-selectedEntityChanged(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that is raised when the selected entity changes.
【中文翻译】
获取当选择的实体(entity)发生变化时触发的事件。

2.47 属性:Viewer-trackedEntityChanged(只读)(常用)

【类型】
Event
【官方解释】
Gets the event that is raised when the tracked entity changes.
【中文翻译】
获取当追踪的实体(entity)发生变化时触发的事件。

3 其他可能用到的 Cesium API

3.1 函数:ScreenSpaceEventHandler-setInputAction(action, type, modifier)

【官方解释】
Set a function to be executed on an input event.
【中文翻译】
设置要在输入事件上执行的函数。
【入参】
action,类型:function,当输入事件发生时要执行的函数。
type,类型:Number,输入事件的屏幕空间事件类型(ScreenSpaceEventType)。
modifier(可选),类型:Number,当 type 中的事件发生时按住的键盘修饰符(KeyboardEventModifier)。
【出参】
无。

3.2 函数:ScreenSpaceEventHandler-removeInputAction(type, modifier)

【官方解释】
Removes the function to be executed on an input event.
【中文翻译】
移除要在输入事件上执行的函数。
【入参】
type,类型:Number,输入事件的屏幕空间事件类型(ScreenSpaceEventType)。
modifier(可选),类型:Number,当 type 中的事件发生时按住的键盘修饰符(KeyboardEventModifier)。
【出参】
无。

3.3 函数:ScreenSpaceEventHandler-getInputAction(type, modifier)

【官方解释】
Returns the function to be executed on an input event.
【中文翻译】
返回要在输入事件上执行的函数。
【入参】
type,类型:Number,输入事件的屏幕空间事件类型(ScreenSpaceEventType)。
modifier(可选),类型:Number,当 type 中的事件发生时按住的键盘修饰符(KeyboardEventModifier)。
【出参】
类型:function,要在输入事件上执行的函数。

3.4 属性:ScreenSpaceCameraController-lookEventTypes

【类型】
CameraEventType|Array|undefined
【官方解释】
The input that allows the user to change the direction the camera is viewing. This only applies in 3D and Columbus view modes.
The type came be a CameraEventType, undefined, an object with eventType and modifier properties with types CameraEventType and KeyboardEventModifier, or an array of any of the preceding.
【中文翻译】
这个事件类型是让用户改变相机观察方向的输入。这只适用于3D视图和哥伦布视图(Columbus,2.5D视图)模式。
该类型是一个未定义的相机事件类型(CameraEventType),一个带有类型为 CameraEventType 的事件类型属性和类型为 KeyboardEventModifier 的键盘修饰符属性的对象,或者上述任何一个的数组。
【默认值】
{
eventType : CameraEventType.LEFT_DRAG,
modifier : KeyboardEventModifier.SHIFT
}

3.5 属性:ScreenSpaceCameraController-rotateEventTypes

【类型】
CameraEventType|Array|undefined
【官方解释】
The input that allows the user to rotate around the globe or another object. This only applies in 3D and Columbus view modes.
The type came be a CameraEventType, undefined, an object with eventType and modifier properties with types CameraEventType and KeyboardEventModifier, or an array of any of the preceding.
【中文翻译】
这个事件类型是让用户绕地球或其他对象旋转的输入。这只适用于3D视图和哥伦布视图(Columbus,2.5D视图)模式。
该类型是一个未定义的相机事件类型(CameraEventType),一个带有类型为 CameraEventType 的事件类型属性和类型为 KeyboardEventModifier 的键盘修饰符属性的对象,或者上述任何一个的数组。
【默认值】
CameraEventType.LEFT_DRAG

3.6 属性:ScreenSpaceCameraController-tiltEventTypes

【类型】
CameraEventType|Array|undefined
【官方解释】
The input that allows the user to tilt in 3D and Columbus view or twist in 2D.
The type came be a CameraEventType, undefined, an object with eventType and modifier properties with types CameraEventType and KeyboardEventModifier, or an array of any of the preceding.
【中文翻译】
这个事件类型是让用户在3D视图、哥伦布视图(2.5D视图)下倾斜或在2D视图下扭转的输入。
该类型是一个未定义的相机事件类型(CameraEventType),一个带有类型为 CameraEventType 的事件类型属性和类型为 KeyboardEventModifier 的键盘修饰符属性的对象,或者上述任何一个的数组。
【默认值】
[
CameraEventType.MIDDLE_DRAG,
CameraEventType.PINCH,
{
eventType : CameraEventType.LEFT_DRAG,
modifier : KeyboardEventModifier.CTRL
},
{
eventType : CameraEventType.RIGHT_DRAG,
modifier : KeyboardEventModifier.CTRL
}]

3.7 属性:ScreenSpaceCameraController-translateEventTypes

【类型】
CameraEventType|Array|undefined
【官方解释】
The input that allows the user to pan around the map. This only applies in 2D and Columbus view modes.
The type came be a CameraEventType, undefined, an object with eventType and modifier properties with types CameraEventType and KeyboardEventModifier, or an array of any of the preceding.
【中文翻译】
这个事件类型是让用户在地图上平移的输入。这只适用于2D视图和哥伦布视图(Columbus,2.5D视图)模式。
该类型是一个未定义的相机事件类型(CameraEventType),一个带有类型为 CameraEventType 的事件类型属性和类型为 KeyboardEventModifier 的键盘修饰符属性的对象,或者上述任何一个的数组。
【默认值】
CameraEventType.LEFT_DRAG

3.8 属性:ScreenSpaceCameraController-zoomEventTypes

【类型】
CameraEventType|Array|undefined
【官方解释】
The input that allows the user to zoom in/out.
The type came be a CameraEventType, undefined, an object with eventType and modifier properties with types CameraEventType and KeyboardEventModifier, or an array of any of the preceding.
【中文翻译】
这个事件类型是让用户缩放地图的输入。
该类型是一个未定义的相机事件类型(CameraEventType),一个带有类型为 CameraEventType 的事件类型属性和类型为 KeyboardEventModifier 的键盘修饰符属性的对象,或者上述任何一个的数组。
【默认值】
[
CameraEventType.RIGHT_DRAG,
CameraEventType.WHEEL,
CameraEventType.PINCH
]

  • 29
    点赞
  • 123
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GISer小辉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值