@@ -85,6 +85,7 @@ const dpiConfig = {
85
85
* @param {Object } [options.serviceProxy] - iportal内置代理信息, 仅矢量瓦片图层上图才会使用
86
86
* @param {string } [options.tiandituKey] - 天地图的key
87
87
* @param {string } [options.proxy] - 代理地址,当域名不一致,请求会加上代理。避免跨域
88
+ * @param {string } [options.tileFormat] - 地图瓦片出图格式,png/webp
88
89
* @param {function } [options.mapSetting.mapClickCallback] - 地图被点击的回调函数
89
90
* @param {function } [options.mapSetting.overlays] - 地图的overlayer
90
91
* @param {function } [options.mapSetting.controls] - 地图的控件
@@ -118,6 +119,7 @@ export class WebMap extends Observable {
118
119
this . layers = [ ] ;
119
120
this . events = new Events ( this , null , [ "updateDataflowFeature" ] , true ) ;
120
121
this . webMap = options . webMap ;
122
+ this . tileFormat = options . tileFormat ;
121
123
this . createMap ( options . mapSetting ) ;
122
124
if ( this . webMap ) {
123
125
// webmap有可能是url地址,有可能是webmap对象
@@ -1235,7 +1237,7 @@ export class WebMap extends Observable {
1235
1237
*/
1236
1238
getTileLayerExtentInfo ( layerInfo , isDynamic = true ) {
1237
1239
let that = this ,
1238
- // token,
1240
+ token ,
1239
1241
url = layerInfo . url . trim ( ) ,
1240
1242
credential = layerInfo . credential ,
1241
1243
options = {
@@ -1253,22 +1255,26 @@ export class WebMap extends Observable {
1253
1255
}
1254
1256
if ( credential ) {
1255
1257
url = `${ url } &token=${ encodeURI ( credential . token ) } ` ;
1256
- // token = credential.token;
1258
+ token = credential . token ;
1257
1259
}
1258
1260
return FetchRequest . get ( that . getRequestUrl ( `${ url } .json` ) , null , options ) . then ( function ( response ) {
1259
1261
return response . json ( ) ;
1260
1262
} ) . then ( async ( result ) => {
1261
1263
if ( result . succeed === false ) {
1262
1264
return result
1263
1265
}
1264
- // let isSupportWebp = await that.isSupportWebp(layerInfo.url, token);
1266
+ let format = 'png' ;
1267
+ if ( that . tileFormat === 'WebP' ) {
1268
+ const isSupportWebp = await that . isSupportWebp ( layerInfo . url , token ) ;
1269
+ format = isSupportWebp ? 'webp' : 'png' ;
1270
+ }
1265
1271
return {
1266
1272
units : result . coordUnit && result . coordUnit . toLowerCase ( ) ,
1267
1273
coordUnit : result . coordUnit ,
1268
1274
visibleScales : result . visibleScales ,
1269
1275
extent : [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ,
1270
1276
projection : `EPSG:${ result . prjCoordSys . epsgCode } ` ,
1271
- format : 'png'
1277
+ format
1272
1278
}
1273
1279
} ) . catch ( ( error ) => {
1274
1280
return {
@@ -1298,7 +1304,7 @@ export class WebMap extends Observable {
1298
1304
}
1299
1305
return FetchRequest . get ( that . getRequestUrl ( `${ layerInfo . url } .json` ) , null , options ) . then ( function ( response ) {
1300
1306
return response . json ( ) ;
1301
- } ) . then ( function ( result ) {
1307
+ } ) . then ( async function ( result ) {
1302
1308
// layerInfo.projection = mapInfo.projection;
1303
1309
// layerInfo.extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y];
1304
1310
// 比例尺 单位
@@ -1311,11 +1317,13 @@ export class WebMap extends Observable {
1311
1317
}
1312
1318
layerInfo . maxZoom = result . maxZoom ;
1313
1319
layerInfo . maxZoom = result . minZoom ;
1314
- // let token = layerInfo.credential ? layerInfo.credential.token : undefined;
1315
- // let isSupprtWebp = await that.isSupportWebp(layerInfo.url, token);
1316
- // eslint-disable-next-line require-atomic-updates
1317
- // layerInfo.format = isSupprtWebp ? 'webp' : 'png';
1320
+ let token = layerInfo . credential ? layerInfo . credential . token : undefined ;
1318
1321
layerInfo . format = 'png' ;
1322
+ // china_dark为默认底图,还是用png出图
1323
+ if ( that . tileFormat === 'WebP' && layerInfo . url !== 'https://maptiles.supermapol.com/iserver/services/map_China/rest/maps/China_Dark' ) {
1324
+ const isSupprtWebp = await that . isSupportWebp ( layerInfo . url , token ) ;
1325
+ layerInfo . format = isSupprtWebp ? 'webp' : 'png' ;
1326
+ }
1319
1327
// 请求结果完成 继续添加图层
1320
1328
if ( mapInfo ) {
1321
1329
//todo 这个貌似没有用到,下次优化
@@ -4597,36 +4605,36 @@ export class WebMap extends Observable {
4597
4605
* @param {* } token 服务token
4598
4606
* @returns {boolean }
4599
4607
*/
4600
- // isSupportWebp(url, token) {
4601
- // // 还需要判断浏览器
4602
- // let isIE = this.isIE();
4603
- // if (isIE || (this.isFirefox() && this.getFirefoxVersion() < 65) ||
4604
- // (this.isChrome() && this.getChromeVersion() < 32)) {
4605
- // return false;
4606
- // }
4607
- // url = token ? `${url}/tileImage.webp?token=${token}` : `${url}/tileImage.webp`;
4608
- // let isSameDomain = CommonUtil.isInTheSameDomain(url), excledeCreditial;
4609
- // if (isSameDomain && !token) {
4610
- // // online上服务域名一直,要用token值
4611
- // excledeCreditial = false;
4612
- // } else {
4613
- // excledeCreditial = true;
4614
- // }
4615
- // url = this.getRequestUrl(url, excledeCreditial);
4616
- // return FetchRequest.get(url, null, {
4617
- // withCredentials: this.withCredentials,
4618
- // withoutFormatSuffix: true
4619
- // }).then(function (response) {
4620
- // if (response.status !== 200) {
4621
- // throw response.status;
4622
- // }
4623
- // return response;
4624
- // }).then(() => {
4625
- // return true;
4626
- // }).catch(() => {
4627
- // return false;
4628
- // })
4629
- // }
4608
+ isSupportWebp ( url , token ) {
4609
+ // 还需要判断浏览器
4610
+ let isIE = this . isIE ( ) ;
4611
+ if ( isIE || ( this . isFirefox ( ) && this . getFirefoxVersion ( ) < 65 ) ||
4612
+ ( this . isChrome ( ) && this . getChromeVersion ( ) < 32 ) ) {
4613
+ return false ;
4614
+ }
4615
+ url = token ? `${ url } /tileImage.webp?token=${ token } ` : `${ url } /tileImage.webp` ;
4616
+ let isSameDomain = CommonUtil . isInTheSameDomain ( url ) , excledeCreditial ;
4617
+ if ( isSameDomain && ! token ) {
4618
+ // online上服务域名一直,要用token值
4619
+ excledeCreditial = false ;
4620
+ } else {
4621
+ excledeCreditial = true ;
4622
+ }
4623
+ url = this . getRequestUrl ( url , excledeCreditial ) ;
4624
+ return FetchRequest . get ( url , null , {
4625
+ withCredentials : this . withCredentials ,
4626
+ withoutFormatSuffix : true
4627
+ } ) . then ( function ( response ) {
4628
+ if ( response . status !== 200 ) {
4629
+ throw response . status ;
4630
+ }
4631
+ return response ;
4632
+ } ) . then ( ( ) => {
4633
+ return true ;
4634
+ } ) . catch ( ( ) => {
4635
+ return false ;
4636
+ } )
4637
+ }
4630
4638
/**
4631
4639
* @private
4632
4640
* @function ol.supermap.WebMap.prototype.isIE
0 commit comments