forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapCalculateUtil.js
More file actions
113 lines (110 loc) · 3.21 KB
/
Copy pathMapCalculateUtil.js
File metadata and controls
113 lines (110 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Unit } from '../REST';
/**
* @function getMeterPerMapUnit
* @description 单位换算,把米|度|千米|英寸|英尺换成米。
* @category BaseTypes Util
* @param {string} mapUnit 地图单位。
* @returns {number} 返回地图的距离单位。
* @usage
* ```
* // 浏览器
* <script type="text/javascript" src="{cdn}"></script>
* <script>
* const result = {namespace}.getMeterPerMapUnit(mapUnit);
*
* </script>
*
* // ES6 Import
* import { getMeterPerMapUnit } from '{npm}';
*
* const result = getMeterPerMapUnit(mapUnit);
* ```
*/
export var getMeterPerMapUnit = function(mapUnit) {
var earchRadiusInMeters = 6378137;
var meterPerMapUnit;
if (mapUnit === Unit.METER) {
meterPerMapUnit = 1;
} else if (mapUnit === Unit.DEGREE) {
// 每度表示多少米。
meterPerMapUnit = (Math.PI * 2 * earchRadiusInMeters) / 360;
} else if (mapUnit === Unit.KILOMETER) {
meterPerMapUnit = 1.0e-3;
} else if (mapUnit === Unit.INCH) {
meterPerMapUnit = 1 / 2.5399999918e-2;
} else if (mapUnit === Unit.FOOT) {
meterPerMapUnit = 0.3048;
} else {
return meterPerMapUnit;
}
return meterPerMapUnit;
};
/**
* @function getWrapNum
* @description 获取该坐标系的经纬度范围的经度或纬度。
* @category BaseTypes Util
* @param {number} x 经度或纬度。
* @param {boolean} includeMax 是否获取经度或纬度的最大值。
* @param {boolean} includeMin 是否获取经度或纬度的最小值。
* @param {number} range 坐标系的经纬度范围。
* @returns {number} 返回经度或纬度的值。
* @usage
* ```
* // 浏览器
* <script type="text/javascript" src="{cdn}"></script>
* <script>
* const result = {namespace}.getWrapNum(x, includeMax, includeMin, range);
*
* </script>
*
* // ES6 Import
* import { getWrapNum } from '{npm}';
*
* const result = getWrapNum(x, includeMax, includeMin, range);
* ```
*/
export function getWrapNum(x, includeMax = true, includeMin = true, range = [-180, 180]) {
var max = range[1],
min = range[0],
d = max - min;
if (x === max && includeMax) {
return x;
}
if (x === min && includeMin) {
return x;
}
var tmp = (((x - min) % d) + d) % d;
if (tmp === 0 && includeMax) {
return max;
}
return ((((x - min) % d) + d) % d) + min;
}
/**
* @function conversionDegree
* @description 转换经纬度。
* @category BaseTypes Util
* @param {number} degrees 经度或纬度。
* @returns {string} 返回度分秒。
* @usage
* ```
* // 浏览器
* <script type="text/javascript" src="{cdn}"></script>
* <script>
* const result = {namespace}.conversionDegree(degrees);
*
* </script>
*
* // ES6 Import
* import { conversionDegree } from '{npm}';
*
* const result = conversionDegree(degrees);
* ```
*/
export function conversionDegree(degrees) {
const degree = parseInt(degrees);
let fraction = parseInt((degrees - degree) * 60);
let second = parseInt(((degrees - degree) * 60 - fraction) * 60);
fraction = parseInt(fraction / 10) === 0 ? `0${fraction}` : fraction;
second = parseInt(second / 10) === 0 ? `0${second}` : second;
return `${degree}°${fraction}'${second}`;
}