new Utils()
Methods
-
static convertColorToZeroToOne(color) → {Array.<Number>}
将以255为最大值的颜色数组转为以1为最大值的颜色数组
-
Parameters:
Name Type Description colorArray.<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 geojsonObject GeoJSON数据 originstring <optional>
'wgs84' 原始坐标系 支持wgs84 gcj020 bd09 deststring <optional>
'gcj02' 目标坐标系 支持wgs84 gcj020 bd09 Returns:
Object - 转换后的GeoJSON对象 -
static convertLonlatToWebMercator(lonLat) → {Array.<Number>}
经纬度坐标转Web墨卡托投影坐标
-
Parameters:
Name Type Description lonLatArray.<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, mode, map) → {Array.<Number>}
经纬度转世界坐标
-
Parameters:
Name Type Description lonLatArray.<Number> [经度,纬度] heightNumber 离地高度 默认0 modeSceneMode 地图模式 2.5D还是3D 默认使用当前地图的模式 mapMap 地图对象 主要是判断使用哪种投影类型 默认使用当前的map对象 避免多app冲突 Returns:
Array.<Number> - 世界坐标 [x,y,z] -
static convertWebMercatorToLonlat(mercator) → {Array.<Number>}
墨卡托投影转经纬度坐标
-
Parameters:
Name Type Description mercatorArray.<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 lonlatArray.<Number> wgs84经纬度坐标 [经度,纬度] Returns:
Array.<Number> - gcj02经纬度坐标 [经度,纬度]Example
const gcj02Coords = Utils.convertWgs84ToGcj02([116.5,39.5]); //返回gcj02坐标 [116.5059564261526, 39.501157091519175] -
static convertWindowToWorld(windowPosition, map) → {Array.<Number>}
屏幕坐标转世界坐标
-
Parameters:
Name Type Description windowPositionArray.<Number> 屏幕坐标[x,y] mapTHING.EARTH.Map 地图实例 Returns:
Array.<Number> - 世界坐标 [x,y,z] -
static convertWorldToLonlat(pos, mode, map) → {Array.<Number>}
世界坐标转经纬度
-
Parameters:
Name Type Description posArray.<Number> 世界坐标[x,y,z] modeSceneMode 地图模式 2.5D还是3D 默认使用当前地图的模式 mapMap 地图对象 主要是判断使用哪种投影类型 默认使用当前的map对象 避免多app冲突 Returns:
Array.<Number> - 经纬度坐标(带高度) [经度,纬度,高度] -
static getAnglesFromLonlat(lonlat, azimuthopt, pitchopt, modeopt, mapopt) → {Array.<Number>}
根据经纬度和方位角得到可以使物体贴地的旋转信息
-
Parameters:
Name Type Attributes Default Description lonlatArray.<Number> 经纬度 azimuthNumber <optional>
0 azimuth 方位角 pitchNumber <optional>
0 pitch 物体倾角 modeTHING.EARTH.SceneMode <optional>
场景模式 如果不传 用当前app.map的mode mapTHING.EARTH.Map <optional>
map实例 如果不传 使用当前app.map Returns:
Array.<Number> - 旋转角度 [x,y,z] -
static getAnglesFromPosition(pos, azimuthopt, pitchopt, modeopt, mapopt) → {Array.<Number>}
根据世界坐标和方位角得到可以使物体贴地的旋转信息
-
Parameters:
Name Type Attributes Default Description posArray.<Number> 世界坐标 azimuthNumber <optional>
0 azimuth 方位角 pitchNumber <optional>
0 pitch 物体倾角 modeTHING.EARTH.SceneMode <optional>
场景模式 如果不传 用当前app.map的mode mapTHING.EARTH.Map <optional>
map实例 如果不传 使用当前app.map Returns:
Array.<Number> - 旋转角度 [x,y,z] -
static getAzimuth(lonlat1, lonlat2) → {Number}
计算两点间的方位角
-
Parameters:
Name Type Description lonlat1Array.<Number> 起点经纬度 lonlat2Array.<Number> 终点经纬度 Returns:
Number - 方位角 -
static getCenterCoordinates(coordinates) → {Array.<Number>}
获取坐标的中心点
-
Parameters:
Name Type Description coordinatesArray 待求坐标点数组 Returns:
Array.<Number> - [x,y] 中心点坐标 -
static getCenterOfGravityPoint(coordinates) → {Array.<Number>}
获取多边形重心/质心 返回[116.47585641025641, 39.98538461538462]
-
Parameters:
Name Type Description coordinatesArray 多边形经纬度坐标数组 符合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, modeopt, mapopt) → {Number}
计算两点间的欧式距离(两点直连的距离) 单位:米
-
Parameters:
Name Type Attributes Description lonlat1Array.<Number> 起点经纬度 lonlat2Array.<Number> 终点经纬度 modeTHING.EARTH.SceneMode <optional>
场景模式 如果不传 用当前app.map的mode mapTHING.EARTH.Map <optional>
map实例 如果不传 使用当前app.map 主要作用是在转世界坐标时判断投影类型 Returns:
Number - 欧式距离 -
static getExtent(coordinates) → {Extent}
获取坐标的范围(最大最小经纬度)
-
Parameters:
Name Type Description coordinatesArray Returns:
Extent - result -
static getFeatureCollectionExtent(featureCollection) → {Extent}
获取geojson的范围
-
Parameters:
Name Type Description featureCollectionGeoJSONFeatureCollection 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, mapopt) → {Number}
根据经纬度获取当前经纬度对应的海拔高度 该方法是根据当前场景的加载的地形数据及倾斜数据进行拾取如果需要拾取的地形没有加载或者加载精度不足,会导致拾取结果不准确获取到的高程是乘以地形夸张系数之后的值2.5D下 仅支持获取地形高度
-
Parameters:
Name Type Attributes Description coordinatesArray 经纬度坐标 仅支持一个坐标 mapTHING.EARTH.Map <optional>
map实例 如果不传 使用当前app.map Returns:
Number - 在当前地形服务中 该经纬度对应的海拔高度 -
async, static getHeightByCoordinatesAsync(coordinates, levelopt, multiplyExaggerationopt, mapopt) → {Promise}
根据经纬度获取当前经纬度对应的海拔高度(通过地形获取,不支持3dtiles) 该方法需要依赖地形服务,通过网络请求根据最高精度的地形数据获取高程 如果没有添加地形,调用这个方法会报错
-
Parameters:
Name Type Attributes Default Description coordinatesNumber | Array.<Array.<Number>> 经纬度坐标 或者经纬度坐标的数组 levelNumber <optional>
层级 如果不传使用精度最高的层级获取高度 multiplyExaggerationBoolean <optional>
true 是否乘以地形夸张值 mapTHING.EARTH.Map <optional>
map实例 如果不传 使用当前app.map Returns:
Promise - 返回promise对象Example
THING.EARTH.Utils.getHeightByCoordinatesAsync([[116,39],[116,39.1]]).then(ev=>{ console.log(ev); //打印结果 [8, 14.3] }) -
static getLineLength(coords, isSpherical) → {Number}
计算线的长度单位:米
-
Parameters:
Name Type Description coordsArray.<Number> 经纬度 isSphericalBoolean 是否计算球面距离 默认true 如果传入false 则计算欧氏距离 Returns:
NumberExample
//根据经纬度计算折线长度 返回结果 29.952 const length = Utils.getLineLength([[116.482141, 40.068031], [116.482137, 40.06816],[116.482133, 40.06802]]); -
static getLongitudeScaleFactorByLatitude(latitude, mapopt) → {Number}
-
Parameters:
Name Type Attributes Description latitudeNumber 纬度 mapTHING.EARTH.Map <optional>
地图示例 如果不传,则使用当前app中的map对象 Returns:
Number - 变形倍数 -
static getSphericalArea(coords) → {Number}
计算多边形的球面面积
-
Parameters:
Name Type Description coordsArray.<Number> 多边形的坐标 Returns:
Number - 球面面积 单位平方米 -
static getSphericalDistance(lonlat1, lonlat2) → {Number}
计算两点间的球面距离 单位:米
-
Parameters:
Name Type Description lonlat1Array.<Number> 起点经纬度 lonlat2Array.<Number> 终点经纬度 Returns:
Number - 球面距离