@lijuhong1981/cesium.utils 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/package.json +45 -4
- package/src/additions/Geographic.js +603 -0
- package/src/additions/GeographicTransform.js +291 -0
- package/src/additions/GeometryInstanceAttributes.js +164 -0
- package/src/additions/ModelMatrixTransforms.js +822 -0
- package/src/additions/PropertyChangedListener.js +72 -0
- package/src/additions/PropertyType.js +30 -0
- package/src/additions/StTransforms.js +266 -0
- package/src/additions/TranslationRotationScaleTransform.js +809 -0
- package/src/additions/index.js +8 -0
- package/src/index.js +4 -0
- package/src/parses/index.js +46 -0
- package/src/parses/parseAltitude.js +32 -0
- package/src/parses/parseArcType.js +26 -0
- package/src/parses/parseAttitudeToHeadingPitchRoll.js +26 -0
- package/src/parses/parseAttitudeToMatrix3.js +17 -0
- package/src/parses/parseAttitudeToQuaternion.js +21 -0
- package/src/parses/parseCartographicToCartesian.js +21 -0
- package/src/parses/parseCartographicsToPositions.js +20 -0
- package/src/parses/parseClassificationType.js +24 -0
- package/src/parses/parseClockRange.js +26 -0
- package/src/parses/parseColorBlendMode.js +26 -0
- package/src/parses/parseCornerType.js +24 -0
- package/src/parses/parseCullFace.js +28 -0
- package/src/parses/parseEulerToHeadingPitchRoll.js +21 -0
- package/src/parses/parseEulerToQuaternion.js +18 -0
- package/src/parses/parseGeographicToCartesian.js +21 -0
- package/src/parses/parseGeographicsToPositions.js +20 -0
- package/src/parses/parseHeading.js +28 -0
- package/src/parses/parseHeightReference.js +24 -0
- package/src/parses/parseHorizontalOrigin.js +26 -0
- package/src/parses/parseLabelStyle.js +26 -0
- package/src/parses/parseLatitude.js +28 -0
- package/src/parses/parseLongitude.js +28 -0
- package/src/parses/parsePitch.js +26 -0
- package/src/parses/parseRoll.js +26 -0
- package/src/parses/parseRotationToHeadingPitchRoll.js +40 -0
- package/src/parses/parseRotationToMatrix3.js +25 -0
- package/src/parses/parseRotationToQuaternion.js +27 -0
- package/src/parses/parseShadowMode.js +26 -0
- package/src/parses/parseToBoundingRectangle.js +33 -0
- package/src/parses/parseToCartesian2.js +35 -0
- package/src/parses/parseToCartesian3.js +37 -0
- package/src/parses/parseToCartesian3Array.js +21 -0
- package/src/parses/parseToCartesian4.js +39 -0
- package/src/parses/parseToCartographic.js +31 -0
- package/src/parses/parseToColor.js +33 -0
- package/src/parses/parseToDistanceDisplayCondition.js +41 -0
- package/src/parses/parseToGeographic.js +31 -0
- package/src/parses/parseToHeadingPitchRange.js +45 -0
- package/src/parses/parseToJulianDate.js +23 -0
- package/src/parses/parseToNearFarScalar.js +33 -0
- package/src/parses/parseToPlane.js +37 -0
- package/src/parses/parseToPolygonHierarchy.js +48 -0
- package/src/parses/parseToRange.js +26 -0
- package/src/parses/parseToRectangle.js +32 -0
- package/src/parses/parseToTimeInterval.js +45 -0
- package/src/parses/parseVerticalOrigin.js +28 -0
- package/src/revisions/BoundingSphere.revise.js +107 -0
- package/src/revisions/Camera.revise.js +366 -0
- package/src/revisions/Cartesian.revise.js +313 -0
- package/src/revisions/Cartographic.revise.js +443 -0
- package/src/revisions/Check.revise.js +164 -0
- package/src/revisions/Color.revise.js +271 -0
- package/src/revisions/DistanceDisplayCondition.revise.js +37 -0
- package/src/revisions/Ellipsoid.revise.js +64 -0
- package/src/revisions/Geometry.revise.js +79 -0
- package/src/revisions/Globe.revise.js +92 -0
- package/src/revisions/HeadingPitchRoll.revise.js +328 -0
- package/src/revisions/JulianDate.revise.js +28 -0
- package/src/revisions/Material.revise.js +308 -0
- package/src/revisions/Math.revise.js +98 -0
- package/src/revisions/Matrix.revise.js +578 -0
- package/src/revisions/POI.revise.js +178 -0
- package/src/revisions/Plane.revise.js +43 -0
- package/src/revisions/PolylinePipeline.revise.js +54 -0
- package/src/revisions/PostProcessStageLibrary.revise.js +1143 -0
- package/src/revisions/Primitive.revise.js +83 -0
- package/src/revisions/Property.revise.js +37 -0
- package/src/revisions/Quaternion.revise.js +66 -0
- package/src/revisions/Rectangle.revise.js +570 -0
- package/src/revisions/SceneTransforms.revise.js +82 -0
- package/src/revisions/Spherical.revise.js +35 -0
- package/src/revisions/index.js +25 -0
- package/src/utils/Scratch.js +165 -0
- package/src/utils/computeCirclePositions.js +48 -0
- package/src/utils/computeCircleRadius.js +19 -0
- package/src/utils/computeModelMatrix.js +109 -0
- package/src/utils/computeStTransform.js +57 -0
- package/src/utils/createGeometry.js +114 -0
- package/src/utils/createPointCloudGeometry.js +79 -0
- package/src/utils/getGeometryInstanceAttributes.js +43 -0
- package/src/utils/getPositionFromTarget.js +29 -0
- package/src/utils/getRenderState.js +35 -0
- package/src/utils/index.js +13 -0
- package/src/utils/isColorMaterial.js +13 -0
- package/src/utils/isTranslucent.js +13 -0
- package/src/utils/resolveModelMatrixByFixedFrame.js +30 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import getValidValue from '@lijuhong1981/jscheck/src/getValidValue.js';
|
|
2
|
+
import Interval from '@lijuhong1981/jsmath/src/Interval.js';
|
|
3
|
+
import { Check } from "cesium";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把数组或对象解析为区间(Interval)。
|
|
7
|
+
* @param {Interval|Array|object} value 待解析的值,支持 [minimum,maximum] 数组或含 start/end/min/max 等字段的对象
|
|
8
|
+
* @param {Interval} [result=new Interval()] 用于存储结果的可选对象
|
|
9
|
+
* @returns {Interval} 解析后的区间对象
|
|
10
|
+
*/
|
|
11
|
+
function parseToRange(value, result = new Interval()) {
|
|
12
|
+
Check.defined('value', value);
|
|
13
|
+
if (value instanceof Interval) {
|
|
14
|
+
if (result && value !== result)
|
|
15
|
+
return value.clone(result);
|
|
16
|
+
else
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const minimum = getValidValue(value[0], value.start, value.minimum, value.min, value.x);
|
|
20
|
+
const maximum = getValidValue(value[1], value.end, value.maximum, value.max, value.y);
|
|
21
|
+
result.setValues(minimum, maximum);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default parseToRange;
|
|
26
|
+
export { parseToRange };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import getValidValue from "@lijuhong1981/jscheck/src/getValidValue.js";
|
|
2
|
+
import { Check, defined, DeveloperError, Rectangle } from "cesium";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 把数组或对象解析为矩形({@link Rectangle})。
|
|
6
|
+
* @param {Rectangle|Array|object} value 待解析的值,支持 [west,south,east,north] 数组或含 west/south/east/north 字段的对象
|
|
7
|
+
* @param {Rectangle} [result] 用于存储结果的可选对象
|
|
8
|
+
* @param {boolean} [isDegrees=true] 输入是否为角度制,为 true 时按角度解析
|
|
9
|
+
* @returns {Rectangle} 解析后的矩形
|
|
10
|
+
*/
|
|
11
|
+
function parseToRectangle(value, result, isDegrees = true) {
|
|
12
|
+
Check.defined('value', value);
|
|
13
|
+
if (value instanceof Rectangle) {
|
|
14
|
+
if (result && value !== result)
|
|
15
|
+
return value.clone(result);
|
|
16
|
+
else
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const west = getValidValue(value[0], value.west);
|
|
20
|
+
const south = getValidValue(value[1], value.south);
|
|
21
|
+
const east = getValidValue(value[2], value.east);
|
|
22
|
+
const north = getValidValue(value[3], value.north);
|
|
23
|
+
if (!defined(west) || !defined(south) || !defined(east) || !defined(north))
|
|
24
|
+
throw new DeveloperError('the west or south or east or north is undefined.');
|
|
25
|
+
if (isDegrees)
|
|
26
|
+
return Rectangle.fromDegrees(west, south, east, north, result);
|
|
27
|
+
else
|
|
28
|
+
return Rectangle.fromRadians(west, south, east, north, result);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default parseToRectangle;
|
|
32
|
+
export { parseToRectangle };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TimeInterval } from "cesium";
|
|
2
|
+
import parseToJulianDate from "./parseToJulianDate.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 把字符串、数组或对象解析为时间区间({@link TimeInterval})。
|
|
6
|
+
* @param {TimeInterval|string|Array|object} value 待解析的值,字符串按 ISO8601 解析,数组为 [start,stop]
|
|
7
|
+
* @param {TimeInterval} [result] 用于存储结果的可选对象
|
|
8
|
+
* @returns {TimeInterval} 解析后的时间区间
|
|
9
|
+
*/
|
|
10
|
+
function parseToTimeInterval(value, result) {
|
|
11
|
+
if (value instanceof TimeInterval) {
|
|
12
|
+
if (result && value !== result)
|
|
13
|
+
return TimeInterval.clone(value, result);
|
|
14
|
+
else
|
|
15
|
+
return value;
|
|
16
|
+
} else if (typeof value === 'string')
|
|
17
|
+
return TimeInterval.fromIso8601(value, result);
|
|
18
|
+
|
|
19
|
+
if (result === undefined)
|
|
20
|
+
result = new TimeInterval();
|
|
21
|
+
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
let start = parseToJulianDate(value[0]);
|
|
24
|
+
let stop = parseToJulianDate(value[1]);
|
|
25
|
+
result.start = start;
|
|
26
|
+
result.stop = stop;
|
|
27
|
+
} else if (typeof value === 'object') {
|
|
28
|
+
let start = value.start || value.startTime;
|
|
29
|
+
start = parseToJulianDate(start);
|
|
30
|
+
let stop = value.stop || value.stopTime;
|
|
31
|
+
stop = parseToJulianDate(stop);
|
|
32
|
+
result.start = start;
|
|
33
|
+
result.stop = stop;
|
|
34
|
+
if (value.data !== undefined)
|
|
35
|
+
result.data = value.data;
|
|
36
|
+
if (value.isStartIncluded)
|
|
37
|
+
result.isStartIncluded = value.isStartIncluded;
|
|
38
|
+
if (value.isStopIncluded)
|
|
39
|
+
result.isStopIncluded = value.isStopIncluded;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default parseToTimeInterval;
|
|
45
|
+
export { parseToTimeInterval };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DeveloperError, VerticalOrigin } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把字符串或数字解析为 Cesium 的 {@link VerticalOrigin} 枚举值。
|
|
5
|
+
* @param {string|number} value 待解析的值,字符串支持 'top'、'bottom'、'baseline'、'center'
|
|
6
|
+
* @returns {VerticalOrigin} 解析后的 VerticalOrigin
|
|
7
|
+
*/
|
|
8
|
+
function parseVerticalOrigin(value) {
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
switch (value.toLowerCase()) {
|
|
11
|
+
case 'top':
|
|
12
|
+
return VerticalOrigin.TOP;
|
|
13
|
+
case 'bottom':
|
|
14
|
+
return VerticalOrigin.BOTTOM;
|
|
15
|
+
case 'baseline':
|
|
16
|
+
return VerticalOrigin.BASELINE;
|
|
17
|
+
case 'center':
|
|
18
|
+
default:
|
|
19
|
+
return VerticalOrigin.CENTER;
|
|
20
|
+
}
|
|
21
|
+
} else if (typeof value === 'number')
|
|
22
|
+
return value;
|
|
23
|
+
else
|
|
24
|
+
throw new DeveloperError('unable parse the ' + value + ' to VerticalOrigin.');
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default parseVerticalOrigin;
|
|
28
|
+
export { parseVerticalOrigin };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BoundingSphere, Cartesian3, Check, defined, Matrix4 } from "cesium";
|
|
2
|
+
import parseGeographicsToPositions from "../parses/parseGeographicsToPositions.js";
|
|
3
|
+
import Scratch from "../utils/Scratch.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 扩展 Cesium 的 BoundingSphere 类,补充从中心点/半径、地理坐标、模型矩阵创建包围球,
|
|
7
|
+
* 以及计算到世界坐标点、相机的距离等方法。
|
|
8
|
+
* @class BoundingSphere
|
|
9
|
+
* @see {@link https://cesium.com/learn/cesiumjs/ref-doc/BoundingSphere.html}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 从中心点与半径创建包围球。
|
|
14
|
+
* @param {Cartesian3} center 包围球中心点(世界坐标)。
|
|
15
|
+
* @param {number} [radius=0] 包围球半径,单位米。
|
|
16
|
+
* @param {BoundingSphere} [result=new BoundingSphere()] 用于存储结果的可选对象。
|
|
17
|
+
* @returns {BoundingSphere} 生成或填充后的包围球。
|
|
18
|
+
* @memberof BoundingSphere
|
|
19
|
+
* @static
|
|
20
|
+
*/
|
|
21
|
+
BoundingSphere.fromElements = function (center, radius = 0, result = new BoundingSphere()) {
|
|
22
|
+
result.center = center;
|
|
23
|
+
result.radius = radius;
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 从一组地理坐标创建包围球,通过计算这些点在世界坐标系下的包围范围得到。
|
|
29
|
+
* @param {Array|object} geographics 地理坐标点集合。
|
|
30
|
+
* @param {Ellipsoid} [ellipsoid] 参考椭球体。
|
|
31
|
+
* @param {BoundingSphere} [result] 用于存储结果的可选对象。
|
|
32
|
+
* @returns {BoundingSphere} 包含所有点的包围球。
|
|
33
|
+
* @memberof BoundingSphere
|
|
34
|
+
* @static
|
|
35
|
+
*/
|
|
36
|
+
BoundingSphere.fromGeographics = function (geographics, ellipsoid, result) {
|
|
37
|
+
const positions = parseGeographicsToPositions(geographics, undefined, ellipsoid);
|
|
38
|
+
return BoundingSphere.fromPoints(positions, result);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 从模型矩阵与半径创建包围球,中心点取矩阵的平移分量。
|
|
43
|
+
* @param {Matrix4} modelMatrix 模型矩阵。
|
|
44
|
+
* @param {number} [radius] 包围球半径;未提供时保留结果对象原有的半径。
|
|
45
|
+
* @param {BoundingSphere} [result=new BoundingSphere()] 用于存储结果的可选对象。
|
|
46
|
+
* @returns {BoundingSphere} 生成或填充后的包围球。
|
|
47
|
+
* @memberof BoundingSphere
|
|
48
|
+
* @static
|
|
49
|
+
*/
|
|
50
|
+
BoundingSphere.fromModelMatrix = function (modelMatrix, radius, result = new BoundingSphere()) {
|
|
51
|
+
Check.defined("modelMatrix", modelMatrix);
|
|
52
|
+
const center = Matrix4.getTranslation(modelMatrix, Scratch.scratchCenter);
|
|
53
|
+
result.center = Cartesian3.clone(center, result.center);
|
|
54
|
+
if (defined(radius))
|
|
55
|
+
result.radius = radius;
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 计算某个世界坐标位置到包围球表面的距离,若点在球内则返回 0。
|
|
61
|
+
* @param {BoundingSphere} boundingSphere 目标包围球。
|
|
62
|
+
* @param {Cartesian3} positionWC 世界坐标位置。
|
|
63
|
+
* @returns {number} 位置到球表面的距离,单位米。
|
|
64
|
+
* @memberof BoundingSphere
|
|
65
|
+
* @static
|
|
66
|
+
*/
|
|
67
|
+
BoundingSphere.distanceToCartesian = function (boundingSphere, positionWC) {
|
|
68
|
+
Check.defined("boundingSphere", boundingSphere);
|
|
69
|
+
Check.defined("positionWC", positionWC);
|
|
70
|
+
return Math.max(0.0, Cartesian3.distance(boundingSphere.center, positionWC) - boundingSphere.radius);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 计算某个世界坐标位置到包围球表面的距离,若点在球内则返回 0。
|
|
75
|
+
* @param {Cartesian3} positionWC 世界坐标位置。
|
|
76
|
+
* @returns {number} 位置到球表面的距离,单位米。
|
|
77
|
+
* @memberof BoundingSphere
|
|
78
|
+
*/
|
|
79
|
+
BoundingSphere.prototype.distanceToCartesian = function (positionWC) {
|
|
80
|
+
return BoundingSphere.distanceToCartesian(this, positionWC);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 计算相机到包围球表面的距离,若相机在球内则返回 0。
|
|
85
|
+
* @param {BoundingSphere} boundingSphere 目标包围球。
|
|
86
|
+
* @param {Camera} camera 相机。
|
|
87
|
+
* @returns {number} 相机到球表面的距离,单位米。
|
|
88
|
+
* @memberof BoundingSphere
|
|
89
|
+
* @static
|
|
90
|
+
*/
|
|
91
|
+
BoundingSphere.distanceToCamera = function (boundingSphere, camera) {
|
|
92
|
+
Check.defined("camera", camera);
|
|
93
|
+
return BoundingSphere.distanceToCartesian(boundingSphere, camera.positionWC);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 计算相机到包围球表面的距离,若相机在球内则返回 0。
|
|
98
|
+
* @param {Camera} camera 相机。
|
|
99
|
+
* @returns {number} 相机到球表面的距离,单位米。
|
|
100
|
+
* @memberof BoundingSphere
|
|
101
|
+
*/
|
|
102
|
+
BoundingSphere.prototype.distanceToCamera = function (camera) {
|
|
103
|
+
return BoundingSphere.distanceToCamera(this, camera);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default BoundingSphere;
|
|
107
|
+
export { BoundingSphere };
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { BoundingSphere, Camera, Cartesian3, Math as CesiumMath, Check, HeadingPitchRoll, Matrix4, Ray, defined } from "cesium";
|
|
2
|
+
import parseAttitudeToHeadingPitchRoll from "../parses/parseAttitudeToHeadingPitchRoll.js";
|
|
3
|
+
import parseGeographicToCartesian from "../parses/parseGeographicToCartesian.js";
|
|
4
|
+
import parseToCartesian3 from "../parses/parseToCartesian3.js";
|
|
5
|
+
import parseToHeadingPitchRange from "../parses/parseToHeadingPitchRange.js";
|
|
6
|
+
import parseToRectangle from "../parses/parseToRectangle.js";
|
|
7
|
+
import computeModelMatrix from "../utils/computeModelMatrix.js";
|
|
8
|
+
import Scratch from "../utils/Scratch.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 扩展 Cesium 的 Camera 类,补充地理坐标、姿态、视线方向等访问属性,
|
|
12
|
+
* 并扩展 setView、flyTo、flyHome 等方法以支持更丰富的参数形式。
|
|
13
|
+
* @class Camera
|
|
14
|
+
* @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Camera.html}
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperties(Camera.prototype, {
|
|
18
|
+
/**
|
|
19
|
+
* 获取相机所属的场景对象。
|
|
20
|
+
* @type {Scene}
|
|
21
|
+
* @memberof Camera
|
|
22
|
+
*/
|
|
23
|
+
scene: {
|
|
24
|
+
get: function () {
|
|
25
|
+
return this._scene;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* 获取相机当前位置对应的地理坐标。
|
|
30
|
+
* @type {Geographic}
|
|
31
|
+
* @memberof Camera
|
|
32
|
+
*/
|
|
33
|
+
geographic: {
|
|
34
|
+
get: function () {
|
|
35
|
+
return this.positionCartographic.toGeographic();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* 获取相机航向角(角度制,单位度)。
|
|
40
|
+
* @type {number}
|
|
41
|
+
* @memberof Camera
|
|
42
|
+
*/
|
|
43
|
+
headingDegrees: {
|
|
44
|
+
get: function () {
|
|
45
|
+
return CesiumMath.toDegrees(this.heading);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* 获取相机俯仰角(角度制,单位度)。
|
|
50
|
+
* @type {number}
|
|
51
|
+
* @memberof Camera
|
|
52
|
+
*/
|
|
53
|
+
pitchDegrees: {
|
|
54
|
+
get: function () {
|
|
55
|
+
return CesiumMath.toDegrees(this.pitch);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* 获取相机横滚角(角度制,单位度)。
|
|
60
|
+
* @type {number}
|
|
61
|
+
* @memberof Camera
|
|
62
|
+
*/
|
|
63
|
+
rollDegrees: {
|
|
64
|
+
get: function () {
|
|
65
|
+
return CesiumMath.toDegrees(this.roll);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* 获取相机当前姿态对应的 HeadingPitchRoll(弧度制)。
|
|
70
|
+
* @type {HeadingPitchRoll}
|
|
71
|
+
* @memberof Camera
|
|
72
|
+
*/
|
|
73
|
+
orientation: {
|
|
74
|
+
get: function () {
|
|
75
|
+
if (!defined(this._orientation))
|
|
76
|
+
this._orientation = new HeadingPitchRoll();
|
|
77
|
+
this._orientation.heading = this.heading;
|
|
78
|
+
this._orientation.pitch = this.pitch;
|
|
79
|
+
this._orientation.roll = this.roll;
|
|
80
|
+
return this._orientation;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* 获取相机当前姿态的角度制表示(度)。
|
|
85
|
+
* @type {object}
|
|
86
|
+
* @memberof Camera
|
|
87
|
+
*/
|
|
88
|
+
orientationDegrees: {
|
|
89
|
+
get: function () {
|
|
90
|
+
return this.orientation.toDegrees();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* 获取相机当前姿态的角度制表示(度),等同于 orientationDegrees。
|
|
95
|
+
* @type {object}
|
|
96
|
+
* @memberof Camera
|
|
97
|
+
*/
|
|
98
|
+
attitude: {
|
|
99
|
+
get: function () {
|
|
100
|
+
return this.orientationDegrees;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* 获取相机视锥体的投影矩阵。
|
|
105
|
+
* @type {Matrix4}
|
|
106
|
+
* @memberof Camera
|
|
107
|
+
*/
|
|
108
|
+
projectionMatrix: {
|
|
109
|
+
get: function () {
|
|
110
|
+
return this.frustum.projectionMatrix;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* 判断相机当前是否正在执行飞行(视角切换)动画。
|
|
115
|
+
* @type {boolean}
|
|
116
|
+
* @memberof Camera
|
|
117
|
+
*/
|
|
118
|
+
isFlighting: {
|
|
119
|
+
get: function () {
|
|
120
|
+
return defined(this._currentFlight);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* 获取相机所属场景的参考椭球体。
|
|
125
|
+
* @type {Ellipsoid}
|
|
126
|
+
* @memberof Camera
|
|
127
|
+
*/
|
|
128
|
+
ellipsoid: {
|
|
129
|
+
get: function () {
|
|
130
|
+
return this._scene.ellipsoid;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 计算给定距离处每个像素对应的地面米数。
|
|
137
|
+
* @param {number} distance 距离相机的位置距离,单位米。
|
|
138
|
+
* @returns {number} 每个像素对应的米数。
|
|
139
|
+
* @memberof Camera
|
|
140
|
+
*/
|
|
141
|
+
Camera.prototype.getMetersPerPixel = function (distance) {
|
|
142
|
+
Check.typeOf.number('distance', distance);
|
|
143
|
+
const pixelSize = this.frustum.getPixelDimensions(
|
|
144
|
+
this._scene.drawingBufferWidth,
|
|
145
|
+
this._scene.drawingBufferHeight,
|
|
146
|
+
distance,
|
|
147
|
+
this._scene.pixelRatio,
|
|
148
|
+
Scratch.scratchPixelSize
|
|
149
|
+
);
|
|
150
|
+
return Math.max(pixelSize.x, pixelSize.y);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 原始 setView 方法的引用,扩展后的 setView 在完成参数处理后调用它。
|
|
155
|
+
* @type {function}
|
|
156
|
+
* @memberof Camera
|
|
157
|
+
*/
|
|
158
|
+
Camera.prototype.originalSetView = Camera.prototype.setView;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 重写 setView,支持通过 geographic、position、rectangle、attitude 等参数形式设置视角。
|
|
162
|
+
* @param {object} options 视角设置项,支持 geographic/position/rectangle/attitude/destination/orientation 等字段。
|
|
163
|
+
* @memberof Camera
|
|
164
|
+
*/
|
|
165
|
+
Camera.prototype.setView = function (options) {
|
|
166
|
+
if (defined(options.geographic) || defined(options.position)) {
|
|
167
|
+
const modelMatrix = computeModelMatrix({
|
|
168
|
+
geographic: options.geographic,
|
|
169
|
+
position: options.position,
|
|
170
|
+
translation: options.translation,
|
|
171
|
+
ellipsoid: this.ellipsoid,
|
|
172
|
+
});
|
|
173
|
+
options.destination = Matrix4.getTranslation(modelMatrix, new Cartesian3());
|
|
174
|
+
} else if (defined(options.rectangle)) {
|
|
175
|
+
options.destination = parseToRectangle(options.rectangle);
|
|
176
|
+
}
|
|
177
|
+
if (defined(options.attitude))
|
|
178
|
+
options.orientation = parseAttitudeToHeadingPitchRoll(options.attitude);
|
|
179
|
+
else if (options.orientation && Array.isArray(options.orientation))
|
|
180
|
+
options.orientation = HeadingPitchRoll.unpack(options.orientation);
|
|
181
|
+
this.originalSetView(options);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 原始 flyTo 方法的引用,扩展后的 flyTo 在完成参数处理后调用它。
|
|
186
|
+
* @type {function}
|
|
187
|
+
* @memberof Camera
|
|
188
|
+
*/
|
|
189
|
+
Camera.prototype.originalFlyTo = Camera.prototype.flyTo;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 重写 flyTo,支持通过 geographic、position、rectangle、attitude 等参数形式进行视角飞行。
|
|
193
|
+
* @param {object} options 飞行设置项,支持 geographic/position/rectangle/attitude/destination/orientation 等字段。
|
|
194
|
+
* @memberof Camera
|
|
195
|
+
*/
|
|
196
|
+
Camera.prototype.flyTo = function (options) {
|
|
197
|
+
if (defined(options.geographic) || defined(options.position)) {
|
|
198
|
+
const modelMatrix = computeModelMatrix({
|
|
199
|
+
geographic: options.geographic,
|
|
200
|
+
position: options.position,
|
|
201
|
+
translation: options.translation,
|
|
202
|
+
ellipsoid: this.ellipsoid,
|
|
203
|
+
});
|
|
204
|
+
options.destination = Matrix4.getTranslation(modelMatrix, new Cartesian3());
|
|
205
|
+
} else if (defined(options.rectangle)) {
|
|
206
|
+
options.destination = parseToRectangle(options.rectangle);
|
|
207
|
+
}
|
|
208
|
+
if (defined(options.attitude))
|
|
209
|
+
options.orientation = parseAttitudeToHeadingPitchRoll(options.attitude);
|
|
210
|
+
else if (options.orientation && Array.isArray(options.orientation))
|
|
211
|
+
options.orientation = HeadingPitchRoll.unpack(options.orientation);
|
|
212
|
+
this.originalFlyTo(options);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 设置 HomeView(视角),flyHome 时将优先飞至该设置。
|
|
217
|
+
* @param {object} options 视角设置项,参数参见 flyTo。
|
|
218
|
+
* @memberof Camera
|
|
219
|
+
*/
|
|
220
|
+
Camera.prototype.setHomeView = function (options) {
|
|
221
|
+
if (!options)
|
|
222
|
+
return;
|
|
223
|
+
this.homeViewOptions = options;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 设置默认视角,flyHome 时将使用该设置。
|
|
228
|
+
* @param {object} options 视角设置项,参数参见 flyTo。
|
|
229
|
+
* @memberof Camera
|
|
230
|
+
* @deprecated 已废弃,请改用 setHomeView。
|
|
231
|
+
*/
|
|
232
|
+
Camera.prototype.setDefaultView = function (options) {
|
|
233
|
+
console.warn('setDefaultView function is deprecated, use setHomeView instead.');
|
|
234
|
+
this.setHomeView(options);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
//记录Camera原始的flyHome方法
|
|
238
|
+
/**
|
|
239
|
+
* 原始 flyHome 方法的引用,扩展后的 flyHome 在未设置 homeView 时调用它。
|
|
240
|
+
* @type {function}
|
|
241
|
+
* @memberof Camera
|
|
242
|
+
*/
|
|
243
|
+
Camera.prototype.originalFlyHome = Camera.prototype.flyHome;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 重写 flyHome,优先飞至 homeView 设置,未设置时执行原始的 flyHome。
|
|
247
|
+
* @param {number} [duration] 飞行持续时间,单位秒;未指定时使用默认值。
|
|
248
|
+
* @memberof Camera
|
|
249
|
+
*/
|
|
250
|
+
Camera.prototype.flyHome = function (duration) {
|
|
251
|
+
if (this.homeViewOptions) {
|
|
252
|
+
const options = Object.assign({}, this.homeViewOptions);
|
|
253
|
+
if (defined(duration))
|
|
254
|
+
options.duration = duration;
|
|
255
|
+
this.flyTo(options);
|
|
256
|
+
} else {
|
|
257
|
+
this.originalFlyHome(duration);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 相机飞至指定的视点。
|
|
263
|
+
* @param {Cartesian3} viewPoint 目标视点(世界坐标)。
|
|
264
|
+
* @param {HeadingPitchRange|Array} offset 视角偏移,可为 HeadingPitchRange 或数组。
|
|
265
|
+
* @param {object} [options={}] 飞行选项,透传给 flyToBoundingSphere。
|
|
266
|
+
* @memberof Camera
|
|
267
|
+
*/
|
|
268
|
+
Camera.prototype.flyToViewPoint = function (viewPoint, offset, options = {}) {
|
|
269
|
+
Check.defined('viewPoint', viewPoint);
|
|
270
|
+
Check.defined('offset', offset);
|
|
271
|
+
|
|
272
|
+
const boundingSphere = BoundingSphere.fromElements(viewPoint, 0, Scratch.scratchBoundingSphere);
|
|
273
|
+
|
|
274
|
+
options.offset = parseToHeadingPitchRange(offset, Scratch.scratchHeadingPitchRange, offset.degrees);
|
|
275
|
+
|
|
276
|
+
this.flyToBoundingSphere(boundingSphere, options);
|
|
277
|
+
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 相机飞至指定的矩形范围。
|
|
282
|
+
* @param {Rectangle} rectangle 目标矩形范围。
|
|
283
|
+
* @param {object} [options={}] 飞行选项,透传给 flyToBoundingSphere。
|
|
284
|
+
* @memberof Camera
|
|
285
|
+
*/
|
|
286
|
+
Camera.prototype.flyToRectangle = function (rectangle, options = {}) {
|
|
287
|
+
Check.defined('rectangle', rectangle);
|
|
288
|
+
|
|
289
|
+
const boundingSphere = BoundingSphere.fromRectangle3D(rectangle, this.ellipsoid, options.surfaceHeight, Scratch.scratchBoundingSphere);
|
|
290
|
+
this.flyToBoundingSphere(boundingSphere, options);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 相机看向指定的方向。
|
|
295
|
+
* @param {Cartesian3} direction 目标方向。
|
|
296
|
+
* @param {Cartesian3} [up] 上方向;未提供时使用当前位置的椭球法线。
|
|
297
|
+
* @memberof Camera
|
|
298
|
+
*/
|
|
299
|
+
Camera.prototype.lookAtDirection = function (direction, up) {
|
|
300
|
+
|
|
301
|
+
Check.typeOf.object('direction', direction);
|
|
302
|
+
direction = parseToCartesian3(direction, Scratch.scratchDirection, false);
|
|
303
|
+
Cartesian3.normalize(direction, direction);
|
|
304
|
+
if (up) {
|
|
305
|
+
up = parseToCartesian3(up, Scratch.scratchUp, false);
|
|
306
|
+
Cartesian3.normalize(up, up);
|
|
307
|
+
} else {
|
|
308
|
+
up = this.ellipsoid.geodeticSurfaceNormal(this.positionWC, Scratch.scratchUp);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
this.setView({
|
|
312
|
+
orientation: {
|
|
313
|
+
direction: direction,
|
|
314
|
+
up: up,
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 相机看向指定的世界坐标位置。
|
|
322
|
+
* @param {Cartesian3} position 目标位置(世界坐标)。
|
|
323
|
+
* @memberof Camera
|
|
324
|
+
*/
|
|
325
|
+
Camera.prototype.lookAtPosition = function (position) {
|
|
326
|
+
|
|
327
|
+
Check.typeOf.object('position', position);
|
|
328
|
+
position = parseToCartesian3(position, Scratch.scratchPositionWC, false);
|
|
329
|
+
|
|
330
|
+
const direction = Cartesian3.subtract(position, this.positionWC, Scratch.scratchDirection);
|
|
331
|
+
|
|
332
|
+
this.lookAtDirection(direction);
|
|
333
|
+
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 相机看向指定的地理坐标位置。
|
|
338
|
+
* @param {Geographic} geographic 目标地理坐标。
|
|
339
|
+
* @memberof Camera
|
|
340
|
+
*/
|
|
341
|
+
Camera.prototype.lookAtGeographic = function (geographic) {
|
|
342
|
+
|
|
343
|
+
Check.typeOf.object('geographic', geographic);
|
|
344
|
+
const position = parseGeographicToCartesian(geographic, Scratch.scratchPositionWC, this.ellipsoid);
|
|
345
|
+
|
|
346
|
+
const direction = Cartesian3.subtract(position, this.positionWC, Scratch.scratchDirection);
|
|
347
|
+
|
|
348
|
+
this.lookAtDirection(direction);
|
|
349
|
+
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* 获取相机当前位置沿当前朝向的射线。
|
|
354
|
+
* @param {Ray} [result] 存放结果的 Ray 对象。
|
|
355
|
+
* @returns {Ray} 相机朝向射线。
|
|
356
|
+
* @memberof Camera
|
|
357
|
+
*/
|
|
358
|
+
Camera.prototype.getDirectionRay = function (result = new Ray()) {
|
|
359
|
+
result.origin = this.positionWC;
|
|
360
|
+
result.direction = this.directionWC;
|
|
361
|
+
return result;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
export default Camera;
|
|
365
|
+
export { Camera };
|
|
366
|
+
|