@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
|
+
/**
|
|
2
|
+
* 把数字、字符串或数组/对象解析为翻滚角(roll)数值。
|
|
3
|
+
* @param {number|string|Array|object} value 待解析的值,支持第 2 个分量表示的数组或含 roll/x/Roll 字段的对象
|
|
4
|
+
* @returns {number} 解析后的翻滚角,无法解析时返回 0
|
|
5
|
+
*/
|
|
6
|
+
function parseRoll(value) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return 0;
|
|
9
|
+
else if (typeof value === 'number')
|
|
10
|
+
return value;
|
|
11
|
+
else if (typeof value === 'string')
|
|
12
|
+
return parseFloat(value);
|
|
13
|
+
else if (value[2] !== undefined)
|
|
14
|
+
return value[2];
|
|
15
|
+
else if (value.roll !== undefined)
|
|
16
|
+
return value.roll;
|
|
17
|
+
else if (value.x !== undefined)
|
|
18
|
+
return value.x;
|
|
19
|
+
else if (value.Roll !== undefined)
|
|
20
|
+
return value.Roll;
|
|
21
|
+
else
|
|
22
|
+
return 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default parseRoll;
|
|
26
|
+
export { parseRoll };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import getValidValue from "@lijuhong1981/jscheck/src/getValidValue.js";
|
|
2
|
+
import { defined, HeadingPitchRoll, Matrix3, Quaternion } from "cesium";
|
|
3
|
+
import Scratch from "../utils/Scratch.js";
|
|
4
|
+
import parseEulerToHeadingPitchRoll from "./parseEulerToHeadingPitchRoll.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 把多种旋转表示解析为 {@link HeadingPitchRoll} 对象。
|
|
8
|
+
* @param {HeadingPitchRoll|Quaternion|Matrix3|Array|object} value 待解析的旋转值,支持 HeadingPitchRoll、四元数、旋转矩阵、欧拉角数组或对象
|
|
9
|
+
* @param {HeadingPitchRoll} [result] 用于存储结果的可选对象
|
|
10
|
+
* @param {boolean} [isDegrees] 输入是否为角度制,为 true 时按角度解析
|
|
11
|
+
* @returns {HeadingPitchRoll} 解析后的 HeadingPitchRoll
|
|
12
|
+
*/
|
|
13
|
+
function parseRotationToHeadingPitchRoll(value, result, isDegrees) {
|
|
14
|
+
if (value instanceof HeadingPitchRoll) {
|
|
15
|
+
if (result && value !== result)
|
|
16
|
+
return HeadingPitchRoll.clone(value, result);
|
|
17
|
+
else
|
|
18
|
+
return value;
|
|
19
|
+
} else if (value instanceof Quaternion)
|
|
20
|
+
return HeadingPitchRoll.fromQuaternion(value, result);
|
|
21
|
+
else if (value instanceof Matrix3) {
|
|
22
|
+
value = Quaternion.fromRotationMatrix(value, Scratch.scratchQuaternion);
|
|
23
|
+
return HeadingPitchRoll.fromQuaternion(value, result);
|
|
24
|
+
} else if (defined(value.heading) || defined(value.yaw)) {
|
|
25
|
+
if (isDegrees)
|
|
26
|
+
return HeadingPitchRoll.fromDegrees(getValidValue(value.heading, value.yaw), value.pitch, value.roll, result);
|
|
27
|
+
else
|
|
28
|
+
return HeadingPitchRoll.fromRadians(getValidValue(value.heading, value.yaw), value.pitch, value.roll, result);
|
|
29
|
+
} else if (Array.isArray(value)) {
|
|
30
|
+
if (isDegrees)
|
|
31
|
+
return HeadingPitchRoll.fromDegrees(value[0], value[1], value[2], result);
|
|
32
|
+
else
|
|
33
|
+
return HeadingPitchRoll.fromRadians(value[0], value[1], value[2], result);
|
|
34
|
+
} else {
|
|
35
|
+
return parseEulerToHeadingPitchRoll(value, result, isDegrees);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default parseRotationToHeadingPitchRoll;
|
|
40
|
+
export { parseRotationToHeadingPitchRoll };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Matrix3 } from "cesium";
|
|
2
|
+
import Scratch from "../utils/Scratch.js";
|
|
3
|
+
import parseRotationToHeadingPitchRoll from "./parseRotationToHeadingPitchRoll.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把多种旋转表示解析为 3x3 旋转矩阵({@link Matrix3})。
|
|
7
|
+
* @param {Matrix3|HeadingPitchRoll|Quaternion|Array|object} value 待解析的旋转值
|
|
8
|
+
* @param {Matrix3} [result] 用于存储结果的可选对象
|
|
9
|
+
* @param {boolean} [isDegrees] 输入是否为角度制,为 true 时按角度解析
|
|
10
|
+
* @returns {Matrix3} 解析后的旋转矩阵
|
|
11
|
+
*/
|
|
12
|
+
function parseRotationToMatrix3(value, result, isDegrees) {
|
|
13
|
+
if (value instanceof Matrix3) {
|
|
14
|
+
if (result && value !== result)
|
|
15
|
+
return Matrix3.clone(value, result);
|
|
16
|
+
else
|
|
17
|
+
return value;
|
|
18
|
+
} else {
|
|
19
|
+
const hpr = parseRotationToHeadingPitchRoll(value, Scratch.scratchHeadingPitchRoll, isDegrees);
|
|
20
|
+
return Matrix3.fromHeadingPitchRoll(hpr, result);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default parseRotationToMatrix3;
|
|
25
|
+
export { parseRotationToMatrix3 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defined, Quaternion } from "cesium";
|
|
2
|
+
import Scratch from "../utils/Scratch.js";
|
|
3
|
+
import parseRotationToHeadingPitchRoll from "./parseRotationToHeadingPitchRoll.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把多种旋转表示解析为四元数({@link Quaternion})。
|
|
7
|
+
* @param {Quaternion|HeadingPitchRoll|Matrix3|Array|object} value 待解析的旋转值,未定义时返回单位四元数
|
|
8
|
+
* @param {Quaternion} [result] 用于存储结果的可选对象
|
|
9
|
+
* @param {boolean} [isDegrees] 输入是否为角度制,为 true 时按角度解析
|
|
10
|
+
* @returns {Quaternion} 解析后的四元数
|
|
11
|
+
*/
|
|
12
|
+
function parseRotationToQuaternion(value, result, isDegrees) {
|
|
13
|
+
if (!defined(value))
|
|
14
|
+
return Quaternion.IDENTITY.clone(result);
|
|
15
|
+
else if (value instanceof Quaternion) {
|
|
16
|
+
if (result && value !== result)
|
|
17
|
+
return Quaternion.clone(value, result);
|
|
18
|
+
else
|
|
19
|
+
return value;
|
|
20
|
+
} else {
|
|
21
|
+
const hpr = parseRotationToHeadingPitchRoll(value, Scratch.scratchHeadingPitchRoll, isDegrees);
|
|
22
|
+
return Quaternion.fromHeadingPitchRoll(hpr, result);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default parseRotationToQuaternion;
|
|
27
|
+
export { parseRotationToQuaternion };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ShadowMode } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把字符串或数字解析为 Cesium 的 {@link ShadowMode} 枚举值。
|
|
5
|
+
* @param {string|number} value 待解析的值,字符串包含 'cast' 返回 CAST_ONLY、'receive' 返回 RECEIVE_ONLY、'enable' 返回 ENABLED
|
|
6
|
+
* @returns {ShadowMode} 解析后的 ShadowMode
|
|
7
|
+
*/
|
|
8
|
+
function parseShadowMode(value) {
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
value = value.toLowerCase();
|
|
11
|
+
if (value.match('cast'))
|
|
12
|
+
return ShadowMode.CAST_ONLY;
|
|
13
|
+
else if (value.match('receive'))
|
|
14
|
+
return ShadowMode.RECEIVE_ONLY;
|
|
15
|
+
else if (value.match('enable'))
|
|
16
|
+
return ShadowMode.ENABLED;
|
|
17
|
+
else
|
|
18
|
+
return ShadowMode.DISABLED;
|
|
19
|
+
} else if (typeof value === 'number')
|
|
20
|
+
return value;
|
|
21
|
+
else
|
|
22
|
+
return ShadowMode.DISABLED;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default parseShadowMode;
|
|
26
|
+
export { parseShadowMode };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BoundingRectangle, DeveloperError } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把数组或对象解析为包围矩形({@link BoundingRectangle})。
|
|
5
|
+
* @param {BoundingRectangle|Array|object} value 待解析的值
|
|
6
|
+
* @param {BoundingRectangle} [result] 用于存储结果的可选对象
|
|
7
|
+
* @returns {BoundingRectangle} 解析后的包围矩形
|
|
8
|
+
*/
|
|
9
|
+
function parseToBoundingRectangle(value, result) {
|
|
10
|
+
if (value instanceof BoundingRectangle) {
|
|
11
|
+
if (result && value !== result) {
|
|
12
|
+
BoundingRectangle.clone(value, result);
|
|
13
|
+
return result;
|
|
14
|
+
} else
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (result === undefined)
|
|
19
|
+
result = new BoundingRectangle();
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
BoundingRectangle.unpack(value, 0, result);
|
|
23
|
+
} else if (typeof value === 'object') {
|
|
24
|
+
BoundingRectangle.clone(value, result);
|
|
25
|
+
} else {
|
|
26
|
+
throw new DeveloperError('can not parse the ' + value + ' to BoundingRectangle.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default parseToBoundingRectangle;
|
|
33
|
+
export { parseToBoundingRectangle };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import getValidValue from '@lijuhong1981/jscheck/src/getValidValue.js';
|
|
2
|
+
import parseNumber from '@lijuhong1981/jsmath/src/parseNumber.js';
|
|
3
|
+
import { Cartesian2, Check, defined, DeveloperError } from "cesium";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把数字、字符串或数组/对象解析为二维笛卡尔坐标({@link Cartesian2})。
|
|
7
|
+
* @param {Cartesian2|number|string|Array|object} value 待解析的值,支持 [x,y] 数组或含 x/y 字段的对象
|
|
8
|
+
* @param {Cartesian2} [result] 用于存储结果的可选对象
|
|
9
|
+
* @param {number} [defaultValue=0.0] 缺省分量的默认值
|
|
10
|
+
* @returns {Cartesian2} 解析后的二维笛卡尔坐标
|
|
11
|
+
*/
|
|
12
|
+
function parseToCartesian2(value, result, defaultValue = 0.0) {
|
|
13
|
+
if (!defined(value)) {
|
|
14
|
+
if (typeof defaultValue === 'number')
|
|
15
|
+
return Cartesian2.fromElements(defaultValue, defaultValue, result);
|
|
16
|
+
else
|
|
17
|
+
throw new DeveloperError('value undefined.');
|
|
18
|
+
} else if (value instanceof Cartesian2) {
|
|
19
|
+
if (result && value !== result)
|
|
20
|
+
return value.clone(result);
|
|
21
|
+
else
|
|
22
|
+
return value;
|
|
23
|
+
} else if (typeof value === 'number' || typeof value === 'string') {
|
|
24
|
+
value = parseNumber(value);
|
|
25
|
+
return Cartesian2.fromElements(value, value, result);
|
|
26
|
+
}
|
|
27
|
+
const x = getValidValue(value[0], value.x, defaultValue);
|
|
28
|
+
Check.typeOf.number('x', x);
|
|
29
|
+
const y = getValidValue(value[1], value.y, defaultValue);
|
|
30
|
+
Check.typeOf.number('y', y);
|
|
31
|
+
return Cartesian2.fromElements(x, y, result);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default parseToCartesian2;
|
|
35
|
+
export { parseToCartesian2 };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import getValidValue from '@lijuhong1981/jscheck/src/getValidValue.js';
|
|
2
|
+
import parseNumber from '@lijuhong1981/jsmath/src/parseNumber.js';
|
|
3
|
+
import { Cartesian3, Check, defined, DeveloperError } from "cesium";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把数字、字符串或数组/对象解析为三维笛卡尔坐标({@link Cartesian3})。
|
|
7
|
+
* @param {Cartesian3|number|string|Array|object} value 待解析的值,支持 [x,y,z] 数组或含 x/y/z 字段的对象
|
|
8
|
+
* @param {Cartesian3} [result] 用于存储结果的可选对象
|
|
9
|
+
* @param {number} [defaultValue=0.0] 缺省分量的默认值
|
|
10
|
+
* @returns {Cartesian3} 解析后的三维笛卡尔坐标
|
|
11
|
+
*/
|
|
12
|
+
function parseToCartesian3(value, result, defaultValue = 0.0) {
|
|
13
|
+
if (!defined(value)) {
|
|
14
|
+
if (typeof defaultValue === 'number')
|
|
15
|
+
return Cartesian3.fromElements(defaultValue, defaultValue, defaultValue, result);
|
|
16
|
+
else
|
|
17
|
+
throw new DeveloperError('value undefined.');
|
|
18
|
+
} else if (value instanceof Cartesian3) {
|
|
19
|
+
if (result && value !== result)
|
|
20
|
+
return value.clone(result);
|
|
21
|
+
else
|
|
22
|
+
return value;
|
|
23
|
+
} else if (typeof value === 'number' || typeof value === 'string') {
|
|
24
|
+
value = parseNumber(value);
|
|
25
|
+
return Cartesian3.fromElements(value, value, value, result);
|
|
26
|
+
}
|
|
27
|
+
const x = getValidValue(value[0], value.x, defaultValue);
|
|
28
|
+
Check.typeOf.number('x', x);
|
|
29
|
+
const y = getValidValue(value[1], value.y, defaultValue);
|
|
30
|
+
Check.typeOf.number('y', y);
|
|
31
|
+
const z = getValidValue(value[2], value.z, defaultValue);
|
|
32
|
+
Check.typeOf.number('z', z);
|
|
33
|
+
return Cartesian3.fromElements(x, y, z, result);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default parseToCartesian3;
|
|
37
|
+
export { parseToCartesian3 };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Check } from "cesium";
|
|
2
|
+
import parseToCartesian3 from "./parseToCartesian3.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 把数组批量解析为三维笛卡尔坐标数组({@link Cartesian3})。
|
|
6
|
+
* @param {Array} array 待解析的数组
|
|
7
|
+
* @param {Array} [result=[]] 用于存储结果的数组
|
|
8
|
+
* @param {number} [defaultValue] 缺省分量的默认值
|
|
9
|
+
* @returns {Array} 解析后的三维笛卡尔坐标数组
|
|
10
|
+
*/
|
|
11
|
+
function parseToCartesian3Array(array, result = [], defaultValue) {
|
|
12
|
+
Check.typeOf.array('array', array);
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < array.length; i++) {
|
|
15
|
+
result[i] = parseToCartesian3(array[i], result[i], defaultValue);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default parseToCartesian3Array;
|
|
21
|
+
export { parseToCartesian3Array };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import getValidValue from '@lijuhong1981/jscheck/src/getValidValue.js';
|
|
2
|
+
import parseNumber from '@lijuhong1981/jsmath/src/parseNumber.js';
|
|
3
|
+
import { Cartesian4, Check, defined, DeveloperError } from "cesium";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把数字、字符串或数组/对象解析为四维笛卡尔坐标({@link Cartesian4})。
|
|
7
|
+
* @param {Cartesian4|number|string|Array|object} value 待解析的值,支持 [x,y,z,w] 数组或含 x/y/z/w 字段的对象
|
|
8
|
+
* @param {Cartesian4} [result] 用于存储结果的可选对象
|
|
9
|
+
* @param {number} [defaultValue=0.0] 缺省分量的默认值
|
|
10
|
+
* @returns {Cartesian4} 解析后的四维笛卡尔坐标
|
|
11
|
+
*/
|
|
12
|
+
function parseToCartesian4(value, result, defaultValue = 0.0) {
|
|
13
|
+
if (!defined(value)) {
|
|
14
|
+
if (typeof defaultValue === 'number')
|
|
15
|
+
return Cartesian4.fromElements(defaultValue, defaultValue, defaultValue, defaultValue, result);
|
|
16
|
+
else
|
|
17
|
+
throw new DeveloperError('value undefined.');
|
|
18
|
+
} else if (value instanceof Cartesian4) {
|
|
19
|
+
if (result && value !== result)
|
|
20
|
+
return value.clone(result);
|
|
21
|
+
else
|
|
22
|
+
return value;
|
|
23
|
+
} else if (typeof value === 'number' || typeof value === 'string') {
|
|
24
|
+
value = parseNumber(value);
|
|
25
|
+
return Cartesian4.fromElements(value, value, value, value, result);
|
|
26
|
+
}
|
|
27
|
+
const x = getValidValue(value[0], value.x, defaultValue);
|
|
28
|
+
Check.typeOf.number('x', x);
|
|
29
|
+
const y = getValidValue(value[1], value.y, defaultValue);
|
|
30
|
+
Check.typeOf.number('y', y);
|
|
31
|
+
const z = getValidValue(value[2], value.z, defaultValue);
|
|
32
|
+
Check.typeOf.number('z', z);
|
|
33
|
+
const w = getValidValue(value[3], value.w, defaultValue);
|
|
34
|
+
Check.typeOf.number('w', w);
|
|
35
|
+
return Cartesian4.fromElements(x, y, z, w, result);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default parseToCartesian4;
|
|
39
|
+
export { parseToCartesian4 };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Cartesian3, Cartographic } from "cesium";
|
|
2
|
+
import Geographic from "../additions/Geographic.js";
|
|
3
|
+
import { parseHeight } from "./parseAltitude.js";
|
|
4
|
+
import parseLatitude from "./parseLatitude.js";
|
|
5
|
+
import parseLongitude from "./parseLongitude.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 把地理坐标解析为 {@link Cartographic} 对象,输入按经度/纬度角度制处理。
|
|
9
|
+
* @param {Cartographic|Geographic|Cartesian3|Array|object} value 待解析的值
|
|
10
|
+
* @param {Cartographic} [result] 用于存储结果的可选对象
|
|
11
|
+
* @param {Ellipsoid} [ellipsoid] 参考椭球体
|
|
12
|
+
* @returns {Cartographic} 解析后的 Cartographic
|
|
13
|
+
*/
|
|
14
|
+
function parseToCartographic(value, result, ellipsoid) {
|
|
15
|
+
if (value instanceof Cartographic) {
|
|
16
|
+
if (result && value !== result)
|
|
17
|
+
return value.clone(result);
|
|
18
|
+
else
|
|
19
|
+
return value;
|
|
20
|
+
} else if (value instanceof Geographic)
|
|
21
|
+
return value.toCartographic(result);
|
|
22
|
+
else if (value instanceof Cartesian3)
|
|
23
|
+
return value.toCartographic(ellipsoid, result);
|
|
24
|
+
const longitude = parseLongitude(value);
|
|
25
|
+
const latitude = parseLatitude(value);
|
|
26
|
+
const height = parseHeight(value);
|
|
27
|
+
return Cartographic.fromDegrees(longitude, latitude, height, result);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default parseToCartographic;
|
|
31
|
+
export { parseToCartographic };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Cartesian3, Cartesian4, Check, Color, DeveloperError } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把字符串、数字、笛卡尔坐标或数组解析为颜色({@link Color})。
|
|
5
|
+
* @param {Color|string|number|Cartesian3|Cartesian4|Array} value 待解析的值,字符串按 CSS 颜色、数字按 RGBA 解析
|
|
6
|
+
* @param {Color} [result] 用于存储结果的可选对象
|
|
7
|
+
* @returns {Color} 解析后的颜色
|
|
8
|
+
*/
|
|
9
|
+
function parseToColor(value, result) {
|
|
10
|
+
Check.defined('value', value);
|
|
11
|
+
if (value instanceof Color) {
|
|
12
|
+
if (result && value !== result)
|
|
13
|
+
return value.clone(result);
|
|
14
|
+
else
|
|
15
|
+
return value;
|
|
16
|
+
} else if (typeof value === 'string') {
|
|
17
|
+
return Color.fromCssColorString(value, result);
|
|
18
|
+
} else if (typeof value === 'number') {
|
|
19
|
+
return Color.fromRgba(value, result);
|
|
20
|
+
} else if (value instanceof Cartesian3) {
|
|
21
|
+
return Color.fromCartesian3(value, result);
|
|
22
|
+
} else if (value instanceof Cartesian4) {
|
|
23
|
+
return Color.fromCartesian4(value, result);
|
|
24
|
+
} else if (Array.isArray(value)) {
|
|
25
|
+
return Color.unpack(value, 0, result);
|
|
26
|
+
} else {
|
|
27
|
+
console.error('unsupported color value:', value);
|
|
28
|
+
throw new DeveloperError('unsupported color value:' + value);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default parseToColor;
|
|
33
|
+
export { parseToColor };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DeveloperError, DistanceDisplayCondition } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把数组、对象、数字或字符串解析为 {@link DistanceDisplayCondition} 对象。
|
|
5
|
+
* @param {DistanceDisplayCondition|Array|object|number|string} value 待解析的值,数字/字符串时以 near=0、该值为 far 处理
|
|
6
|
+
* @param {DistanceDisplayCondition} [result] 用于存储结果的可选对象
|
|
7
|
+
* @returns {DistanceDisplayCondition} 解析后的距离显示条件
|
|
8
|
+
*/
|
|
9
|
+
function parseToDistanceDisplayCondition(value, result) {
|
|
10
|
+
if (!value) return;
|
|
11
|
+
|
|
12
|
+
if (value instanceof DistanceDisplayCondition) {
|
|
13
|
+
if (result && value !== result) {
|
|
14
|
+
DistanceDisplayCondition.clone(value, result);
|
|
15
|
+
return result;
|
|
16
|
+
} else
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (result === undefined)
|
|
21
|
+
result = new DistanceDisplayCondition();
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
DistanceDisplayCondition.unpack(value, 0, result);
|
|
25
|
+
} else if (typeof value === 'object') {
|
|
26
|
+
DistanceDisplayCondition.clone(value, result);
|
|
27
|
+
} else if (typeof value === 'number') {
|
|
28
|
+
result.near = 0;
|
|
29
|
+
result.far = value;
|
|
30
|
+
} else if (typeof value === 'string') {
|
|
31
|
+
result.near = 0;
|
|
32
|
+
result.far = parseFloat(value);
|
|
33
|
+
} else {
|
|
34
|
+
throw new DeveloperError('can not parse the ' + value + ' to DistanceDisplayCondition.');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default parseToDistanceDisplayCondition;
|
|
41
|
+
export { parseToDistanceDisplayCondition };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Cartesian3, Cartographic } from "cesium";
|
|
2
|
+
import Geographic from "../additions/Geographic.js";
|
|
3
|
+
import parseAltitude from "./parseAltitude.js";
|
|
4
|
+
import parseLatitude from "./parseLatitude.js";
|
|
5
|
+
import parseLongitude from "./parseLongitude.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 把地理坐标解析为 {@link Geographic} 对象,输入按角度制处理。
|
|
9
|
+
* @param {Geographic|Cartographic|Cartesian3|Array|object} value 待解析的值
|
|
10
|
+
* @param {Geographic} [result] 用于存储结果的可选对象
|
|
11
|
+
* @param {Ellipsoid} [ellipsoid] 参考椭球体
|
|
12
|
+
* @returns {Geographic} 解析后的 Geographic
|
|
13
|
+
*/
|
|
14
|
+
function parseToGeographic(value, result, ellipsoid) {
|
|
15
|
+
if (value instanceof Geographic) {
|
|
16
|
+
if (result && value !== result)
|
|
17
|
+
return value.clone(result);
|
|
18
|
+
else
|
|
19
|
+
return value;
|
|
20
|
+
} else if (value instanceof Cartographic)
|
|
21
|
+
return value.toGeographic(result);
|
|
22
|
+
else if (value instanceof Cartesian3)
|
|
23
|
+
return value.toGeographic(ellipsoid, result);
|
|
24
|
+
const longitude = parseLongitude(value);
|
|
25
|
+
const latitude = parseLatitude(value);
|
|
26
|
+
const altitude = parseAltitude(value);
|
|
27
|
+
return Geographic.fromDegrees(longitude, latitude, altitude, result);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default parseToGeographic;
|
|
31
|
+
export { parseToGeographic };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Math as CesiumMath, Check, HeadingPitchRange } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把数组或对象解析为 {@link HeadingPitchRange} 对象。
|
|
5
|
+
* @param {HeadingPitchRange|Array|object} value 待解析的值,支持 [heading,pitch,range] 数组或含 heading/pitch/range 字段的对象
|
|
6
|
+
* @param {HeadingPitchRange} [result=new HeadingPitchRange()] 用于存储结果的可选对象
|
|
7
|
+
* @param {boolean} [isDegrees=true] 输入是否为角度制,为 true 时按角度解析
|
|
8
|
+
* @returns {HeadingPitchRange} 解析后的 HeadingPitchRange
|
|
9
|
+
*/
|
|
10
|
+
function parseToHeadingPitchRange(value, result = new HeadingPitchRange(), isDegrees = true) {
|
|
11
|
+
Check.defined('value', value);
|
|
12
|
+
|
|
13
|
+
if (value instanceof HeadingPitchRange) {
|
|
14
|
+
if (value !== result) {
|
|
15
|
+
HeadingPitchRange.clone(value, result);
|
|
16
|
+
return result;
|
|
17
|
+
} else
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
if (isDegrees) {
|
|
23
|
+
result.heading = CesiumMath.toRadians(value[0]);
|
|
24
|
+
result.pitch = CesiumMath.toRadians(value[1]);
|
|
25
|
+
} else {
|
|
26
|
+
result.heading = value[0];
|
|
27
|
+
result.pitch = value[1];
|
|
28
|
+
}
|
|
29
|
+
result.range = value[2];
|
|
30
|
+
} else if (typeof value === 'object') {
|
|
31
|
+
if (isDegrees) {
|
|
32
|
+
result.heading = CesiumMath.toRadians(value.heading ?? value.yaw);
|
|
33
|
+
result.pitch = CesiumMath.toRadians(value.pitch);
|
|
34
|
+
} else {
|
|
35
|
+
result.heading = value.heading ?? value.yaw;
|
|
36
|
+
result.pitch = value.pitch;
|
|
37
|
+
}
|
|
38
|
+
result.range = value.range;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default parseToHeadingPitchRange;
|
|
45
|
+
export { parseToHeadingPitchRange };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { JulianDate } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把日期字符串、数字时间戳、Date 或 {@link JulianDate} 解析为儒略日期。
|
|
5
|
+
* @param {JulianDate|string|number|Date} value 待解析的值
|
|
6
|
+
* @param {JulianDate} [result] 用于存储结果的可选对象
|
|
7
|
+
* @returns {JulianDate} 解析后的儒略日期
|
|
8
|
+
*/
|
|
9
|
+
function parseToJulianDate(value, result) {
|
|
10
|
+
if (value instanceof JulianDate) {
|
|
11
|
+
if (result && value !== result)
|
|
12
|
+
return JulianDate.clone(value, result);
|
|
13
|
+
else
|
|
14
|
+
return value;
|
|
15
|
+
} else if (typeof value === 'string' || typeof value === 'number') {
|
|
16
|
+
return JulianDate.fromDate(new Date(value), result);
|
|
17
|
+
} else if (value instanceof Date) {
|
|
18
|
+
return JulianDate.fromDate(value, result);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default parseToJulianDate;
|
|
23
|
+
export { parseToJulianDate };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DeveloperError, NearFarScalar } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把数组或对象解析为 {@link NearFarScalar} 对象。
|
|
5
|
+
* @param {NearFarScalar|Array|object} value 待解析的值
|
|
6
|
+
* @param {NearFarScalar} [result] 用于存储结果的可选对象
|
|
7
|
+
* @returns {NearFarScalar} 解析后的 NearFarScalar
|
|
8
|
+
*/
|
|
9
|
+
function parseToNearFarScalar(value, result) {
|
|
10
|
+
if (value instanceof NearFarScalar) {
|
|
11
|
+
if (result && value !== result) {
|
|
12
|
+
NearFarScalar.clone(value, result);
|
|
13
|
+
return result;
|
|
14
|
+
} else
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (result === undefined)
|
|
19
|
+
result = new NearFarScalar();
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
NearFarScalar.unpack(value, 0, result);
|
|
23
|
+
} else if (typeof value === 'object') {
|
|
24
|
+
NearFarScalar.clone(value, result);
|
|
25
|
+
} else {
|
|
26
|
+
throw new DeveloperError('can not parse the ' + value + ' to NearFarScalar.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default parseToNearFarScalar;
|
|
33
|
+
export { parseToNearFarScalar };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import getValidValue from "@lijuhong1981/jscheck/src/getValidValue.js";
|
|
2
|
+
import { Cartesian3, Cartesian4, Check, defined, Plane } from "cesium";
|
|
3
|
+
import Scratch from "../utils/Scratch.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把对象或数组解析为平面({@link Plane})。
|
|
7
|
+
* @param {Plane|Array|object} value 待解析的值,支持 [x,y,z,w] 数组、含 point/normal 或 normal/distance 字段的对象
|
|
8
|
+
* @param {Plane} [result] 用于存储结果的可选对象
|
|
9
|
+
* @returns {Plane} 解析后的平面
|
|
10
|
+
*/
|
|
11
|
+
function parseToPlane(value, result) {
|
|
12
|
+
Check.defined('value', value);
|
|
13
|
+
if (value instanceof Plane) {
|
|
14
|
+
if (result && value !== result)
|
|
15
|
+
return Plane.clone(value, result);
|
|
16
|
+
else
|
|
17
|
+
return value;
|
|
18
|
+
} else if (defined(value.point) && defined(value.normal)) {
|
|
19
|
+
return Plane.fromPointNormal(value.point, value.normal, result);
|
|
20
|
+
} else if (defined(value.normal) && defined(value.distance)) {
|
|
21
|
+
if (!result)
|
|
22
|
+
result = new Plane();
|
|
23
|
+
Cartesian3.clone(value.normal, result.normal);
|
|
24
|
+
result.distance = value.distance;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const x = getValidValue(value[0], value.x);
|
|
29
|
+
const y = getValidValue(value[1], value.y);
|
|
30
|
+
const z = getValidValue(value[2], value.z);
|
|
31
|
+
const w = getValidValue(value[3], value.w);
|
|
32
|
+
const coefficients = Cartesian4.fromElements(x, y, z, w, Scratch.scratchCartesian4);
|
|
33
|
+
return Plane.fromCartesian4(coefficients, result);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default parseToPlane;
|
|
37
|
+
export { parseToPlane };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Cartesian3, defined, DeveloperError, PolygonHierarchy } from "cesium";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把洞信息解析为 {@link PolygonHierarchy} 数组。
|
|
5
|
+
* @param {PolygonHierarchy|Array|object} holes 待解析的洞信息
|
|
6
|
+
* @param {Ellipsoid} [ellipsoid] 参考椭球体
|
|
7
|
+
* @returns {Array} 解析后的 PolygonHierarchy 数组
|
|
8
|
+
*/
|
|
9
|
+
function parseHoles(holes, ellipsoid) {
|
|
10
|
+
if (holes instanceof PolygonHierarchy)
|
|
11
|
+
return [holes];
|
|
12
|
+
else if (Array.isArray(holes)) {
|
|
13
|
+
if (holes[0] instanceof Cartesian3 || defined(holes[0].x))
|
|
14
|
+
return [parseToPolygonHierarchy(holes, undefined, ellipsoid)];
|
|
15
|
+
else if (holes[0] instanceof PolygonHierarchy)
|
|
16
|
+
return holes;
|
|
17
|
+
const result = [];
|
|
18
|
+
for (let i = 0; i < holes.length; i++) {
|
|
19
|
+
const hierarchy = parseToPolygonHierarchy(holes[i].positions, holes[i].holes, ellipsoid);
|
|
20
|
+
result.push(hierarchy);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
} else if (typeof holes === 'object') {
|
|
24
|
+
const result = [];
|
|
25
|
+
const hierarchy = parseToPolygonHierarchy(holes.positions, holes.holes, ellipsoid);
|
|
26
|
+
result.push(hierarchy);
|
|
27
|
+
return result;
|
|
28
|
+
} else {
|
|
29
|
+
throw new DeveloperError('unsupported holes: ' + holes);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 把顶点坐标与洞信息解析为多边形层级({@link PolygonHierarchy})。
|
|
35
|
+
* @param {Array} positions 多边形顶点坐标
|
|
36
|
+
* @param {PolygonHierarchy|Array|object} [holes] 洞信息
|
|
37
|
+
* @param {Ellipsoid} [ellipsoid] 参考椭球体
|
|
38
|
+
* @returns {PolygonHierarchy} 解析后的多边形层级
|
|
39
|
+
*/
|
|
40
|
+
function parseToPolygonHierarchy(positions, holes, ellipsoid) {
|
|
41
|
+
if (defined(holes)) {
|
|
42
|
+
holes = parseHoles(holes, ellipsoid);
|
|
43
|
+
}
|
|
44
|
+
return new PolygonHierarchy(positions, holes);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default parseToPolygonHierarchy;
|
|
48
|
+
export { parseHoles, parseToPolygonHierarchy };
|