1. Util
通用工具类
1.1. 方法
1.1.1. Util.generateUUID() ⇒ String
生成一个UUID
Returns : String
-
返回36位的uuid通用唯一识别码
Example
let str = BOSGeo.Util.generateUUID();
1.1.2. Util.cartesianToDegrees(ellipsoid, position) ⇒ Cartesian3
世界坐标转经纬度
Returns : Cartesian3
-
经纬度坐标 Cartesian3(lng, lat, alt)
Param | Type | Description |
---|---|---|
ellipsoid | Ellipsoid |
地球椭球体 |
position | Cartesian3 |
世界坐标 |
Example
let poisition = BOSGeo.Util.cartesianToDegrees(ellipsoid, position);
1.1.3. Util.computeVertex(start, end, arcFactor) ⇒ Array
计算顶点
Returns : Array
-
顶点
Param | Type | Description |
---|---|---|
start | Object |
起点,包含x,y,z |
end | Object |
终点,包含x,y,z |
arcFactor | Number |
因子 |
Example
let coordinates = BOSGeo.Util.computeVertex(start, end, arcFactor);
1.1.4. Util.isCoordShun(coords) ⇒ *
判断多边形点是否顺逆时针
Returns : *
-
是否顺时针
Param | Type | Description |
---|---|---|
coords | Array |
多边形点 |
Example
let res = BOSGeo.Util.isCoordShun(coords);
1.1.5. Util.computeHeading(posCart1, posCart2) ⇒ Number
计算两点的方向(航偏角)
Returns: Number
-
两点之间的方向
Param | Type | Description |
---|---|---|
posCart1 | Cartesian3 |
点1 |
posCart2 | Cartesian3 |
点2 |
Example
let posCart1 = new BOSGeo.Cartesian3.fromDegrees(112,23.2,10)
let posCart2 = new BOSGeo.Cartesian3.fromDegrees(112,23.1,10)
let heading = BOSGeo.Util.computeHeading(posCart1,posCart2)
1.1.6. Util.computeOrientation(position, headingDegree) ⇒ Object
改变模型的偏航角
Returns: Object
-
模型方向
Param | Type | Description |
---|---|---|
position | Cartesian3 |
位置 |
headingDegree | Number |
航偏角 |
Example
let posCart1 = new BOSGeo.Cartesian3.fromDegrees(112,23.2,10)
let posCart2 = new BOSGeo.Cartesian3.fromDegrees(112,23.1,10)
let heading = BOSGeo.Util.computeHeading(posCart1,posCart2)
let orientation = BOSGeo.Util.computeOrientation(posCart1,heading)
1.1.7. Util.calculatingTargetPoints(viewer, lon, lat, height, direction, radius) ⇒ Object
根据距离方向和观察点计算目标点(109.878321 19.963493 82 0 500)
Returns : Object
-
目标点
Param | Type | Description |
---|---|---|
viewer | Object |
geomap.viewer |
lon | Number |
经度 |
lat | Number |
维度 |
height | Number |
高度 |
direction | Number |
方向 |
radius | Number |
可视距离 |
Example
let poi = BOSGeo.Util.calculatingTargetPoints(viewer, lon, lat, height, direction, radius);
1.1.8. Util.getNorthPointByDistance(position, distance) ⇒ Cartesian3
计算一个点正北方向x米的另一个点的坐标
Returns : Cartesian3
-
结果坐标
Param | Type | Description |
---|---|---|
position | Cartesian3 |
坐标点 |
distance | Number |
距离 |
Example
let res = BOSGeo.Util.getNorthPointByDistance(position, distance);
1.1.9. Util.convex(p:顶点数组(数组对象)) ⇒ Number
判断是否是凸多边形函数
Returns : Number
-
1:凸集;-1:凹集;0:曲线不符合
Param | Type |
---|---|
p:顶点数组(数组对象) | Array |
Example
let res = BOSGeo.Util.convex(p);
1.1.10. Util.deepClone(target) ⇒ Object
定义一个深拷贝函数 接收目标target参数
Returns : Object
-
拷贝结果
Param | Type | Description |
---|---|---|
target | Object |
拷贝对象 |
Example
let res = BOSGeo.Util.deepClone(target);
1.1.11. Util.parseFloatWithDot(value, [accuracy]) ⇒ String
将数值转换为带小数点的字符串(用于着色器)
Param | Type | Default | Description |
---|---|---|---|
value | Number |
待转换的数值 |
|
[accuracy] | Number |
3 |
小数点后整数位 |
Example
var str = BOSGeo.Util.parseFloatWithDot(1); // str---0.001
1.1.12. Util.parseFloatArrayWithDot(numberList, [accuracy]) ⇒ Array.<String>
将数值数组转换为带小数点的字符串数组(用于着色器)
Param | Type | Default | Description |
---|---|---|---|
numberList | Array.<Number> |
待转换的数值 |
|
[accuracy] | Number |
8 |
小数点后整数位 |
Example
var str = BOSGeo.Util.parseFloatArrayWithDot([1, 2]); // str---[0.001, 0.002]
1.1.13. Util.removeFromArray(arr, val)
删除数组中指定的某个元素
Param | Type | Description |
---|---|---|
arr | Array |
数组 |
val | Object |
数组中需要被删除的元素 |
Example
//Example 1
var arr = [1, 2, 3]
BOSGeo.Util.removeFromArray(arr, 2)
//Example 2.
var emp = ['abs', 'dsf', 'sdf', 'fd']
BOSGeo.Util.removeFromArray(emp, "abs") *
1.1.14. Util.validate(options)
校验输入的经纬度、方位和缩放参数值
Param | Type | Description |
---|---|---|
options | Object |
包含以下参数的Object对象: |
[options.position] | Array |
经纬度坐标数组; |
[options.rotation] | Array |
包含偏航角、俯仰角和方位角的方位数组; |
[options.scale] | Number |
缩放比例。 |
Example
BOSGeo.Util.validate({position: [181, 23]})
1.1.15. Util.createGradientColors(startColor, endColor, steps, gamma)
获取颜色区域中间的十六位颜色数组
Returns : Array
-
梯度十六位颜色数组
Param | Type | Default | Description |
---|---|---|---|
startColor | String |
十六位起始颜色 |
|
endColor | String |
十六位结束颜色 |
|
[steps] | Number |
20 |
颜色分解次数 |
[gamma] | Number |
1 |
伽马,可理解为透明一点 |
Example
//Example 1
var gradientColors = new BOSGeo.Util.createGradientColors('#00ff00', '#ff0000', 50, 1);
1.1.16. Util.queueExec(fn)
异步互斥执行队列函数
Returns:
函数回调结果
Param | Type | Description |
---|---|---|
fn | function |
函数 |
Example
function async _getThirdParty (){
console.log(1)
}
BOSGeo.Util.queueExec(_getThirdParty).then((SuperMap3D) => {
consloe.log(SuperMap3D);
})
BOSGeo.Util.queueExec(_getThirdParty).then((SuperMap3D) => {
consloe.log(SuperMap3D);
})
1.1.17. Util.computeStraightDistance(startPoint, endPoint) ⇒ Number
计算上两点间直线最短距离
Returns : Number
-
单位:米
Param | Type | Description |
---|---|---|
startPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
endPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
Example
let startPoint = [112, 23, 10];
let endPoint = [112, 24, 20];
let distance = BOSGeo.Util.computeStraightDistance(startPoint, endPoint);
1.1.18. Util.computeSphericalDistance(startPoint, endPoint) ⇒ Number
计算上两点间球面最短距离
Returns : Number
-
单位:米
Param | Type | Description |
---|---|---|
startPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
endPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
Example
let startPoint = [112, 23, 10];
let endPoint = [112, 24, 20];
let distance = BOSGeo.Util.computeSphericalDistance(startPoint, endPoint);
1.1.19. Util.computeGroundDistance(startPoint, endPoint) ⇒ Number
计算上两点间贴地距离
Returns : Number
-
单位:米
Param | Type | Description |
---|---|---|
startPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
endPoint | Cartesian3 | Array.<Number> |
三维笛卡尔坐标,或经纬度和高程的数组 |
Example
let startPoint = [112, 23, 10];
let endPoint = [112, 24, 20];
let distance = BOSGeo.Util.computeGroundDistance(startPoint, endPoint);