coords.js
1.65 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
var earthCircumferenceInMeters = 40075016.685578488;
var halfEarthCircumferenceInMeters = earthCircumferenceInMeters / 2;
var earthRadiusInMeters = 6378137.0;
var MercatorLatitudeLimit = 85.051128;
/**
* 经纬度转米坐标
*/
function latLonToMeters(point) {
//如果用户传入的是SuperMap.Geometry.Point类型的对象就执行if语句,否则就执行else语句
if(point.CLASS_NAME == "SuperMap.Geometry.Point" || point.x != null){
var mx = point.x / 180.0 * halfEarthCircumferenceInMeters;
var my = Math.log(Math.tan((90 + point.y) * Math.PI / 360.0)) / (Math.PI / 180.0);
my = my / 180.0 * halfEarthCircumferenceInMeters;
return new SuperMap.Geometry.Point(mx, my);
}else{
var mx = point.lon / 180.0 * halfEarthCircumferenceInMeters;
var my = Math.log(Math.tan((90 + point.lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
my = my / 180.0 * halfEarthCircumferenceInMeters;
return new SuperMap.LonLat(mx, my);
}
}
/**
* 米坐标转经纬度
*/
function metersToLatLon(point) {
if (point.CLASS_NAME == "SuperMap.Geometry.Point" || point.x != null) {
var lon = point.x / halfEarthCircumferenceInMeters * 180.0;
var lat = point.y / halfEarthCircumferenceInMeters * 180.0;
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2);
return new SuperMap.Geometry.Point(lon, lat);
} else {
var lon = point.lon / halfEarthCircumferenceInMeters * 180.0;
var lat = point.lat / halfEarthCircumferenceInMeters * 180.0;
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2);
return new SuperMap.LonLat(lon, lat);
}
}