common.tsx
4.64 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
export function setFavicon (logoPath: string) {
const link = document.createElement('link');
link.rel = 'icon';
link.href = logoPath;
document.head.appendChild(link);
}
// 每个园区都有独立的分支 这里需要更换成对应的corpCode
export const currentCorpCode = () => {
return 'test';
};
export const _baseUrl = "http://36.34.99.80:8088";
// export const _baseUrl = "https://test.qgutech.com";
export const handleSearch = (search: any) => {
const _search = decodeURIComponent(search);
const index = _search.indexOf('?');
const baseUrl = index === -1? _search : _search.slice(index,_search?.length);
const _str = baseUrl?.replace('?', '');
const _arr = _str?.split('&');
let _params: any;
_arr?.forEach((item: any) => {
if (item.includes('=')) {
const _key = item?.split('=')?.[0];
const _value = item?.split('=')?.[1];
let _item = {
[_key]: _value === 'undefined' ? null : _value,
};
_params = {
..._params,
..._item,
};
}
});
return _params;
};
// 百度坐标系转大地坐标系
export const BD09II2WGS84 = (bdLon: number, bdLat: number) => {
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
//百度坐标转成火星坐标
let mars_point = { lat: 0, lon: 0,};
let x = bdLon - 0.0065;
let y = bdLat - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
mars_point.lat = z * Math.sin(theta);
mars_point.lon = z * Math.cos(theta);
//把火星坐标GCJ02转地球坐标系WGS84
let gcjLat = mars_point.lat;
let gcjLon = mars_point.lon;
let d = delta(gcjLat, gcjLon)
return {
'lat': ( gcjLat - d.lat ),
'lon': ( gcjLon - d.lon )
}
}
// 伪墨卡托投影 转 天地图(Tianditu) WGS84 经纬度坐标系
export const webMercatorToWGS84 = (x: any, y: any) => {
// 地球半径(Web Mercator 投影的参数)
const earthRadius = 20037508.34;
// 经度转换
const longitude = (x / earthRadius) * 180;
// 纬度转换
let latitude = (y / earthRadius) * 180;
latitude = (180 / Math.PI) * (2 * Math.atan(Math.exp((latitude * Math.PI) / 180)) - Math.PI / 2);
return { latitude, longitude };
}
const delta = (lat: number, lon: number) => {
let PI = 3.14159265358979324;
let a = 6378245.0
let ee = 0.00669342162296594323
let dLat = transformLat(lon - 105.0, lat - 35.0)
let dLon = transformLon(lon - 105.0, lat - 35.0)
let radLat = lat / 180.0 * PI
let magic = Math.sin(radLat)
magic = 1 - ee * magic * magic
let sqrtMagic = Math.sqrt(magic)
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI)
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * PI)
return {
'lat': dLat,
'lon': dLon
}
}
const transformLat = (x: number, y: number) => {
let PI = 3.14159265358979324;
let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0
ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0
ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0
return ret
}
const transformLon = (x: number, y: number) => {
let PI = 3.14159265358979324;
let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0
ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0
ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0
return ret
}
// 十六进制颜色 转换成 rgba
export const hexToRgba = (hex: string | null | undefined, alpha: any) => {
let r: string | number = 0, g: string | number = 0, b: string | number = 0;
// 3 digits
if (hex?.length == 4) {
r = "0x" + hex?.[1] + hex?.[1];
g = "0x" + hex?.[2] + hex?.[2];
b = "0x" + hex?.[3] + hex?.[3];
// 6 digits
} else if (hex?.length == 7) {
r = "0x" + hex?.[1] + hex?.[2];
g = "0x" + hex?.[3] + hex?.[4];
b = "0x" + hex?.[5] + hex?.[6];
}
return "rgba(" + +r + "," + +g + "," + +b + "," + alpha + ")";
}
// // 使用示例
// const hexColor = "#ff5733"; // 16进制颜色
// const opacity = 0.5; // 透明度(0.0 到 1.0)
// const rgbaColor = hexToRgba(hexColor, opacity);
// console.log(rgbaColor); // 输出: "rgba(255, 87, 51, 0.5)"