web-vue2
Version:
web ui for vue2
114 lines (113 loc) • 4.61 kB
JavaScript
import core from "../../../utils/core";
export default {
PI: 3.14159265358979324,
x_pi: 3.14159265358979324 * 3000.0 / 180.0,
// gps:null,
// getLocation(map,options,defaults=[117,25]){
//
//
// if(this.gps==null){
// core.loadJavaScript("https://api.tianditu.gov.cn/api?v=4.0&tk=4f25a25b0b2559c4cfaa95e04fa4552d")
// .then((res)=>{
// console.log(this.gps,"==>");
// this.gps = new T.Geolocation();
// this.getLocation(map,options,defaults);
// });
// return;
// }
// let err=(err)=>{
// switch (err.code) {
// case 1:
// alert('位置服务被拒绝');
// break;
// case 2:
// alert('暂时获取不到位置信息');
// break;
// case 3:
// alert('获取信息超时');
// break;
// default:
// alert('未知错误');
// break;
// }
// };
// // let gps = new this.T.Geolocation();
// this.gps.getCurrentPosition((loc)=>{
// map.location= [loc.lnglat.lng,loc.lnglat.lat]
// },options.err||err);
// // if(navigator.geolocation&&navigator.geolocation.getCurrentPosition) {
// // let err=(err)=>{
// // switch (err.code) {
// // case 1:
// // alert('位置服务被拒绝');
// // break;
// // case 2:
// // alert('暂时获取不到位置信息');
// // break;
// // case 3:
// // alert('获取信息超时');
// // break;
// // default:
// // alert('未知错误');
// // break;
// // }
// // }
// // navigator.geolocation.getCurrentPosition((re) => {
// // map.location =this.gcj_encrypt([re.coords.longitude, re.coords.latitude]);
// // }, options.err||err);
// // }
// },
delta: function (lat, lon)
{
let a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
let ee = 0.00669342162296594323; // ee: 椭球的偏心率。
let dLat = this.transformLat(lon - 105.0, lat - 35.0);
let dLon = this.transformLon(lon - 105.0, lat - 35.0);
let radLat = lat / 180.0 * this.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) * this.PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
return { 'lat': dLat, 'lon': dLon };
// return [dLon,dLat];
},
/**
* 编码 WGS-84 to GCJ-02
* @param wgsLat
* @param wgsLon
* @returns {{lon: *, lat: *}}
*/
gcj_encrypt: function (coordinate)
{
let d = this.delta(coordinate[1], coordinate[0]);
return [coordinate[0]+d.lon,coordinate[1]+d.lat];
},
/**
* 解码 GCJ-02 to WGS-84
* @param gcjLat
* @param gcjLon
* @returns {{lon: *, lat: *}|{lon: number, lat: number}}
*/
gcj_decrypt: function (coordinate)
{
let d = this.delta(coordinate[1], coordinate[0]);
return [coordinate[0]-d.lon,coordinate[1]-d.lat];
},
transformLat: function (x, y)
{
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 * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
return ret;
},
transformLon: function (x, y)
{
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 * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
return ret;
}
}