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
47 lines (44 loc) · 1.47 KB
/
MapCalculateUtil.js
File metadata and controls
47 lines (44 loc) · 1.47 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
import { Unit } from '../REST';
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;
};
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;
}
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}`;
}