wgs84坐標批量轉BD09坐標js腳本(親測批量轉換10000條數據)


1、將需要轉換的文件通過office軟件自動生成html文件,並引入該腳本

2、引入該腳本所需的js插件

3、點擊按鈕進行轉換

4、chrome瀏覽器自動下載的生成的json文件

//dynamicLoadCss('css/mui.min.css');

document.write("<script src='js/jquery.min.js'></script>");
//document.write("<script src='js/mui.min.js'></script>");
document.write("<script src='js/FileSaver.js'></script>");
//需使用項目申請的百度地圖api ak秘鑰
document.write("<script src='http://api.map.baidu.com/api?v=2.0&ak=q9Y6RkCd6GNQyPeQyN1zCtkMq36uifxn'></script>");
//document.write("<script src='js/changeMore.js'></script>");


var list = [];
var points = [];
var count = 0;
//爬取數據列
var p_EXPNO = 5;
var p_X = 6;
var p_Y = 7;
//批處理數
var batching = 10; //每次處理10條
var page = 0;


//導入css文件
function dynamicLoadCss(url) {
        var head = document.getElementsByTagName('head')[0];
        var link = document.createElement('link');
        link.type='text/css';
        link.rel = 'stylesheet';
        link.href = url;
        head.appendChild(link);
    }
//生成json文件
function downloadJson(data,name) {
if(name == undefined)
name = "hello.json";
var blob = new Blob([JSON.stringify(data)], { type: "" });
saveAs(blob, name);
}
//坐標轉換回調函數
function translateCallback(data){
$('#count').text((++count)+'/'+page);
if(data.status === 0){
var xyResult = null;
for(var i=0; i<data.points.length; i++){
xyResult = data.points[i];
try{
list[((count-1)*batching+i)].X = xyResult.lat;
list[((count-1)*batching+i)].Y = xyResult.lng;
}catch(e){
console.log(((count-1)*batching+i)+' in list is false!');
}
}
if(count == page-1){
console.log(data.points.length);
}
if(count == page){
// mui('button').button('reset');
downloadJson(list,'轉換數據.json');
count = 0;
return true;
}
}
}


window.onload = function(){
for(var i=0;i<$('tr').length;i++){
var tr = $('tr').eq(i);
var expno = tr.children('td').eq(p_EXPNO).text();
var x = parseFloat(tr.children('td').eq(p_X).text());
var y = parseFloat(tr.children('td').eq(p_Y).text());
if((!isNaN(x))&&(x!='')&&(x!=NaN)){
var data = {
"EXPNO": expno,
"X": x,
"Y": y
};
list.push(data);
points.push(new BMap.Point(x,y));
}
}

(function(){
// 按鈕
var button = document.createElement('button');
// button.className = "mui-btn";
button.innerText = '點擊生成json';
var body = document.getElementsByTagName("body")[0];
body.insertBefore(button,body.childNodes[0]);
// 轉換數
var p = document.createElement('p');
p.id = 'count';
p.style.display = 'inline-block';
p.style.margin = '0px 0px 0px 10px';
p.style.color = 'red';
p.innerHTML = '0/0';
body.insertBefore(p,body.childNodes[1]);
})();
// 計算總頁數並顯示
page = Math.ceil(points.length/batching);
$('#count').text('0/'+page);

$('button').click(function(){
// mui(this).button('loading');
downloadJson(list,'原始數據.json');
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(new BMap.Point(119.71113301700,30.23375714910));
convertor.translate(pointArr, 1, 5, function(data){
console.log('frist data.status is '+data.status); //轉碼測試
});
for(var i=0; i<page; i++){
if(i === (page-1))
var pointArr = points.slice(i*batching,points.length);
else
var pointArr = points.slice(i*batching,(i+1)*batching);
setTimeout(function(){ //延時防止回調數據丟失
// 1:GPS設備獲取的角度坐標,wgs84坐標
// 5:百度地圖采用的經緯度坐標
convertor.translate(pointArr, 1, 5, translateCallback);
},i*10);//10ms,如果數據依然丟失,可增加時間間隔
}
});
}


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com