new Utils()
Methods
-
static convertColorToZeroToOne(color) → {Array.<Number>}
将以255为最大值的颜色数组转为以1为最大值的颜色数组
-
Parameters:
Name Type Description color
Array.<Number> 以255为最大值的颜色数组 Returns:
Array.<Number> - color 以1为最大值的颜色数组Example
const color = Utils.convertColorToZeroToOne([255,0,0]);//return [1,0,0]
-
static convertGeoJSONCrs(geojson, originopt, destopt) → {Object}
-
Parameters:
Name Type Attributes Default Description geojson
Object GeoJSON数据 origin
string <optional>
'wgs84' 原始坐标系 支持wgs84 gcj020 bd09 dest
string <optional>
'gcj02' 目标坐标系 支持wgs84 gcj020 bd09 Returns:
Object - 转换后的GeoJSON对象 -
static convertLonlatToWebMercator(lonLat) → {Array.<Number>}
经纬度坐标转Web墨卡托投影坐标
-
Parameters:
Name Type Description lonLat
Array.<Number> [经度,纬度] Returns:
Array.<Number> - Web墨卡托投影坐标[x,y]Example
const coords = Utils.convertLonlatToWebMercator([119.5,36.5]); //返回web墨卡托坐标 [12968720.675611112, 4793547.458437541]
-
static convertLonlatToWorld(lonLat, height) → {Array.<Number>}
经纬度转世界坐标
-
Parameters:
Name Type Description lonLat
Array.<Number> [经度,纬度] height
Number 离地高度 默认0 Returns:
Array.<Number> - 世界坐标 [x,y,z] -
static convertWebMercatorToLonlat(mercator) → {Array.<Number>}
墨卡托投影转经纬度坐标
-
Parameters:
Name Type Description mercator
Array.<Number> Web墨卡托坐标 [x,y] Returns:
Array.<Number> - 经纬度坐标 [经度,纬度]Example
const coords = Utils.convertWebMercatorToLonlat([12968720.675611112, 4793547.458437541]); //返回经纬度坐标 [116.5,36.5]
-
static convertWgs84ToGcj02(lonlat) → {Array.<Number>}
wgs84坐标转为gcj02坐标
-
Parameters:
Name Type Description lonlat
Array.<Number> wgs84经纬度坐标 [经度,纬度] Returns:
Array.<Number> - gcj02经纬度坐标 [经度,纬度]Example
const gcj02Coords = Utils.convertWgs84ToGcj02([116.5,39.5]); //返回gcj02坐标 [116.5059564261526, 39.501157091519175]
-
static convertWindowToWorld(windowPosition) → {Array.<Number>}
屏幕坐标转世界坐标
-
Parameters:
Name Type Description windowPosition
Array.<Number> 屏幕坐标[x,y] Returns:
Array.<Number> - 世界坐标 [x,y,z] -
static convertWorldToLonlat(pos) → {Array.<Number>}
世界坐标转经纬度
-
Parameters:
Name Type Description pos
Array.<Number> 世界坐标[x,y,z] Returns:
Array.<Number> - 经纬度坐标(带高度) [经度,纬度,高度] -
static getAnglesFromLonlat(lonlat, azimuthopt, pitchopt) → {Array.<Number>}
根据经纬度和方位角得到可以使物体贴地的旋转信息
-
Parameters:
Name Type Attributes Default Description lonlat
Array.<Number> 经纬度 azimuth
Number <optional>
0 azimuth 方位角 pitch
Number <optional>
0 pitch 物体倾角 Returns:
Array.<Number> - 旋转角度 [x,y,z] -
static getAnglesFromPosition(pos, azimuthopt, pitchopt) → {Array.<Number>}
根据世界坐标和方位角得到可以使物体贴地的旋转信息
-
Parameters:
Name Type Attributes Default Description pos
Array.<Number> 世界坐标 azimuth
Number <optional>
0 azimuth 方位角 pitch
Number <optional>
0 pitch 物体倾角 Returns:
Array.<Number> - 旋转角度 [x,y,z] -
static getAzimuth(lonlat1, lonlat2) → {Number}
计算两点间的方位角
-
Parameters:
Name Type Description lonlat1
Array.<Number> 起点经纬度 lonlat2
Array.<Number> 终点经纬度 Returns:
Number - 方位角 -
static getCenterCoordinates(coordinates) → {Array.<Number>}
获取坐标的中心点
-
Parameters:
Name Type Description coordinates
Array 待求坐标点数组 Returns:
Array.<Number> - [x,y] 中心点坐标 -
static getCenterOfGravityPoint(coordinates) → {Array.<Number>}
获取多边形重心/质心 返回[116.47585641025641, 39.98538461538462]
-
Parameters:
Name Type Description coordinates
Array 多边形经纬度坐标数组 符合GeoJSON 线和面的coordinates数组 Returns:
Array.<Number> - [x,y] 重心点坐标Example
// 返回多边形的重心的经纬度坐标 const center = Utils.getCenterOfGravityPoint([[[116.4757, 39.9851], [116.4755, 39.9852], [116.4761, 39.9857], [116.4762, 39.9856], [116.4757, 39.9851]]]);
-
static getEuclideanDistance(lonlat1, lonlat2) → {Number}
计算两点间的欧式距离(两点直连的距离) 单位:米
-
Parameters:
Name Type Description lonlat1
Array.<Number> 起点经纬度 lonlat2
Array.<Number> 终点经纬度 Returns:
Number - 欧式距离 -
static getExtent(coordinates) → {Extent}
获取坐标的范围(最大最小经纬度)
-
Parameters:
Name Type Description coordinates
Array Returns:
Extent - result -
static getFeatureCollectionExtent(featureCollection) → {Extent}
获取geojson的范围
-
Parameters:
Name Type Description featureCollection
GeoJSONFeatureCollection geojson对象 Returns:
Extent - geojson数据的范围Example
//返回geojson数据的范围 {minX: -73.99995803833008, minY: 40.71805432623303, maxX: -73.98167610168457, maxY: 40.726087955120704} const extent = Utils.getFeatureCollectionExtent({ "type": "FeatureCollection", "crs": { "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" }, "type": "name" }, "features": [ { "type": "Feature", "properties": { "type": "rain", "value": 5 }, "geometry": { "type": "Point", "coordinates": [ -73.99995803833008, 40.71805432623303 ] } }, { "type": "Feature", "properties": { "type": "water", "value": 7 }, "geometry": { "type": "Point", "coordinates": [ -73.98167610168457, 40.726087955120704 ] } } ] });
-
static getHeightByCoordinates(coordinates) → {Number}
根据经纬度获取当前经纬度对应的海拔高度 该方法是根据当前场景的加载的地形数据及倾斜数据进行拾取,如果需要拾取的地形没有加载或者加载精度不足,会导致拾取结果不准确
-
Parameters:
Name Type Description coordinates
Array 经纬度坐标 Returns:
Number - 在当前地形服务中 该经纬度对应的海拔高度 -
async, static getHeightByCoordinatesAsync(coordinates) → {Promise}
根据经纬度获取当前经纬度对应的海拔高度(通过地形获取,不支持3dtiles) 该方法需要依赖地形服务,通过网络请求根据最高精度的地形数据获取高程
-
Parameters:
Name Type Description coordinates
Array 经纬度坐标 Returns:
Promise - 返回promise对象 -
static getLineLength(coords, isSpherical) → {Number}
计算线的长度单位:米
-
Parameters:
Name Type Description coords
Array.<Number> 经纬度 isSpherical
Boolean 是否计算球面距离 默认true 如果传入false 则计算欧氏距离 Returns:
NumberExample
//根据经纬度计算折线长度 返回结果 29.952 const length = Utils.getLineLength([[116.482141, 40.068031], [116.482137, 40.06816],[116.482133, 40.06802]]);
-
static getSphericalArea(coords) → {Number}
计算多边形的球面面积
-
Parameters:
Name Type Description coords
Array.<Number> 多边形的坐标 Returns:
Number - 球面面积 单位平方米 -
static getSphericalDistance(lonlat1, lonlat2) → {Number}
计算两点间的球面距离 单位:米
-
Parameters:
Name Type Description lonlat1
Array.<Number> 起点经纬度 lonlat2
Array.<Number> 终点经纬度 Returns:
Number - 球面距离