openlayer读取三种类型的本地瓦片的计算公式
1.arcgis server瓦片的计算公式及geturl方法:
getURL: function(bounds){
var lon1=bounds.left;
var lat1=bounds.top;
var lon2=bounds.right;
var lat2=bounds.bottom;
var picHeight=256; //图片大小
var picResolution,picRow,picCol; //分辨率,所求图片行号,列号
var tileOriginX,tileOriginY; //切图原点
var iResolution = this.map.getResolution();
var temp1=new Array();
var i,zoom=0,path; //zoom代表缩放级别;
tileOriginX=this.tileOrigin.lon;
tileOriginY=this.tileOrigin.lat;
//计算zoom
zoom=this.map.getZoom();
//获得行列号(使用瓦片的中心点经纬度计算)
picRow=Math.ceil(Math.abs((tileOriginY-(lat1+lat2)/2)/(iResolution*picHeight)))-1;
picCol=Math.ceil(Math.abs((tileOriginX-(lon1+lon2)/2)/(iResolution*picHeight)))-1;
//计算瓦片路径,把级别、行列十进制转化为十六进制
zoom=zoom.toString(16);
picRow=picRow.toString(16);
picCol=picCol.toString(16);
var zoomTemp=”00″+zoom.toString();
var picRowTemp=”00000000″+picRow.toString();
var picColTemp=”00000000″+picCol.toString();
zoom=”L”+zoomTemp.substring(zoom.length,zoom.length+2);
picRow=”R”+picRowTemp.substring(picRow.length,picRow.length+8);
picCol=”C”+picColTemp.substring(picCol.length,picCol.length+8);
path=this.url+”+zoom+”/”+picRow+”/”+picCol+”.jpg”;
//alert(path);
return path;
}, //end function
2.google瓦片的geturl方法:
getURL: function(bounds){
var x = Math.round(Math.pow(2,this.map.getZoom())*(bounds.left+180)/360);
x = Math.round(x);
var y = Math.round(Math.pow(2,this.map.getZoom()-1)*(90-bounds.top)/180+Math.pow(2,this.map.getZoom()-2));
var z = this.map.getZoom();
return “../../googleMap/m_”+z+”_”+x+”_”+y+”.png”;
},
3.天地图瓦片的geturl方法:
getURL: function(bounds){
var lon1=bounds.left;
var lat1=bounds.top;
var lon2=bounds.right;
var lat2=bounds.bottom;
var picHeight=256; //图片大小
var picResolution,picRow,picCol; //分辨率,所求图片行号,列号
var tileOriginX,tileOriginY; //切图原点
var iResolution = this.map.getResolution();
var temp1=new Array();
var i,zoom=0,path; //zoom代表缩放级别;
tileOriginX=-180;
tileOriginY=90;
//计算zoom
zoom=this.map.getZoom();
//计算行列号(使用瓦片的中心点经纬度计算)
picRow=Math.ceil(Math.abs((tileOriginY-(lat1+lat2)/2)/(iResolution*picHeight)))-1;
picCol=Math.ceil(Math.abs((tileOriginX-(lon1+lon2)/2)/(iResolution*picHeight)))-1;
path=”../../china/”+zoom+”/”+picRow+”/”+picCol+”.png”
//alert(path);
return path;
}, //end function
转载自:https://blog.csdn.net/yihui1314/article/details/77601199