Skip to content

Commit f19592d

Browse files
committed
[bug] 1、Rest Map 提供可用比例尺数组的情况,缩放到一定的级别,出图错乱
2、互联网底图最大缩放级别矫正 review by zhaoqin
1 parent 4f1d449 commit f19592d

File tree

1 file changed

+77
-38
lines changed

1 file changed

+77
-38
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ export class WebMap extends ol.Observable {
322322
*/
323323
addBaseMap(mapInfo) {
324324
let layer = this.createBaseLayer(mapInfo, null, false);
325-
this.map.addLayer(layer);
325+
// 部分图层是异步的 早期异步没有设计好,所以将就将就吧
326+
if(layer){
327+
this.map.addLayer(layer);
328+
}
329+
326330
if (mapInfo.baseLayer && mapInfo.baseLayer.labelLayerVisible) {
327331
let layerInfo = mapInfo.baseLayer;
328332
//存在天地图路网
@@ -373,6 +377,7 @@ export class WebMap extends ol.Observable {
373377
createView(options) {
374378
let oldcenter = options.center,
375379
zoom = options.level !== undefined ? options.level : 1,
380+
maxZoom = options.maxZoom || 22,
376381
extent,
377382
projection = this.baseProjection;
378383
let center = [];
@@ -400,13 +405,11 @@ export class WebMap extends ol.Observable {
400405
maxResolution = Math.max(maxResolution1, maxResolution2);
401406
}
402407

403-
this.map.setView(new ol.View({
404-
zoom,
405-
center,
406-
projection,
407-
extent,
408-
maxResolution
409-
}));
408+
if(options.baseLayer.visibleScales){
409+
maxZoom = options.baseLayer.visibleScales.length;
410+
}
411+
412+
this.map.setView(new ol.View({zoom, center, projection, extent, maxResolution, maxZoom}));
410413
}
411414
/**
412415
* @private
@@ -434,9 +437,11 @@ export class WebMap extends ol.Observable {
434437
this.getInternetMapInfo(mapInfo.baseLayer);
435438
}else if(mapInfo.baseLayer.layerType === 'WMTS' && !isCallBack){
436439
// 通过请求完善信息
437-
//todo 之后需要优化
438440
this.getWmtsInfo(mapInfo.baseLayer, this.createBaseLayer, mapInfo);
439441
return;
442+
}else if(mapInfo.baseLayer.layerType === 'TILE' && !isCallBack){
443+
this.getTileInfo(mapInfo.baseLayer, this.createBaseLayer, mapInfo);
444+
return;
440445
}else{
441446
mapInfo.baseLayer.projection = mapInfo.projection;
442447
mapInfo.baseLayer.extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y];
@@ -473,7 +478,7 @@ export class WebMap extends ol.Observable {
473478
break;
474479
case 'TILE':
475480
case 'SUPERMAP_REST':
476-
source = this.createDynamicTiledSource(layerInfo, isBaseLayer);
481+
source = that.createDynamicTiledSource(layerInfo, isBaseLayer);
477482
break;
478483
case 'CLOUD':
479484
case 'CLOUD_BLACK':
@@ -546,7 +551,7 @@ export class WebMap extends ol.Observable {
546551
baseLayerInfo.iServerUrl= 'https://map.baidu.com/';
547552
baseLayerInfo.epsgCode= 'EPSG:3857';
548553
baseLayerInfo.minZoom= 1;
549-
baseLayerInfo.maxZoom= 18;
554+
baseLayerInfo.maxZoom= 19;
550555
baseLayerInfo.level= 1;
551556
baseLayerInfo.extent= baiduBounds;
552557
// thumbnail: this.getImagePath('bmap.png') 暂时不用到缩略图
@@ -555,7 +560,7 @@ export class WebMap extends ol.Observable {
555560
baseLayerInfo.url= 'http://t2.supermapcloud.com/FileService/image?map=quanguo&type=web&x={x}&y={y}&z={z}';
556561
baseLayerInfo.epsgCode= 'EPSG:3857';
557562
baseLayerInfo.minZoom= 1;
558-
baseLayerInfo.maxZoom= 18;
563+
baseLayerInfo.maxZoom= 19;
559564
baseLayerInfo.level= 1;
560565
baseLayerInfo.extent= baiduBounds;
561566
break;
@@ -580,19 +585,25 @@ export class WebMap extends ol.Observable {
580585
baseLayerInfo.iserverUrl= 'http://map.tianditu.gov.cn/';
581586
baseLayerInfo.epsgCode= 'EPSG:3857';
582587
baseLayerInfo.minZoom= 0;
583-
baseLayerInfo.maxZoom= 18;
588+
baseLayerInfo.maxZoom= 19;
584589
baseLayerInfo.level= 1;
585590
baseLayerInfo.extent= baiduBounds;
591+
if(baseLayerInfo.layerType === "TIANDITU_TER_3857"){
592+
baseLayerInfo.maxZoom = 14;
593+
}
586594
break;
587595
case ('TIANDITU_VEC_4326'):
588596
case ('TIANDITU_IMG_4326'):
589597
case ('TIANDITU_TER_4326'):
590598
baseLayerInfo.iserverUrl= 'http://map.tianditu.gov.cn/';
591599
baseLayerInfo.epsgCode= 'EPSG:4326';
592600
baseLayerInfo.minZoom= 0;
593-
baseLayerInfo.maxZoom= 18;
601+
baseLayerInfo.maxZoom= 19;
594602
baseLayerInfo.level= 1;
595603
baseLayerInfo.extent= bounds_4326;
604+
if(baseLayerInfo.layerType === "TIANDITU_TER_4326"){
605+
baseLayerInfo.maxZoom = 14;
606+
}
596607
break;
597608
case ('OSM'):
598609
baseLayerInfo.url= 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
@@ -607,29 +618,11 @@ export class WebMap extends ol.Observable {
607618
baseLayerInfo.url= 'http://www.google.cn/maps/vt/pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m3!1e0!2sm!3i380072576!3m8!2szh-CN!3scn!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e0!5m1!1e0';
608619
baseLayerInfo.epsgCode= 'EPSG:3857';
609620
baseLayerInfo.minZoom= 1;
610-
baseLayerInfo.maxZoom= 20;
611-
baseLayerInfo.level= 1;
612-
baseLayerInfo.extent= osmBounds;
613-
baseLayerInfo.iserverUrl= 'http://www.google.cn/maps';
614-
break;
615-
case ('GOOGLE_CN'):
616-
baseLayerInfo.url= 'https://mt{0-3}.google.cn/vt/lyrs=m&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}';
617-
baseLayerInfo.epsgCode= 'EPSG:3857';
618-
baseLayerInfo.minZoom= 1;
619-
baseLayerInfo.maxZoom= 20;
621+
baseLayerInfo.maxZoom= 22;
620622
baseLayerInfo.level= 1;
621623
baseLayerInfo.extent= osmBounds;
622624
baseLayerInfo.iserverUrl= 'http://www.google.cn/maps';
623625
break;
624-
case ('BING'):
625-
baseLayerInfo.url= 'http://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';
626-
baseLayerInfo.epsgCode= 'EPSG:3857';
627-
baseLayerInfo.minZoom= 1;
628-
baseLayerInfo.maxZoom= 18;
629-
baseLayerInfo.level= 1;
630-
baseLayerInfo.extent= osmBounds;
631-
baseLayerInfo.iserverUrl= 'https://cn.bing.com/maps';
632-
break;
633626
case ('JAPAN_STD'):
634627
baseLayerInfo.url= 'http://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png';
635628
baseLayerInfo.epsgCode= 'EPSG:3857';
@@ -686,19 +679,29 @@ export class WebMap extends ol.Observable {
686679
SecurityManager[`register${keyfix}`](keyParams, credential);
687680
}
688681
// extent: isBaseLayer ? layerInfo.extent : ol.proj.transformExtent(layerInfo.extent, layerInfo.projection, this.baseProjection),
689-
let source = new ol.source.TileSuperMapRest({
682+
let options = {
690683
transparent: true,
691684
url: layerInfo.url,
692685
wrapX: false,
693686
serverType: serverType,
694-
extent: this.baseLayerExtent,
687+
// extent: this.baseLayerExtent,
695688
prjCoordSys:{ epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1] },
696-
697689
tileProxy: this.tileProxy
698-
});
690+
};
691+
if(layerInfo.visibleScales){
692+
let result = this.getReslutionsFromScales(layerInfo.visibleScales, 96, layerInfo.coordUnit);
693+
let tileGrid = new ol.tilegrid.TileGrid({
694+
extent: layerInfo.extent,
695+
resolutions: result.res
696+
});
697+
layerInfo.visibleResolutions = result.res;
698+
options.tileGrid = tileGrid;
699+
}else{
700+
options.extent = this.baseLayerExtent;
701+
}
702+
let source = new ol.source.TileSuperMapRest(options);
699703
SecurityManager[`register${keyfix}`](layerInfo.url);
700704
return source;
701-
702705
}
703706
/**
704707
* @private
@@ -837,6 +840,42 @@ export class WebMap extends ol.Observable {
837840
}
838841
});
839842
}
843+
844+
/**
845+
* @private
846+
* @function ol.supermap.WebMap.prototype.getTileInfo
847+
* @description 获取rest map的图层参数。
848+
* @param {Object} layerInfo - 图层信息。
849+
* @param {function} callback - 获得wmts图层参数执行的回调函数
850+
*/
851+
getTileInfo(layerInfo, callback, mapInfo){
852+
let that = this;
853+
let url = layerInfo.url;
854+
let options = {
855+
withCredentials: this.withCredentials,
856+
withoutFormatSuffix: true
857+
};
858+
FetchRequest.get(url + ".json", null, options).then(function (response) {
859+
return response.json();
860+
}).then(function (result) {
861+
layerInfo.projection = mapInfo.projection;
862+
layerInfo.extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y];
863+
// 比例尺 单位
864+
if(result.visibleScales){
865+
layerInfo.visibleScales = result.visibleScales;
866+
layerInfo.coordUnit = result.coordUnit;
867+
}
868+
// 请求结果完成 继续添加图层
869+
if(mapInfo){
870+
callback(mapInfo, null, true, that);
871+
}else{
872+
callback(layerInfo);
873+
}
874+
875+
}).catch(function (error) {
876+
that.errorCallback && that.errorCallback(error, 'getWmtsFaild', that.map)
877+
});
878+
}
840879

841880
/**
842881
* @private

0 commit comments

Comments
 (0)