码迷,mamicode.com
首页 > 其他好文 > 详细

openlayers对接百度地图新方法

时间:2014-12-03 10:25:35      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

上次给大家提供的openlayers对接百度地图有些问题,是因为没有进行分辨率设置,也没有进行相应的平面坐标转换,获取getURL的方法还是没有变化的

 1 getURL: function (bounds) {
 2       var tilez=this.map.zoom-1;
 3       var res = this.map.getResolution();
 4       var bbox = this.map.getMaxExtent();
 5       var size = this.tileSize;
 6       var bx = Math.round((bounds.left - this.tileOrigin.lon) / (res * size.w));
 7       var by = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * size.h));
 8       tilez = tilez + 1; 
 9       var x = bx.toString().replace("-","M");  
10       var y = by.toString().replace("-","M"); 
11       var urlsNum = parseInt((bx + by) % this.url.length); 
12       var strURL = ""; 
13       strURL = this.url[urlsNum] + ‘?qt=tile&x=‘+x+‘&y=‘+y+‘&z=‘+tilez+‘&styles=pl&udt=20140807‘;
14       return strURL;
15     },

主要是前端调用时候的设置有所更改,在new map时需要传入两个参数

projection:"EPSG:900913",
displayProjection:"EPSG:4326"

以平面形式对接,

var tileOrigin = new OpenLayers.LonLat(0,28000);//这个参数在对接中还是稍微有y轴的偏移,考虑因该是百度平面坐标系不是基于web墨卡托投影,而这个用的是web墨卡托投影的方式却对接的。
var maxExtent = new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);

new Layer的时候需要传入的opts = {

numZoomLevels:20,
maxResolution:262144,

maxExtent :maxExtent ,

tileOrigin :tileOrigin 

}

openlayers对接百度地图新方法

标签:style   blog   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/songjiang6940/p/4139258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!