Openlayers加载腾讯、高德、天地图

之前加载的百度地图,偏移较大,一直没有再测试,于是将腾讯、高德、天地图的整理一下,方便查看。

腾讯js代码:

 1 OpenLayers.Layer.QQ = OpenLayers.Class(OpenLayers.Layer.TileCache, {
 2     sateTiles: !1,
 3     initialize: function(a, b, c) {
 4         var d = OpenLayers.Util.extend({
 5             format: "image/png",
 6             isBaseLayer: !0
 7         },
 8         c);
 9         OpenLayers.Layer.TileCache.prototype.initialize.apply(this, [a, b, {},
10         d]),
11         this.extension = this.format.split("/")[1].toLowerCase(),
12         this.extension = "jpg" == this.extension ? "jpeg": this.extension,
13         this.transitionEffect = "resize",
14         this.buffer = 0
15     },
16     getURL: function(a) {
17         var b = this.map.getResolution(),
18         c = this.map.getMaxExtent(),
19         d = this.tileSize,
20         e = this.map.zoom,
21         f = Math.round((a.left - c.left) / (b * d.w)),
22         g = Math.round((c.top - a.top) / (b * d.h)),
23         h = new Array(0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 7, 0, 7, 0, 15, 0, 15, 0, 31, 0, 31, 0, 63, 4, 59, 0, 127, 12, 115, 0, 225, 28, 227, 356, 455, 150, 259, 720, 899, 320, 469, 1440, 1799, 650, 929, 2880, 3589, 1200, 2069, 5760, 7179, 2550, 3709, 11520, 14349, 5100, 7999, 23060, 28689, 10710, 15429, 46120, 57369, 20290, 29849, 89990, 124729, 41430, 60689, 184228, 229827, 84169, 128886),
24         i = 4 * e,
25         j = h[i++],
26         k = h[i++],
27         l = h[i++],
28         h = h[i],
29         m = this.sateTiles ? ".jpg": ".png";
30         if (f >= j && k >= f && g >= l && h >= g) {
31             g = Math.pow(2, e) - 1 - g;
32             var n = 'z=' + e + '&x=' + f + '&y=' + g + '&type=vector&style=0&v=1.1.1'
33         }
34         var o = this.url;
35         return OpenLayers.Util.isArray(o) && n && (o = this.selectUrl(n, o)),
36         o + n
37     },
38     clone: function(a) {
39         return null == a && (a = new OpenLayers.Layer.QQ(this.name, this.url, this.options)),
40         a = OpenLayers.Layer.TileCache.prototype.clone.apply(this, [a])
41     },
42     CLASS_NAME: "OpenLayers.Layer.QQ"
43 });
View Code

  QQ地图的服务地址换了,这里记下以前的地址(屏蔽的代码)和现在的地址。

 1     //QQ地图
 2     map.addLayer(
 3         new OpenLayers.Layer.QQ("QQ地图",
 4             [
 5                 //"http://p0.map.soso.com/maptilesv2/",
 6                 //"http://p1.map.soso.com/maptilesv2/",
 7                 //"http://p2.map.soso.com/maptilesv2/", 
 8                 //"http://p3.map.soso.com/maptilesv2/"
 9                 'http://rt0.map.gtimg.com/realtimerender?',
10                 'http://rt1.map.gtimg.com/realtimerender?',
11                 'http://rt2.map.gtimg.com/realtimerender?',
12                 'http://rt3.map.gtimg.com/realtimerender?'
13             ],
14             {
15                 sateTiles: false
16             }
17         )
18     );
View Code

 

QQ地图和高德地图为火星坐标,纠正坐标可以用同一套方法,网上有js文件可以下载。

高德地图:

 1 OpenLayers.Layer.Gaode = OpenLayers.Class(OpenLayers.Layer.TileCache, {
 2     initialize: function (name, url, options) {
 3         var tempoptions = OpenLayers.Util.extend({
 4             'format': 'image/png',
 5             isBaseLayer: true
 6         }, options);
 7         OpenLayers.Layer.TileCache.prototype.initialize.apply(this, [name, url, {},    tempoptions]);
 8         this.extension = this.format.split('/')[1].toLowerCase();
 9         this.extension = (this.extension == 'jpg') ? 'jpeg' : this.extension;
10         this.transitionEffect = "resize";
11         this.buffer = 0;
12     },
13     getURL: function (bounds) {
14         var retUrl = this.url+"lang=zh_cn&size=1&scale=1&style=8&";
15         var res = 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值