Skip to content

Commit 9057e88

Browse files
update 修改 ol webmap bing 地图数据源 review by luox
1 parent 8b3564d commit 9057e88

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import * as olGeometry from 'ol/geom';
4242
import Vector from 'ol/source/Vector';
4343
import XYZ from 'ol/source/XYZ';
4444
import WMTS from 'ol/source/WMTS';
45+
import BingMaps from 'ol/source/BingMaps';
4546
import TileWMS from 'ol/source/TileWMS';
4647
import Feature from 'ol/Feature';
4748
import olRenderFeature from 'ol/render/Feature';
@@ -91,6 +92,7 @@ const dpiConfig = {
9192
* @param {boolean} [options.excludePortalProxyUrl] - server传递过来的url是否带有代理
9293
* @param {Object} [options.serviceProxy] - iportal内置代理信息, 仅矢量瓦片图层上图才会使用
9394
* @param {string} [options.tiandituKey] - 天地图的key
95+
* @param {string} [options.bingMapsKey] - 必应地图的 key。
9496
* @param {string} [options.googleMapsAPIKey] - 谷歌底图需要的key
9597
* @param {string} [options.proxy] - 代理地址,当域名不一致,请求会加上代理。避免跨域
9698
* @param {string} [options.tileFormat] - 地图瓦片出图格式,png/webp
@@ -124,6 +126,7 @@ export class WebMap extends Observable {
124126
this.excludePortalProxyUrl = options.excludePortalProxyUrl || false;
125127
this.serviceProxy = options.serviceProxy || null;
126128
this.tiandituKey = options.tiandituKey;
129+
this.bingMapsKey = options.bingMapsKey || '';
127130
this.googleMapsAPIKey = options.googleMapsAPIKey || '';
128131
this.proxy = options.proxy;
129132
//计数叠加图层,处理过的数量(成功和失败都会计数)
@@ -902,7 +905,7 @@ export class WebMap extends Observable {
902905
source = this.createBaiduSource();
903906
break;
904907
case 'BING':
905-
source = this.createBingSource(layerInfo, layerInfo.projection);
908+
source = this.createBingSource();
906909
break;
907910
case "WMS":
908911
source = this.createWMSSource(layerInfo);
@@ -1230,32 +1233,15 @@ export class WebMap extends Observable {
12301233
* @private
12311234
* @function WebMap.prototype.createBingSource
12321235
* @description 创建bing地图的source。
1233-
* @returns {ol.source.XYZ} bing地图的source
1234-
*/
1235-
createBingSource(layerInfo, projection) {
1236-
let url = 'https://dynamic.t0.tiles.ditu.live.com/comp/ch/{quadKey}?it=G,TW,L,LA&mkt=zh-cn&og=109&cstl=w4c&ur=CN&n=z';
1237-
return new XYZ({
1238-
wrapX: false,
1239-
projection: projection,
1240-
crossOrigin: 'anonymous',
1241-
tileUrlFunction: function (coordinates) {
1242-
let /*quadDigits = '', */[z, x, y] = [...coordinates];
1243-
y = y > 0 ? y - 1 : -y - 1;
1244-
let index = '';
1245-
for (let i = z; i > 0; i--) {
1246-
let b = 0;
1247-
let mask = 1 << (i - 1);
1248-
if ((x & mask) !== 0) {
1249-
b++;
1250-
}
1251-
if ((y & mask) !== 0) {
1252-
b += 2;
1253-
}
1254-
index += b.toString()
1255-
}
1256-
return url.replace('{quadKey}', index);
1257-
}
1258-
})
1236+
* @returns {ol.source.BingMaps} bing地图的source
1237+
*/
1238+
createBingSource() {
1239+
return new BingMaps({
1240+
key: this.bingMapsKey,
1241+
imagerySet: 'RoadOnDemand',
1242+
culture: 'zh-cn',
1243+
wrapX: false
1244+
});
12591245
}
12601246

12611247
/**

0 commit comments

Comments
 (0)