1 /**
2 * Flies the camera from its current position to a new position.
3 *
4 * @param {Object} options Object with the following properties:
5 * @param {Cartesian3|Rectangle} options.destination The final position of the camera in WGS84 (world) coordinates or a rectangle that would be visible from a top-down view.
6 * @param {Object} [options.orientation] An object that contains either direction and up properties or heading, pitch and roll properties. By default, the direction will point
7 * towards the center of the frame in 3D and in the negative z direction in Columbus view. The up direction will point towards local north in 3D and in the positive
8 * y direction in Columbus view. Orientation is not used in 2D when in infinite scrolling mode.
9 * @param {Number} [options.duration] The duration of the flight in seconds. If omitted, Cesium attempts to calculate an ideal duration based on the distance to be traveled by the flight.
10 * @param {Camera.FlightCompleteCallback} [options.complete] The function to execute when the flight is complete.
11 * @param {Camera.FlightCancelledCallback} [options.cancel] The function to execute if the flight is cancelled.
12 * @param {Matrix4} [options.endTransform] Transform matrix representing the reference frame the camera will be in when the flight is completed.
13 * @param {Number} [options.maximumHeight] The maximum height at the peak of the flight.
14 * @param {Number} [options.pitchAdjustHeight] If camera flyes higher than that value, adjust pitch duiring the flight to look down, and keep Earth in viewport.
15 * @param {Number} [options.flyOverLongitude] There are always two ways between 2 points on globe. This option force camera to choose fight direction to fly over that longitude.
16 * @param {Number} [options.flyOverLongitudeWeight] Fly over the lon specifyed via flyOverLongitude only if that way is not longer than short way times flyOverLongitudeWeight.
17 * @param {Boolean} [options.convert] Whether to convert the destination from world coordinates to scene coordinates (only relevant when not using 3D). Defaults to <code>true</code>.
18 * @param {EasingFunction.Callback} [options.easingFunction] Controls how the time is interpolated over the duration of the flight.
19 *
20 * @exception {DeveloperError} If either direction or up is given, then both are required.
21 *
22 * @example
23 * // 1. Fly to a position with a top-down view
24 * viewer.camera.flyTo({
25 * destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
26 * });
27 *
28 * // 2. Fly to a Rectangle with a top-down view
29 * viewer.camera.flyTo({
30 * destination : Cesium.Rectangle.fromDegrees(west, south, east, north)
31 * });
32 *
33 * // 3. Fly to a position with an orientation using unit vectors.
34 * viewer.camera.flyTo({
35 * destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
36 * orientation : {
37 * direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734),
38 * up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339)
39 * }
40 * });
41 *
42 * // 4. Fly to a position with an orientation using heading, pitch and roll.
43 * viewer.camera.flyTo({
44 * destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
45 * orientation : {
46 * heading : Cesium.Math.toRadians(175.0),
47 * pitch : Cesium.Math.toRadians(-35.0),
48 * roll : 0.0
49 * }
50 * });
51 */
52 Camera.prototype.flyTo = function (options) {
53 options = defaultValue(options, defaultValue.EMPTY_OBJECT);
54 var destination = options.destination;
55 //>>includeStart('debug', pragmas.debug);
56
57 //如果没设置目的地报错
58 if (!defined(destination)) {
59 throw new DeveloperError("destination is required.");
60 }
61 //>>includeEnd('debug');
62
63 var mode = this._mode;
64
65 //如果当前scene正在变化中
66 if (mode === SceneMode.MORPHING) {
67 return;
68 }
69
70 this.cancelFlight();
71
72 var orientation = defaultValue(
73 options.orientation,
74 defaultValue.EMPTY_OBJECT
75 );
76
77 //如果定义了方向,则将方向转换为HeadingPitchRoll这种格式
78 if (defined(orientation.direction)) {
79 orientation = directionUpToHeadingPitchRoll(
80 this,
81 destination,
82 orientation,
83 scratchSetViewOptions.orientation
84 );
85 }
86
87 //如果设置的持续时间小于0,则用setView方法直接改变view,也就是0秒、没动画
88 if (defined(options.duration) && options.duration <= 0.0) {
89 var setViewOptions = scratchSetViewOptions;
90 setViewOptions.destination = options.destination;
91 setViewOptions.orientation.heading = orientation.heading;
92 setViewOptions.orientation.pitch = orientation.pitch;
93 setViewOptions.orientation.roll = orientation.roll;
94 setViewOptions.convert = options.convert;
95 setViewOptions.endTransform = options.endTransform;
96 this.setView(setViewOptions);
97
98 //如果原来的options里还说了在视角转到目的地之后要做什么,则现在setview之后做
99 if (typeof options.complete === "function") {
100 options.complete();
101 }
102 return;
103 }
104
105 //如果是通过设置需要看到的矩形区域的四个坐标
106 var isRectangle = defined(destination.west);
107 if (isRectangle) {
108 //通过矩形的位置计算返回camera的位置
109 destination = this.getRectangleCameraCoordinates(
110 destination,
111 scratchFlyToDestination
112 );
113 }
114
115 var that = this;
116 var flightTween;
117
118 newOptions.destination = destination;
119 newOptions.heading = orientation.heading;
120 newOptions.pitch = orientation.pitch;
121 newOptions.roll = orientation.roll;
122 newOptions.duration = options.duration;
123 newOptions.complete = function () {
124 if (flightTween === that._currentFlight) {
125 that._currentFlight = undefined;
126 }
127 if (defined(options.complete)) {
128 options.complete();
129 }
130 };
131 newOptions.cancel = options.cancel;
132 newOptions.endTransform = options.endTransform;
133 newOptions.convert = isRectangle ? false : options.convert;
134 newOptions.maximumHeight = options.maximumHeight;
135 newOptions.pitchAdjustHeight = options.pitchAdjustHeight;
136 newOptions.flyOverLongitude = options.flyOverLongitude;
137 newOptions.flyOverLongitudeWeight = options.flyOverLongitudeWeight;
138 newOptions.easingFunction = options.easingFunction;
139
140 var scene = this._scene;
141 var tweenOptions = CameraFlightPath.createTween(scene, newOptions);
142 // If the camera doesn't actually need to go anywhere, duration
143 // will be 0 and we can just complete the current flight.
144 if (tweenOptions.duration === 0) {
145 if (typeof tweenOptions.complete === "function") {
146 tweenOptions.complete();
147 }
148 return;
149 }
150 flightTween = scene.tweens.add(tweenOptions);
151 this._currentFlight = flightTween;
152
153 // Save the final destination view information for the PRELOAD_FLIGHT pass.
154 var preloadFlightCamera = this._scene.preloadFlightCamera;
155 if (this._mode !== SceneMode.SCENE2D) {
156 if (!defined(preloadFlightCamera)) {
157 preloadFlightCamera = Camera.clone(this);
158 }
159 preloadFlightCamera.setView({
160 destination: destination,
161 orientation: orientation,
162 });
163
164 this._scene.preloadFlightCullingVolume = preloadFlightCamera.frustum.computeCullingVolume(
165 preloadFlightCamera.positionWC,
166 preloadFlightCamera.directionWC,
167 preloadFlightCamera.upWC
168 );
169 }
170 };

Cesium源码之flyTo(一)的更多相关文章

  1. Cesium源码剖析---Clipping Plane

    之前就一直有写博客的想法,别人也建议写一写,但一直没有动手写,自己想了一下原因,就一个字:懒.懒.懒.为了改掉这个毛病,决定从今天开始写博客了,一方面对自己掌握的知识做一个梳理,另一方面和大家做一个交 ...

  2. Cesium 源码笔记[1] Viewer模块实例化的大致过程

    我原本想写日记的,但是不太现实. 源码下载 源码可以从源码包和发行包中的Source目录中获取. Cesium的模块化机制从1.63版本开始,由原来的RequireJs变为ES6.但有可能是原先设计耦 ...

  3. Cesium源码剖析---Post Processing之物体描边(Silhouette)

    Cesium在1.46版本中新增了对整个场景的后期处理(Post Processing)功能,包括模型描边.黑白图.明亮度调整.夜视效果.环境光遮蔽等.对于这么炫酷的功能,我们绝不犹豫,先去翻一翻它的 ...

  4. Cesium源码剖析---视频投影

    Cesium中的视频投影是指将视频作为一种物体材质,实现在物体上播放视频的效果.这个功能在Cesium早期版本中就支持了,在Code Example中有一个示例.今天就来分析一下其内部实现原理. 1. ...

  5. Cesium源码剖析---Ambient Occlusion(环境光遮蔽)

    Ambient Occlusion简称AO,中文没有太确定的叫法,一般译作环境光遮蔽.百度百科上对AO的解释是这样的:AO是来描绘物体和物体相交或靠近的时候遮挡周围漫反射光线的效果,可以解决或改善漏光 ...

  6. cesium结合geoserver利用WFS服务实现图层新增(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  7. cesium结合geoserver利用WFS服务实现图层编辑(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  8. cesium结合geoserver利用WFS服务实现图层删除(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  9. cesium编程中级(二)源码编译

    cesium编程中级(二)源码编译 有些情况下,比如我们自己从Github下载了最新的代码,或者自己临时修改了一点代码,想要编译后的Build文件夹的内容,需要自行编译源码,这里介绍一下编译的方法 下 ...

  10. cesium 结合 geoserver 实现地图属性查询(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

随机推荐

  1. vulnhub靶场之EVILBOX: ONE

    准备: 攻击机:虚拟机kali.本机win10. 靶机:EVILBOX: ONE,下载地址:https://download.vulnhub.com/evilbox/EvilBox---One.ova ...

  2. Asp.Net Core&Jaeger实现链路追踪

    前言 随着应用愈发复杂,请求的链路也愈发复杂,微服务化下,更是使得不同的服务分布在不同的机器,地域,语言也不尽相同.因此需要借助工具帮助分析,跟踪,定位请求中出现的若干问题,以此来保障服务治理,链路追 ...

  3. MYSQL快速安装整理

    参考教程:https://www.cnblogs.com/brad93/p/16650780.html [检查是否已安装过] find / -name mysql [快速安装开始] groupadd  ...

  4. 【面试题总结】Java并发-多线程、JUC详述(思维导图)

    〇.整体目录 一.多线程 1.实现方式 2.内存图 3.线程状态 4.实现线程同步 5.并发编程 二.JUC 1.概述与volatile关键字 2.ThreadLocal类 3.CAS方法 4.ato ...

  5. 【实时数仓】Day04-DWS层业务:DWS设计、访客宽表、商品主题宽表、流合并、地区主题表、FlinkSQL、关键词主题表、分词

    一.DWS层与DWM设计 1.思路 之前已经进行分流 但只需要一些指标进行实时计算,将这些指标以主题宽表的形式输出 2.需求 访客.商品.地区.关键词四层的需求(可视化大屏展示.多维分析) 3.DWS ...

  6. 【每日一题】【回溯】2021年12月29日-93. 复原 IP 地址

    有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 '.' 分隔. 例如:"0.1.2.201" 和 "192.1 ...

  7. org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents

    异常:org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to b ...

  8. 前端HTML不使用flash兼容IE浏览器播放视频

    前言:最近公司项目上有个需求就是在IE8上不使用flash技术来去实现视频播放 分析:IE8不支持HTML5,所以不能使用video标签,在非IE的浏览器可以使用video标签 目录 我的解决 DEM ...

  9. STM32标准库中GPIO_ReadInputData与GPIO_ReadInputDataBit的区别

    GPIO_ReadInputData读的是GPIOx的整个IDR寄存器的数据,返回一个十六位数,对应IDR寄存器的十六位.反映GPIOx所有端口的电平状态,所以参数只用传入GPIOx. uint16_ ...

  10. 手动解析word Table模块内容

    最近来了一个需求, 需要手动解析word ( 好处就是不需要安装office 以及不会有office解析的线程残留),然后就是可以自定义解析规则,比较方便 比如解析这个word里面的内容: 标题,表格 ...