| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import {mapConfig} from '../config/mapConfig'
- /**
- * 根据不同坐标系,自动判断进行何种转换
- * @param {*} poi {x:'',y:''}
- */
- export function _longLatTransform(poi){
- if(mapConfig.wkid == '102100' || mapConfig.wkid == '3857'){
- return _getLngLat(poi)
- }else{
- return poi;
- }
- }
- /**
- * 墨卡托转经纬度
- * @param poi 墨卡托
- * @returns {{}}
- * @private
- */
- export function _getLngLat(poi){
- var lnglat = {};
- lnglat.x = poi.x/20037508.34*180;
- var mmy = poi.y/20037508.34*180;
- lnglat.y = 180/Math.PI*(2*Math.atan(Math.exp(mmy*Math.PI/180))-Math.PI/2);
- return lnglat;
- }
- export function _getLng(x){
- var lng;
- lng = x/20037508.34*180;
- return lng;
- }
- export function _getLat(y){
- var lat;
- var mmy = y/20037508.34*180;
- lat = 180/Math.PI*(2*Math.atan(Math.exp(mmy*Math.PI/180))-Math.PI/2);
- return lat;
- }
- /**
- * 经纬度转墨卡托
- * @param poi 经纬度
- * @returns {{}}
- * @private
- */
- export function _getMercator(poi) {//[114.32894, 30.585748]
- var mercator = {};
- var earthRad = 6378137.0;
- // console.log("mercator-poi",poi);
- mercator.x = poi.lng * Math.PI / 180 * earthRad;
- var a = poi.lat * Math.PI / 180;
- mercator.y = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
- // console.log("mercator",mercator);
- return mercator; //[12727039.383734727, 3579066.6894065146]
- }
|