|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- export const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
-
- return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
- }
-
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- export let isType = (type, target) => Object.prototype.toString.call(target) == `[object ${type}]`
-
- export function getDataByPath(data, dataPath) {
- dataPath = dataPath.split('.');
- for (let key of dataPath) {
- if (!data) return null;
- data = data[key]
- }
- return data;
- }
-
- /**
- * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
- * 即谷歌、高德 转 百度
- */
- var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
- var PI = 3.1415926535897932384626;
- var a = 6378245.0;
- var ee = 0.00669342162296594323;
-
- export function out_of_china(lng, lat) {
- return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);
- }
- export function gcj02tobd09(lng, lat) {
- var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
- var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
- var bd_lng = z * Math.cos(theta) + 0.0065;
- var bd_lat = z * Math.sin(theta) + 0.006;
- return [bd_lng, bd_lat]
- }
- export function transformlat(lng, lat) {
- var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
- ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
- ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
- return ret
- }
- export function transformlng(lng, lat) {
- var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
- ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
- ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
- return ret
- }
- export function wgs84togcj02(coordinate) {
- let lng = coordinate[0];
- let lat = coordinate[1];
- if (out_of_china(lng, lat)) {
- return [lng, lat]
- }
- else {
- var dlat = transformlat(lng - 105.0, lat - 35.0);
- var dlng = transformlng(lng - 105.0, lat - 35.0);
- var radlat = lat / 180.0 * PI;
- var magic = Math.sin(radlat);
- magic = 1 - ee * magic * magic;
- var sqrtmagic = Math.sqrt(magic);
- dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
- dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
- var mglat = parseFloat(lat) + parseFloat(dlat);
- var mglng = parseFloat(lng) + parseFloat(dlng);
- return [mglng, mglat]
- }
- }
- export function foramtRegion(arr,data){
- for(let item of data){
- let tem=[]
- for(let key of arr){
- if(item[key]){
- tem.push(item[key])
- }else{
- break;
- }
- }
- item.region=tem.join("/");
- }
-
- return data;
- }
-
|