@@ -130,6 +130,7 @@ export class WebMap extends Observable {
130
130
this . webMap = options . webMap ;
131
131
this . tileFormat = options . tileFormat && options . tileFormat . toLowerCase ( ) ;
132
132
this . restDataSingleRequestCount = options . restDataSingleRequestCount || 1000 ;
133
+ this . tileRequestParameters = options . tileRequestParameters ;
133
134
this . createMap ( options . mapSetting ) ;
134
135
if ( this . webMap ) {
135
136
// webmap有可能是url地址,有可能是webmap对象
@@ -589,7 +590,8 @@ export class WebMap extends Observable {
589
590
let options = {
590
591
serverType,
591
592
url,
592
- tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid
593
+ tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid ,
594
+ tileLoadFunction : me . getCustomTileLoadFunction ( )
593
595
} ;
594
596
if ( url && ! CommonUtil . isInTheSameDomain ( url ) && ! this . isIportalProxyServiceUrl ( url ) ) {
595
597
options . tileProxy = me . server + 'apps/viewer/getUrlResource.png?url=' ;
@@ -1176,6 +1178,36 @@ export class WebMap extends Observable {
1176
1178
break ;
1177
1179
}
1178
1180
}
1181
+
1182
+ getCustomTileLoadFunction ( transformImageUrl ) {
1183
+ const that = this ;
1184
+ if ( this . tileRequestParameters ) {
1185
+ return function ( imageTile , url ) {
1186
+ const src = transformImageUrl ? transformImageUrl ( url ) : url ;
1187
+ const requestParameters = that . tileRequestParameters ( src ) ;
1188
+ if ( requestParameters ) {
1189
+ FetchRequest . get ( src , null , {
1190
+ ...requestParameters ,
1191
+ withoutFormatSuffix : true
1192
+ } )
1193
+ . then ( function ( response ) {
1194
+ return response . blob ( ) ;
1195
+ } )
1196
+ . then ( function ( blob ) {
1197
+ const imageUrl = URL . createObjectURL ( blob ) ;
1198
+ imageTile . getImage ( ) . src = imageUrl ;
1199
+ } )
1200
+ . catch ( function ( error ) {
1201
+ console . error ( 'Error fetching the image:' , error ) ;
1202
+ imageTile . setState ( 'error' ) ;
1203
+ } ) ;
1204
+ } else {
1205
+ imageTile . getImage ( ) . src = src ;
1206
+ }
1207
+ }
1208
+ }
1209
+ }
1210
+
1179
1211
/**
1180
1212
* @private
1181
1213
* @function WebMap.prototype.createDynamicTiledSource
@@ -1206,7 +1238,8 @@ export class WebMap extends Observable {
1206
1238
// crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
1207
1239
// extent: this.baseLayerExtent,
1208
1240
// prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1209
- format : layerInfo . format
1241
+ format : layerInfo . format ,
1242
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1210
1243
} ;
1211
1244
if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
1212
1245
options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1320,7 +1353,8 @@ export class WebMap extends Observable {
1320
1353
return new XYZ ( {
1321
1354
url : layerInfo . url ,
1322
1355
wrapX : false ,
1323
- crossOrigin : 'anonymous'
1356
+ crossOrigin : 'anonymous' ,
1357
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1324
1358
} ) ;
1325
1359
}
1326
1360
@@ -1339,7 +1373,8 @@ export class WebMap extends Observable {
1339
1373
urls,
1340
1374
wrapX : false ,
1341
1375
crossOrigin : 'anonymous' ,
1342
- tileGrid
1376
+ tileGrid,
1377
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1343
1378
} ) ;
1344
1379
}
1345
1380
@@ -1361,9 +1396,7 @@ export class WebMap extends Observable {
1361
1396
VERSION : layerInfo . version || '1.3.0'
1362
1397
} ,
1363
1398
projection : layerInfo . projection || that . baseProjection ,
1364
- tileLoadFunction : function ( imageTile , src ) {
1365
- imageTile . getImage ( ) . src = src ;
1366
- }
1399
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1367
1400
} ) ;
1368
1401
}
1369
1402
@@ -1756,13 +1789,12 @@ export class WebMap extends Observable {
1756
1789
layerInfo . origin ,
1757
1790
layerInfo . matrixIds
1758
1791
) ,
1759
- tileLoadFunction : function ( imageTile , src ) {
1792
+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
1760
1793
if ( src . indexOf ( 'tianditu.gov.cn' ) >= 0 ) {
1761
- imageTile . getImage ( ) . src = `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
1762
- return ;
1794
+ return `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
1763
1795
}
1764
- imageTile . getImage ( ) . src = src ;
1765
- }
1796
+ return src ;
1797
+ } )
1766
1798
} ) ;
1767
1799
}
1768
1800
@@ -2958,13 +2990,15 @@ export class WebMap extends Observable {
2958
2990
} ;
2959
2991
let featureType = layerInfo . featureType ;
2960
2992
let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
2993
+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
2961
2994
return new olLayer . VectorTile ( {
2962
2995
//设置避让参数
2963
2996
source : new VectorTileSuperMapRest ( {
2964
2997
url : layerInfo . url ,
2965
2998
projection : layerInfo . projection ,
2966
2999
tileType : 'ScaleXY' ,
2967
- format : format
3000
+ format : format ,
3001
+ ...requestParameters
2968
3002
} ) ,
2969
3003
style : style
2970
3004
} ) ;
@@ -5081,7 +5115,6 @@ export class WebMap extends Observable {
5081
5115
* @param {Object } layerInfo - 图层信息
5082
5116
*/
5083
5117
createMVTLayer ( layerInfo ) {
5084
- // let that = this;
5085
5118
let styles = layerInfo . styles ;
5086
5119
const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
5087
5120
const visibleResolution = this . createVisibleResolution (
@@ -5094,13 +5127,15 @@ export class WebMap extends Observable {
5094
5127
const styleResolutions = this . getStyleResolutions ( envelope ) ;
5095
5128
// const origin = [envelope.left, envelope.top];
5096
5129
let withCredentials = this . isIportalProxyServiceUrl ( styles . sprite ) ;
5130
+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( styles . sprite ) ;
5097
5131
// 创建MapBoxStyle样式
5098
5132
let mapboxStyles = new MapboxStyles ( {
5099
5133
style : styles ,
5100
5134
source : styles . name ,
5101
5135
resolutions : styleResolutions ,
5102
5136
map : this . map ,
5103
- withCredentials
5137
+ withCredentials,
5138
+ ...requestParameters
5104
5139
} ) ;
5105
5140
return new Promise ( ( resolve ) => {
5106
5141
mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5116,7 +5151,8 @@ export class WebMap extends Observable {
5116
5151
format : new MVT ( {
5117
5152
featureClass : olRenderFeature
5118
5153
} ) ,
5119
- wrapX : false
5154
+ wrapX : false ,
5155
+ ...requestParameters
5120
5156
} ) ,
5121
5157
style : mapboxStyles . featureStyleFuntion ,
5122
5158
visible : layerInfo . visible ,
0 commit comments