-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathBaidu.js
189 lines (162 loc) · 5.57 KB
/
Baidu.js
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* @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,
/**
* APIProperty: dpi
* {Float} 屏幕上每英寸包含像素点的个数。
* 该参数结合图层比例尺可以推算出该比例尺下图层的分辨率.默认为96。
*/
dpi: 96,
/**
* Property: attribution
* {String} The layer attribution.
*/
attribution: "Data by <a style='white-space: nowrap' target='_blank' href='http://map.baidu.com/'>Baidu</a>",
/**
* Property: zOffset
* {Number} 图片url中z值偏移量
*/
zOffset:3,
/**
* Constructor: SuperMap.Layer.Baidu
* 创建Baidu图层
*
* Example:
* (code)
*
* var baiduLayer = new SuperMap.Layer.Baidu(type);
* (end)
*/
initialize: function (type,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";
if (type =="PHYSICAL")//普通
me.url = "http://online${num}.map.bdimg.com/onlinelabel/?qt=tile&x=${x}&y=${y}&z=${z}&styles=pl&udt=20150815&scaler=1";
else if (type=="SATELLITE")//卫星
me.url = "http://shangetu1.map.bdimg.com/it/u=x=${x};y=${y};z=${z};v=009;type=sate&fm=46&udt=20130506";
else if (type=="DARK")//夜视
me.url = "http://api1.map.bdimg.com/customimage/tile?&x=${x}&y=${y}&z=${z}&udt=20170908&scale=1&ak=E4805d16520de693a3fe707cdc962045&customid=dark"
else if (type=="ROUTE")//道路
me.url = "http://online${num}.map.bdimg.com/tile/?qt=tile&x=${x}&y=${y}&z=${z}&styles=sl&udt=20170908"
else
me.url = "http://online${num}.map.bdimg.com/onlinelabel/?qt=tile&x=${x}&y=${y}&z=${z}&styles=pl&udt=20150815&scaler=1";
/*
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";
//投影从非官方的900913改为3857
me.projection = "EPSG:3857";
},
/**
* APIMethod: clone
* 创建当前图层的副本。
*
* Parameters:
* obj - {Object}
*
* Returns:
* {<SuperMap.Layer.Baidu>} 新的图层。
*/
clone: function (obj) {
var me = this;
if (obj == null) {
obj = new SuperMap.Layer.Baidu(
me.name, me.url, me.params, me.getOptions());
}
obj = SuperMap.CanvasLayer.prototype.clone.apply(me, [obj]);
obj._timeoutId = null;
return obj;
},
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 + me.zOffset;
var offsetX = Math.pow(2, zoom-1);
var offsetY = offsetX - 1;
var numX = xyz.x - offsetX;
var numY = -xyz.y + offsetY;
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'
});