@hzab/map-combine 0.0.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/package.json +2 -2
- package/src/basic/BasicBusiness.ts +72 -0
- package/src/basic/BasicElement.ts +35 -0
- package/src/basic/BasicMarker.ts +45 -0
- package/src/basic/MapCombine.ts +11 -1
- package/src/basic/MapElement.ts +15 -17
- package/src/basic/ReactPopup.tsx +24 -1
- package/src/basic/Tile3D.ts +76 -41
- package/src/cesium/CesiumEvent.ts +18 -29
- package/src/cesium/CesiumMap.ts +148 -53
- package/src/cesium/CesiumTile3D.ts +184 -55
- package/src/cesium/cesium-tile-covert/index.js +48 -0
- package/src/cesium/cesium-tile-covert/modules/index.js +12 -0
- package/src/cesium/cesium-tile-covert/modules/projection/BD09Projection.js +377 -0
- package/src/cesium/cesium-tile-covert/modules/provider/AMapImageryProvider.js +27 -0
- package/src/cesium/cesium-tile-covert/modules/provider/BaiduImageryProvider.js +58 -0
- package/src/cesium/cesium-tile-covert/modules/provider/GeoVisImageryProvider.js +25 -0
- package/src/cesium/cesium-tile-covert/modules/provider/GoogleImageryProvider.js +27 -0
- package/src/cesium/cesium-tile-covert/modules/provider/TdtImageryProvider.js +23 -0
- package/src/cesium/cesium-tile-covert/modules/provider/TencentImageryProvider.js +41 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/BD09TilingScheme.js +100 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/CustomGeographicTilingScheme.js +60 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/CustomMercatorTilingScheme.js +70 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/GCJ02TilingScheme.js +33 -0
- package/src/cesium/cesium-tile-covert/modules/transform/CoordTransform.js +148 -0
- package/src/openlayer/OpenlayerMap.ts +82 -27
- package/src/openlayer/openlayer-tile-gcj02-wgs84.js +144 -0
- package/src/utils/index.ts +15 -2
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const EARTH_RADIUS = 6370996.81;
|
|
7
|
+
const MC_BAND = [12890594.86, 8362377.87, 5591021, 3481989.83, 1678043.12, 0];
|
|
8
|
+
const LL_BAND = [75, 60, 45, 30, 15, 0];
|
|
9
|
+
const MC2LL = [
|
|
10
|
+
[
|
|
11
|
+
1.410526172116255e-8, 8.98305509648872e-6, -1.9939833816331, 2.009824383106796e2, -1.872403703815547e2,
|
|
12
|
+
91.6087516669843, -23.38765649603339, 2.57121317296198, -0.03801003308653, 1.73379812e7,
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
-7.435856389565537e-9, 8.983055097726239e-6, -0.78625201886289, 96.32687599759846, -1.85204757529826,
|
|
16
|
+
-59.36935905485877, 47.40033549296737, -16.50741931063887, 2.28786674699375, 1.026014486e7,
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
-3.030883460898826e-8, 8.98305509983578e-6, 0.30071316287616, 59.74293618442277, 7.357984074871, -25.38371002664745,
|
|
20
|
+
13.45380521110908, -3.29883767235584, 0.32710905363475, 6.85681737e6,
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
-1.981981304930552e-8, 8.983055099779535e-6, 0.03278182852591, 40.31678527705744, 0.65659298677277,
|
|
24
|
+
-4.44255534477492, 0.85341911805263, 0.12923347998204, -0.04625736007561, 4.48277706e6,
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
3.09191371068437e-9, 8.983055096812155e-6, 0.00006995724062, 23.10934304144901, -0.00023663490511, -0.6321817810242,
|
|
28
|
+
-0.00663494467273, 0.03430082397953, -0.00466043876332, 2.5551644e6,
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
2.890871144776878e-9, 8.983055095805407e-6, -0.00000003068298, 7.47137025468032, -0.00000353937994,
|
|
32
|
+
-0.02145144861037, -0.00001234426596, 0.00010322952773, -0.00000323890364, 8.260885e5,
|
|
33
|
+
],
|
|
34
|
+
];
|
|
35
|
+
const LL2MC = [
|
|
36
|
+
[
|
|
37
|
+
-0.0015702102444, 1.113207020616939e5, 1.704480524535203e15, -1.033898737604234e16, 2.611266785660388e16,
|
|
38
|
+
-3.51496691766537e16, 2.659570071840392e16, -1.072501245418824e16, 1.800819912950474e15, 82.5,
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
42
|
+
8.277824516172526e-4, 1.113207020463578e5, 6.477955746671608e8, -4.082003173641316e9, 1.077490566351142e10,
|
|
43
|
+
-1.517187553151559e10, 1.205306533862167e10, -5.124939663577472e9, 9.133119359512032e8, 67.5,
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
0.00337398766765, 1.113207020202162e5, 4.481351045890365e6, -2.339375119931662e7, 7.968221547186455e7,
|
|
47
|
+
-1.159649932797253e8, 9.723671115602145e7, -4.366194633752821e7, 8.477230501135234e6, 52.5,
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
0.00220636496208, 1.113207020209128e5, 5.175186112841131e4, 3.796837749470245e6, 9.920137397791013e5,
|
|
51
|
+
-1.22195221711287e6, 1.340652697009075e6, -6.209436990984312e5, 1.444169293806241e5, 37.5,
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
-3.441963504368392e-4, 1.113207020576856e5, 2.782353980772752e2, 2.485758690035394e6, 6.070750963243378e3,
|
|
55
|
+
5.482118345352118e4, 9.540606633304236e3, -2.71055326746645e3, 1.405483844121726e3, 22.5,
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
-3.218135878613132e-4, 1.113207020701615e5, 0.00369383431289, 8.237256402795718e5, 0.46104986909093,
|
|
59
|
+
2.351343141331292e3, 1.58060784298199, 8.77738589078284, 0.37238884252424, 7.45,
|
|
60
|
+
],
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
class BD09Projection {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.isWgs84 = false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getDistanceByMC(point1, point2) {
|
|
69
|
+
if (!point1 || !point2) {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
point1 = this.convertMC2LL(point1);
|
|
73
|
+
if (!point1) {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
let x1 = this.toRadians(point1["lng"]);
|
|
77
|
+
let y1 = this.toRadians(point1["lat"]);
|
|
78
|
+
point2 = this.convertMC2LL(point2);
|
|
79
|
+
if (!point2) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
let x2 = this.toRadians(point2["lng"]);
|
|
83
|
+
let y2 = this.toRadians(point2["lat"]);
|
|
84
|
+
return this.getDistance(x1, x2, y1, y2);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 根据经纬度坐标计算两点间距离;
|
|
89
|
+
* @param point1
|
|
90
|
+
* @param point2
|
|
91
|
+
* @returns {number|*} 返回两点间的距离
|
|
92
|
+
*/
|
|
93
|
+
getDistanceByLL(point1, point2) {
|
|
94
|
+
if (!point1 || !point2) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
point1["lng"] = this.getLoop(point1["lng"], -180, 180);
|
|
98
|
+
point1["lat"] = this.getRange(point1["lat"], -74, 74);
|
|
99
|
+
point2["lng"] = this.getLoop(point2["lng"], -180, 180);
|
|
100
|
+
point2["lat"] = this.getRange(point2["lat"], -74, 74);
|
|
101
|
+
let x1 = this.toRadians(point1["lng"]);
|
|
102
|
+
let y1 = this.toRadians(point1["lat"]);
|
|
103
|
+
let x2 = this.toRadians(point2["lng"]);
|
|
104
|
+
let y2 = this.toRadians(point2["lat"]);
|
|
105
|
+
return this.getDistance(x1, x2, y1, y2);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 平面直角坐标转换成经纬度坐标;
|
|
110
|
+
* @param point
|
|
111
|
+
* @returns {{lng: number, lat: number}}
|
|
112
|
+
*/
|
|
113
|
+
convertMC2LL(point) {
|
|
114
|
+
if (!point) {
|
|
115
|
+
return { lng: 0, lat: 0 };
|
|
116
|
+
}
|
|
117
|
+
let lnglat = {};
|
|
118
|
+
if (this.isWgs84) {
|
|
119
|
+
lnglat.lng = (point.lng / 20037508.34) * 180;
|
|
120
|
+
let mmy = (point.lat / 20037508.34) * 180;
|
|
121
|
+
lnglat.lat = (180 / Math.PI) * (2 * Math.atan(Math.exp((mmy * Math.PI) / 180)) - Math.PI / 2);
|
|
122
|
+
return {
|
|
123
|
+
lng: lnglat["lng"].toFixed(6),
|
|
124
|
+
lat: lnglat["lat"].toFixed(6),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let temp = {
|
|
129
|
+
lng: Math.abs(point["lng"]),
|
|
130
|
+
lat: Math.abs(point["lat"]),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
let factor = undefined;
|
|
134
|
+
for (let i = 0; i < MC_BAND.length; i++) {
|
|
135
|
+
if (temp["lat"] >= MC_BAND[i]) {
|
|
136
|
+
factor = MC2LL[i];
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
lnglat = this.convertor(point, factor);
|
|
141
|
+
return {
|
|
142
|
+
lng: lnglat["lng"].toFixed(6),
|
|
143
|
+
lat: lnglat["lat"].toFixed(6),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 经纬度坐标转换成平面直角坐标;
|
|
149
|
+
* @param point 经纬度坐标
|
|
150
|
+
* @returns {{lng: number, lat: number}|*}
|
|
151
|
+
*/
|
|
152
|
+
convertLL2MC(point) {
|
|
153
|
+
if (!point) {
|
|
154
|
+
return { lng: 0, lat: 0 };
|
|
155
|
+
}
|
|
156
|
+
if (point["lng"] > 180 || point["lng"] < -180 || point["lat"] > 90 || point["lat"] < -90) {
|
|
157
|
+
return point;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (this.isWgs84) {
|
|
161
|
+
let mercator = {};
|
|
162
|
+
let earthRad = 6378137.0;
|
|
163
|
+
mercator.lng = ((point.lng * Math.PI) / 180) * earthRad;
|
|
164
|
+
let a = (point.lat * Math.PI) / 180;
|
|
165
|
+
mercator.lat = (earthRad / 2) * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
lng: parseFloat(mercator["lng"].toFixed(2)),
|
|
169
|
+
lat: parseFloat(mercator["lat"].toFixed(2)),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
point["lng"] = this.getLoop(point["lng"], -180, 180);
|
|
174
|
+
point["lat"] = this.getRange(point["lat"], -74, 74);
|
|
175
|
+
let temp = { lng: point["lng"], lat: point["lat"] };
|
|
176
|
+
let factor = undefined;
|
|
177
|
+
for (let i = 0; i < LL_BAND.length; i++) {
|
|
178
|
+
if (temp["lat"] >= LL_BAND[i]) {
|
|
179
|
+
factor = LL2MC[i];
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!factor) {
|
|
184
|
+
for (let i = 0; i < LL_BAND.length; i++) {
|
|
185
|
+
if (temp["lat"] <= -LL_BAND[i]) {
|
|
186
|
+
factor = LL2MC[i];
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
let mc = this.convertor(point, factor);
|
|
192
|
+
return {
|
|
193
|
+
lng: parseFloat(mc["lng"].toFixed(2)),
|
|
194
|
+
lat: parseFloat(mc["lat"].toFixed(2)),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
*
|
|
200
|
+
* @param fromPoint
|
|
201
|
+
* @param factor
|
|
202
|
+
* @returns {{lng: *, lat: *}}
|
|
203
|
+
*/
|
|
204
|
+
convertor(fromPoint, factor) {
|
|
205
|
+
if (!fromPoint || !factor) {
|
|
206
|
+
return { lng: 0, lat: 0 };
|
|
207
|
+
}
|
|
208
|
+
let x = factor[0] + factor[1] * Math.abs(fromPoint["lng"]);
|
|
209
|
+
let temp = Math.abs(fromPoint["lat"]) / factor[9];
|
|
210
|
+
let y =
|
|
211
|
+
factor[2] +
|
|
212
|
+
factor[3] * temp +
|
|
213
|
+
factor[4] * temp * temp +
|
|
214
|
+
factor[5] * temp * temp * temp +
|
|
215
|
+
factor[6] * temp * temp * temp * temp +
|
|
216
|
+
factor[7] * temp * temp * temp * temp * temp +
|
|
217
|
+
factor[8] * temp * temp * temp * temp * temp * temp;
|
|
218
|
+
x *= fromPoint["lng"] < 0 ? -1 : 1;
|
|
219
|
+
y *= fromPoint["lat"] < 0 ? -1 : 1;
|
|
220
|
+
return {
|
|
221
|
+
lng: x,
|
|
222
|
+
lat: y,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
*
|
|
228
|
+
* @param x1
|
|
229
|
+
* @param x2
|
|
230
|
+
* @param y1
|
|
231
|
+
* @param y2
|
|
232
|
+
* @returns {number}
|
|
233
|
+
*/
|
|
234
|
+
getDistance(x1, x2, y1, y2) {
|
|
235
|
+
return EARTH_RADIUS * Math.acos(Math.sin(y1) * Math.sin(y2) + Math.cos(y1) * Math.cos(y2) * Math.cos(x2 - x1));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
*
|
|
240
|
+
* @param deg
|
|
241
|
+
* @returns {number}
|
|
242
|
+
*/
|
|
243
|
+
toRadians(deg) {
|
|
244
|
+
return (Math.PI * deg) / 180;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* @param rad
|
|
250
|
+
* @returns {number}
|
|
251
|
+
*/
|
|
252
|
+
toDegrees(rad) {
|
|
253
|
+
return (180 * rad) / Math.PI;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
*
|
|
258
|
+
* @param v
|
|
259
|
+
* @param a
|
|
260
|
+
* @param b
|
|
261
|
+
* @returns {number}
|
|
262
|
+
*/
|
|
263
|
+
getRange(v, a, b) {
|
|
264
|
+
if (a != null) {
|
|
265
|
+
v = Math.max(v, a);
|
|
266
|
+
}
|
|
267
|
+
if (b != null) {
|
|
268
|
+
v = Math.min(v, b);
|
|
269
|
+
}
|
|
270
|
+
return v;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
*
|
|
275
|
+
* @param v
|
|
276
|
+
* @param a
|
|
277
|
+
* @param b
|
|
278
|
+
* @returns {*}
|
|
279
|
+
*/
|
|
280
|
+
getLoop(v, a, b) {
|
|
281
|
+
while (v > b) {
|
|
282
|
+
v -= b - a;
|
|
283
|
+
}
|
|
284
|
+
while (v < a) {
|
|
285
|
+
v += b - a;
|
|
286
|
+
}
|
|
287
|
+
return v;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
*
|
|
292
|
+
* @param point
|
|
293
|
+
* @returns {{lng: number, lat: number}|*}
|
|
294
|
+
*/
|
|
295
|
+
lngLatToMercator(point) {
|
|
296
|
+
return this.convertLL2MC(point);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
*
|
|
301
|
+
* @param point
|
|
302
|
+
* @returns {{x: (number|*), y: (number|*)}}
|
|
303
|
+
*/
|
|
304
|
+
lngLatToPoint(point) {
|
|
305
|
+
let mercator = this.convertLL2MC(point);
|
|
306
|
+
return {
|
|
307
|
+
x: mercator["lng"],
|
|
308
|
+
y: mercator["lat"],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 墨卡托变换至经纬度
|
|
314
|
+
* @param point 墨卡托
|
|
315
|
+
* @returns Point 经纬度
|
|
316
|
+
*/
|
|
317
|
+
mercatorToLngLat(point) {
|
|
318
|
+
return this.convertMC2LL(point);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 平面到球面坐标
|
|
323
|
+
* @param point 平面坐标
|
|
324
|
+
* @returns Point 球面坐标
|
|
325
|
+
*/
|
|
326
|
+
pointToLngLat(point) {
|
|
327
|
+
let mercator = { lng: point.x, lat: point.y };
|
|
328
|
+
return this.convertMC2LL(mercator);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 地理坐标转换至像素坐标
|
|
333
|
+
* @param point 地理坐标
|
|
334
|
+
* @param zoom 级别
|
|
335
|
+
* @param mapCenter 地图中心点,注意为了保证没有误差,这里需要传递墨卡托坐标
|
|
336
|
+
* @param mapSize 地图容器大小
|
|
337
|
+
*/
|
|
338
|
+
pointToPixel(point, zoom, mapCenter, mapSize) {
|
|
339
|
+
if (!point) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
point = this.lngLatToMercator(point);
|
|
343
|
+
let zoomUnits = this.getZoomUnits(zoom);
|
|
344
|
+
let x = Math.round((point["lng"] - mapCenter["lng"]) / zoomUnits + mapSize.width / 2);
|
|
345
|
+
let y = Math.round((mapCenter["lat"] - point["lat"]) / zoomUnits + mapSize.height / 2);
|
|
346
|
+
return { x, y };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 像素坐标转换至地理坐标
|
|
351
|
+
* @param pixel 像素坐标
|
|
352
|
+
* @param zoom 级别
|
|
353
|
+
* @param mapCenter 地图中心点,注意为了保证没有误差,这里需要传递墨卡托坐标
|
|
354
|
+
* @param mapSize 地图容器大小
|
|
355
|
+
*/
|
|
356
|
+
pixelToPoint(pixel, zoom, mapCenter, mapSize) {
|
|
357
|
+
if (!pixel) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
let zoomUnits = this.getZoomUnits(zoom);
|
|
361
|
+
let lng = mapCenter["lng"] + zoomUnits * (pixel.x - mapSize.width / 2);
|
|
362
|
+
let lat = mapCenter["lat"] - zoomUnits * (pixel.y - mapSize.height / 2);
|
|
363
|
+
let point = { lng, lat };
|
|
364
|
+
return this.mercatorToLngLat(point);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
*
|
|
369
|
+
* @param zoom
|
|
370
|
+
* @returns {number}
|
|
371
|
+
*/
|
|
372
|
+
getZoomUnits(zoom) {
|
|
373
|
+
return Math.pow(2, 18 - zoom);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export default BD09Projection;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import GCJ02TilingScheme from "../tiling-scheme/GCJ02TilingScheme.js";
|
|
7
|
+
|
|
8
|
+
const TILE_URL = {
|
|
9
|
+
img: "//webst{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
|
|
10
|
+
elec: "//webrd{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
|
|
11
|
+
cva: "//webst{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class AMapImageryProvider extends Cesium.UrlTemplateImageryProvider {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
options["url"] = options.url || [options.protocol || "", TILE_URL[options.style] || TILE_URL["elec"]].join("");
|
|
17
|
+
if (!options.subdomains || !options.subdomains.length) {
|
|
18
|
+
options["subdomains"] = ["01", "02", "03", "04"];
|
|
19
|
+
}
|
|
20
|
+
if (options.crs === "WGS84") {
|
|
21
|
+
options["tilingScheme"] = new GCJ02TilingScheme();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
super(options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default AMapImageryProvider;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import BD09TilingScheme from "../tiling-scheme/BD09TilingScheme.js";
|
|
7
|
+
|
|
8
|
+
const { Cartesian2, WebMercatorTilingScheme, ImageryProvider, UrlTemplateImageryProvider } = Cesium;
|
|
9
|
+
|
|
10
|
+
const TILE_URL = {
|
|
11
|
+
img: "//shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46",
|
|
12
|
+
vec: "//online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=sl&v=020",
|
|
13
|
+
custom: "//api{s}.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&customid={style}",
|
|
14
|
+
traffic:
|
|
15
|
+
"//its.map.baidu.com:8002/traffic/TrafficTileService?time={time}&label={labelStyle}&v=016&level={z}&x={x}&y={y}&scaler=2",
|
|
16
|
+
};
|
|
17
|
+
class BaiduImageryProvider extends UrlTemplateImageryProvider {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
options["url"] = options.url || [options.protocol || "", TILE_URL[options.style] || TILE_URL["custom"]].join("");
|
|
20
|
+
|
|
21
|
+
if (options.crs === "WGS84") {
|
|
22
|
+
let resolutions = [];
|
|
23
|
+
for (let i = 0; i < 19; i++) {
|
|
24
|
+
resolutions[i] = 256 * Math.pow(2, 18 - i);
|
|
25
|
+
}
|
|
26
|
+
options["tilingScheme"] = new BD09TilingScheme({
|
|
27
|
+
resolutions,
|
|
28
|
+
rectangleSouthwestInMeters: new Cartesian2(-20037726.37, -12474104.17),
|
|
29
|
+
rectangleNortheastInMeters: new Cartesian2(20037726.37, 12474104.17),
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
options["tilingScheme"] = new WebMercatorTilingScheme({
|
|
33
|
+
rectangleSouthwestInMeters: new Cartesian2(-33554054, -33746824),
|
|
34
|
+
rectangleNortheastInMeters: new Cartesian2(33554054, 33746824),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
options["maximumLevel"] = 18;
|
|
38
|
+
super(options);
|
|
39
|
+
this._rectangle = this._tilingScheme.rectangle;
|
|
40
|
+
this._url = options.url;
|
|
41
|
+
this._crs = options.crs || "BD09";
|
|
42
|
+
this._style = options.style || "normal";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
requestImage(x, y, level) {
|
|
46
|
+
let xTiles = this._tilingScheme.getNumberOfXTilesAtLevel(level);
|
|
47
|
+
let yTiles = this._tilingScheme.getNumberOfYTilesAtLevel(level);
|
|
48
|
+
let url = this._url.replace("{z}", level).replace("{s}", String(1)).replace("{style}", this._style);
|
|
49
|
+
if (this._crs === "WGS84") {
|
|
50
|
+
url = url.replace("{x}", String(x)).replace("{y}", String(-y));
|
|
51
|
+
} else {
|
|
52
|
+
url = url.replace("{x}", String(x - xTiles / 2)).replace("{y}", String(yTiles / 2 - y - 1));
|
|
53
|
+
}
|
|
54
|
+
return ImageryProvider.loadImage(this, url);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default BaiduImageryProvider;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { UrlTemplateImageryProvider } = Cesium;
|
|
7
|
+
|
|
8
|
+
const TILE_URL = "//tiles{s}.geovisearth.com/base/v1/{style}/{z}/{x}/{y}?format={format}&tmsIds=w&token={key}";
|
|
9
|
+
|
|
10
|
+
class GeoVisImageryProvider extends UrlTemplateImageryProvider {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
options["url"] =
|
|
13
|
+
options.url ||
|
|
14
|
+
[
|
|
15
|
+
options.protocol || "",
|
|
16
|
+
TILE_URL.replace(/\{style\}/g, options.style || "vec")
|
|
17
|
+
.replace(/\{format\}/g, options.format || "png")
|
|
18
|
+
.replace(/\{key\}/g, options.key || ""),
|
|
19
|
+
].join("");
|
|
20
|
+
options["subdomains"] = options.subdomains || ["1", "2", "3"];
|
|
21
|
+
super(options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default GeoVisImageryProvider;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import GCJ02TilingScheme from "../tiling-scheme/GCJ02TilingScheme.js";
|
|
6
|
+
|
|
7
|
+
const { UrlTemplateImageryProvider } = Cesium;
|
|
8
|
+
|
|
9
|
+
const TILE_URL = {
|
|
10
|
+
img: "https://gac-geo.googlecnapps.cn/maps/vt?lyrs=s&x={x}&y={y}&z={z}",
|
|
11
|
+
elec: "https://gac-geo.googlecnapps.cn/maps/vt?lyrs=m&x={x}&y={y}&z={z}",
|
|
12
|
+
cva: "https://gac-geo.googlecnapps.cn/maps/vt?lyrs=h&x={x}&y={y}&z={z}",
|
|
13
|
+
ter: "https://gac-geo.googlecnapps.cn/maps/vt?lyrs=t@131,r&x={x}&y={y}&z={z}",
|
|
14
|
+
img_cva: "https://gac-geo.googlecnapps.cn/maps/vt?lyrs=y&x={x}&y={y}&z={z}",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
class GoogleImageryProvider extends UrlTemplateImageryProvider {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
options["url"] = options.url || [options.protocol || "", TILE_URL[options.style] || TILE_URL["elec"]].join("");
|
|
20
|
+
if (options.crs === "WGS84") {
|
|
21
|
+
options["tilingScheme"] = new GCJ02TilingScheme();
|
|
22
|
+
}
|
|
23
|
+
super(options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default GoogleImageryProvider;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { UrlTemplateImageryProvider } = Cesium;
|
|
7
|
+
|
|
8
|
+
const TILE_URL = "//t{s}.tianditu.gov.cn/DataServer?T={style}_w&x={x}&y={y}&l={z}&tk={key}";
|
|
9
|
+
|
|
10
|
+
class TdtImageryProvider extends UrlTemplateImageryProvider {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super({
|
|
13
|
+
url: [
|
|
14
|
+
options.protocol || "",
|
|
15
|
+
TILE_URL.replace(/\{style\}/g, options.style || "vec").replace(/\{key\}/g, options.key || ""),
|
|
16
|
+
].join(""),
|
|
17
|
+
subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
|
|
18
|
+
maximumLevel: 18,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default TdtImageryProvider;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import GCJ02TilingScheme from "../tiling-scheme/GCJ02TilingScheme.js";
|
|
7
|
+
|
|
8
|
+
const { UrlTemplateImageryProvider } = Cesium;
|
|
9
|
+
const TILE_URL = {
|
|
10
|
+
img: "//p{s}.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{reverseY}.jpg?version=400",
|
|
11
|
+
elec: "//rt{s}.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid={style}&scene=0&version=347",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class TencentImageryProvider extends UrlTemplateImageryProvider {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
let url = options.url || [options.protocol || "", TILE_URL[options.style] || TILE_URL["elec"]].join("");
|
|
17
|
+
options["url"] = url.replace("{style}", options.style || "1");
|
|
18
|
+
|
|
19
|
+
if (!options.subdomains || !options.subdomains.length) {
|
|
20
|
+
options["subdomains"] = ["0", "1", "2"];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (options.style === "img") {
|
|
24
|
+
options["customTags"] = {
|
|
25
|
+
sx: (imageryProvider, x, y, level) => {
|
|
26
|
+
return x >> 4;
|
|
27
|
+
},
|
|
28
|
+
sy: (imageryProvider, x, y, level) => {
|
|
29
|
+
return ((1 << level) - 1 - y) >> 4;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (options.crs === "WGS84") {
|
|
35
|
+
options["tilingScheme"] = new GCJ02TilingScheme();
|
|
36
|
+
}
|
|
37
|
+
super(options);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default TencentImageryProvider;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Caven Chen
|
|
3
|
+
* @Date: 2020-01-15
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import BD09Projection from "../projection/BD09Projection.js";
|
|
7
|
+
import CoordTransform from "../transform/CoordTransform.js";
|
|
8
|
+
|
|
9
|
+
const { WebMercatorTilingScheme, Math: CesiumMath, Cartographic, Cartesian2, Rectangle, defined } = Cesium;
|
|
10
|
+
|
|
11
|
+
class BD09TilingScheme extends WebMercatorTilingScheme {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
let projection = new BD09Projection();
|
|
15
|
+
this._projection.project = function (cartographic, result) {
|
|
16
|
+
result = result || {};
|
|
17
|
+
result = CoordTransform.WGS84ToGCJ02(
|
|
18
|
+
CesiumMath.toDegrees(cartographic.longitude),
|
|
19
|
+
CesiumMath.toDegrees(cartographic.latitude),
|
|
20
|
+
);
|
|
21
|
+
result = CoordTransform.GCJ02ToBD09(result[0], result[1]);
|
|
22
|
+
result[0] = Math.min(result[0], 180);
|
|
23
|
+
result[0] = Math.max(result[0], -180);
|
|
24
|
+
result[1] = Math.min(result[1], 74.000022);
|
|
25
|
+
result[1] = Math.max(result[1], -71.988531);
|
|
26
|
+
result = projection.lngLatToPoint({
|
|
27
|
+
lng: result[0],
|
|
28
|
+
lat: result[1],
|
|
29
|
+
});
|
|
30
|
+
return new Cartesian2(result.x, result.y);
|
|
31
|
+
};
|
|
32
|
+
this._projection.unproject = function (cartesian, result) {
|
|
33
|
+
result = result || {};
|
|
34
|
+
result = projection.mercatorToLngLat({
|
|
35
|
+
lng: cartesian.x,
|
|
36
|
+
lat: cartesian.y,
|
|
37
|
+
});
|
|
38
|
+
result = CoordTransform.BD09ToGCJ02(result.lng, result.lat);
|
|
39
|
+
result = CoordTransform.GCJ02ToWGS84(result[0], result[1]);
|
|
40
|
+
return new Cartographic(CesiumMath.toRadians(result[0]), CesiumMath.toRadians(result[1]));
|
|
41
|
+
};
|
|
42
|
+
this.resolutions = options.resolutions || [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param x
|
|
48
|
+
* @param y
|
|
49
|
+
* @param level
|
|
50
|
+
* @param result
|
|
51
|
+
* @returns {Rectangle|*}
|
|
52
|
+
*/
|
|
53
|
+
tileXYToNativeRectangle(x, y, level, result) {
|
|
54
|
+
const tileWidth = this.resolutions[level];
|
|
55
|
+
const west = x * tileWidth;
|
|
56
|
+
const east = (x + 1) * tileWidth;
|
|
57
|
+
const north = ((y = -y) + 1) * tileWidth;
|
|
58
|
+
const south = y * tileWidth;
|
|
59
|
+
|
|
60
|
+
if (!defined(result)) {
|
|
61
|
+
return new Rectangle(west, south, east, north);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
result.west = west;
|
|
65
|
+
result.south = south;
|
|
66
|
+
result.east = east;
|
|
67
|
+
result.north = north;
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param position
|
|
74
|
+
* @param level
|
|
75
|
+
* @param result
|
|
76
|
+
* @returns {undefined|*}
|
|
77
|
+
*/
|
|
78
|
+
positionToTileXY(position, level, result) {
|
|
79
|
+
const rectangle = this._rectangle;
|
|
80
|
+
if (!Rectangle.contains(rectangle, position)) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const projection = this._projection;
|
|
84
|
+
const webMercatorPosition = projection.project(position);
|
|
85
|
+
if (!defined(webMercatorPosition)) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const tileWidth = this.resolutions[level];
|
|
89
|
+
const xTileCoordinate = Math.floor(webMercatorPosition.x / tileWidth);
|
|
90
|
+
const yTileCoordinate = -Math.floor(webMercatorPosition.y / tileWidth);
|
|
91
|
+
if (!defined(result)) {
|
|
92
|
+
return new Cartesian2(xTileCoordinate, yTileCoordinate);
|
|
93
|
+
}
|
|
94
|
+
result.x = xTileCoordinate;
|
|
95
|
+
result.y = yTileCoordinate;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default BD09TilingScheme;
|