Baidu.js
3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @requires SuperMap/Layer/CanvasLayer.js
* @requires SuperMap/Layer/Grid.js
* @requires SuperMap/Tile/Image.js
*/
/**
* Class: SuperMap.Layer.Baidu
* Baidu服务图层类。
* 用于显示Baidu的地图,使用<SuperMap.Layer.Baidu>的
* 构造函数可以创建Baidu图层,更多信息查看:
*
*
*
* Inherits from:
* - <SuperMap.Layer.CanvasLayer>
*/
SuperMap.Layer.Baidu = SuperMap.Class(SuperMap.CanvasLayer, {
offsetXY:null,
/**
* Property: attribution
* {String} The layer attribution.
*/
attribution: "Data by <a style='white-space: nowrap' target='_blank' href='http://map.baidu.com/'>Baidu</a>",
/**
* Constructor: SuperMap.Layer.Baidu
* 创建Baidu图层
*
* Example:
* (code)
*
* var baiduLayer = new SuperMap.Layer.Baidu();
* (end)
*/
initialize: function (options) {
var me = this;
me.name = "Baidu";
me.url = "http://online${num}.map.bdimg.com/onlinelabel/?qt=tile&x=${x}&y=${y}&z=${z}&styles=pl&udt=20150815&scaler=1";
// me.url = "http://shangetu${num}.map.bdimg.com/it/u=x=${x};y=${y};z=${z};v=017;type=web&fm=44&udt=20130712";
/*
offsetXY = [];
offsetXY.push({x:-3,y:1});//3
offsetXY.push({x:-6,y:3});//4
offsetXY.push({x:-12,y:7});//5
offsetXY.push({x:-24,y:15});//6
offsetXY.push({x:-48,y:31});//7
offsetXY.push({x:-96,y:63});//8
offsetXY.push({x:-192,y:127});//9
offsetXY.push({x:-384,y:255});//10
offsetXY.push({x:-768,y:511});//11
offsetXY.push({x:-1536,y:1023});//12
offsetXY.push({x:-3072,y:2047});//13
offsetXY.push({x:-6144,y:4095});//14
offsetXY.push({x:-12288,y:8191});//15
offsetXY.push({x:-24576,y:16383});//16
offsetXY.push({x:-49152,y:32767});//17
offsetXY.push({x:-98304,y:65535});//18
offsetXY.push({x:-196608,y:131071});//19
*/
/*
var minX = 6291456;
var minY = 0;
var maxX= minX + Math.pow(2, 14) * 256 * 5;
var maxY= minY + Math.pow(2, 14) * 256 * 4;
*/
// console.log(Math.pow(2, 15) * 256 * 4); // bounds 3 16 2 4 1 1 19-3=16 0.5 15
var minX = -33554432;
var minY = -33554432;
var maxX= 33554432;
var maxY= 33554432;
var res = Math.pow(2,15);
var resAry= [];
for (var i = 0; i < 17; i++) //百度 3-19
{
resAry[i] = res;
res *= 0.5; //每次二分之一
}
//计算比例尺数组
var scaAry = [];
for(var i = 0;i<17;i++)
{
scaAry[i] = 0.0254/(96*resAry[i]); //0.0254 为英寸和米的转换常数 //PPI 每英寸的像素点数
}
options = SuperMap.Util.extend({
maxExtent: new SuperMap.Bounds(
minX, minY, maxX, maxY
),
tileOrigin:new SuperMap.LonLat(minX, maxY),
resolutions:resAry
}, options);
SuperMap.CanvasLayer.prototype.initialize.apply(me, [me.name, me.url, null, options]);
me.units = "m";
me.projection = "EPSG:900913";
},
getTileUrl:function(xyz){
var me = this,
url = me.url;
/*
var x = xyz.x + offsetXY[xyz.z].x;
var y = offsetXY[xyz.z].y - xyz.y;
var z = xyz.z + 3;
var num = Math.abs((xyz.x + xyz.y) % 8);
num++;
*/
var zoom = xyz.z - 1;
var offsetX = Math.pow(2, zoom+3);
var offsetY = offsetX - 1;
var numX = xyz.x - offsetX;
var numY = -xyz.y + offsetY;
zoom = xyz.z + 3;
var num = Math.abs((xyz.x + xyz.y) % 8)+1;
url = SuperMap.String.format(url, {
num: num,
x: numX,
y: numY,
z: zoom
});
url = url.replace(/-/g,"M");
return url;
},
CLASS_NAME: 'SuperMap.Layer.Baidu'
});