Class: Util
CMAP. Util
new Util()
地图相关的工具类
Methods
<static> convertLonlatToWebMercator(lonLat) → {Array}
经纬度坐标转Web墨卡托投影坐标
Parameters:
Name Type Description lonLat
Array [经度,纬度]
Returns:
Web墨卡托投影坐标 [x,y]
- Type
- Array
Example
CMAP.Util.convertWebMercatorToLonlat([119.5,36.5]); //返回web墨卡托坐标 [12968720.675611112, 4793547.458437541]
<static> convertLonlatToWorld(lonLat, h) → {Array}
经纬度转世界坐标
Parameters:
Name Type Description lonLat
Array [经度,纬度]
h
Number 离地高度 默认0
Returns:
世界坐标 [x,y,z]
- Type
- Array
<static> convertWebMercatorToLonlat(mercator) → {Array}
墨卡托投影转经纬度坐标
Parameters:
Name Type Description mercator
Array Web墨卡托坐标 [x,y]
Returns:
经纬度坐标 [经度,纬度]
- Type
- Array
Example
var coords = CMAP.Util.convertWebMercatorToLonlat([12968720.675611112, 4793547.458437541]); //返回经纬度坐标 [119.5,36.5]
<static> convertWgs84ToGcj02(wgs84经纬度坐标) → {Array}
wgs84坐标转为gcj02坐标
Parameters:
Name Type Description wgs84经纬度坐标
Array [经度,纬度]
Returns:
gcj02经纬度坐标 [经度,纬度]
- Type
- Array
Example
var gcj02Coords = CMAP.Util.convertWgs84ToGcj02([116.5,39.5]); //返回gcj02坐标 [116.5059564261526, 39.501157091519175]
<static> convertWindowToWorld(windowPosition) → {Array}
屏幕坐标转世界坐标
Parameters:
Name Type Description windowPosition
Array 屏幕坐标
Returns:
世界坐标 [x,y,z]
- Type
- Array
<static> convertWorldToLonlat(pos) → {Array}
世界坐标转经纬度
Parameters:
Name Type Description pos
Array 世界坐标[x,y,z]
Returns:
经纬度坐标(带高度) [经度,纬度,高度]
- Type
- Array
<static> createSkyAndSun()
创建天空和太阳,默认会替代之前设置的光源
<static> getAnglesFromLonlat(lonlat, angle) → {Array}
根据经纬度和方位角得到可以使物体贴地的欧拉角
Parameters:
Name Type Description lonlat
Array 经纬度坐标
angle
Number 方位角 默认0
Returns:
旋转角度 [angleX, angleY, angleZ]
- Type
- Array
<static> getAnglesFromPosition(pos, azimuth) → {Array}
根据世界坐标和方位角得到可以使物体贴地的旋转信息
Parameters:
Name Type Description pos
Array 世界坐标
azimuth
Number 方位角 默认0
Returns:
旋转信息 [angleX, angleY, angleZ]
- Type
- Array
<static> getAzimuth(lonlat1, lonlat2) → {number}
计算两点间的方位角
Parameters:
Name Type Description lonlat1
Array 起点经纬度
lonlat2
Array 终点经纬度
Returns:
方位角
- Type
- number
<static> getCenterCoordinates(coordinates) → {Array}
获取多边形中心点
Parameters:
Name Type Description coordinates
Array 多边形经纬度坐标数组 [[x,y],[x,y],[x,y]......] (注:仅支持二维的经纬度数组)
Returns:
[x,y] 中心点坐标
- Type
- Array
Example
// 返回多边形的重心的经纬度坐标 [116.47585956650495, 39.98538569844471]var center = CMAP.Util.getCenterCoordinates([[116.4757, 39.9851],[116.4755, 39.9852],[116.4761, 39.9857],[116.4762, 39.9856],[116.4757, 39.9851]]);
<static> getCenterOfGravityPoint(coordinates) → {Array}
获取多边形重心
Parameters:
Name Type Description coordinates
Array 多边形经纬度坐标数组 [[x,y],[x,y],[x,y]......] (注:仅支持二维的经纬度数组)
Returns:
[x,y] 重心点坐标
- Type
- Array
Example
// 返回多边形的重心的经纬度坐标 [116.47585956650495, 39.98538569844471]var center = CMAP.Util.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 起点经纬度
lonlat2
Array 终点经纬度
Returns:
欧式距离
- Type
- number
<static> getFeatureCollectionExtent(featureCollection) → {Object}
获取geojson的范围
Parameters:
Name Type Description featureCollection
Object geojson对象
Returns:
geojson数据的范围
- Type
- Object
Example
//返回geojson数据的范围 {minX: -73.99995803833008, minY: 40.71805432623303, maxX: -73.98167610168457, maxY: 40.726087955120704}CMAP.Util.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> getLineLength(coords, isSpherical) → {number}
计算线的长度单位:米
Parameters:
Name Type Description coords
Array 经纬度
isSpherical
Boolean 是否计算球面距离 默认true 如果传入false 则计算欧氏距离
Returns:
- Type
- number
Example
//根据经纬度计算折线长度 返回结果 29.952var length = CMAP.Util.getLineLength([[116.482141, 40.068031], [116.482137, 40.06816],[116.482133, 40.06802]]);
<static> getPolygonExtent(coordinates) → {Object}
获取多边形的范围
Parameters:
Name Type Description coordinates
Array 多边形经纬度坐标数组 [[x,y],[x,y],[x,y]......] 支持Polygon和MultiPolygon
Returns:
多边形的范围
- Type
- Object
Example
// 返回多边形范围 {minX: 116.4755, minY: 39.9851, maxX: 116.4762, maxY: 39.9857}var center = CMAP.Util.getPolygonExtent([[116.4757, 39.9851],[116.4755, 39.9852],[116.4761, 39.9857],[116.4762, 39.9856],[116.4757, 39.9851]]);
<static> getSphericalArea(coords) → {number}
计算多边形的球面面积
Parameters:
Name Type Description coords
Array 多边形的坐标
Returns:
球面面积 单位平方米
- Type
- number
<static> getSphericalDistance(lonlat1, lonlat2) → {number}
计算两点间的球面距离 单位:米
Parameters:
Name Type Description lonlat1
Array 起点经纬度
lonlat2
Array 终点经纬度
Returns:
球面距离
- Type
- number
<static> positionToQuaternion(pos, angle) → {THREE.Quaternion}
根据位置和旋转角度计算贴地的四元数
Parameters:
Name Type Description pos
angle
Returns:
- Type
- THREE.Quaternion