@@ -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.createXYZTileSource
@@ -1191,7 +1223,8 @@ export class WebMap extends Observable {
1191
1223
urls,
1192
1224
wrapX : false ,
1193
1225
crossOrigin : 'anonymous' ,
1194
- tileGrid
1226
+ tileGrid,
1227
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1195
1228
} ) ;
1196
1229
}
1197
1230
/**
@@ -1224,7 +1257,8 @@ export class WebMap extends Observable {
1224
1257
// crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
1225
1258
// extent: this.baseLayerExtent,
1226
1259
// prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1227
- format : layerInfo . format
1260
+ format : layerInfo . format ,
1261
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1228
1262
} ;
1229
1263
if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
1230
1264
options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1338,7 +1372,8 @@ export class WebMap extends Observable {
1338
1372
return new XYZ ( {
1339
1373
url : layerInfo . url ,
1340
1374
wrapX : false ,
1341
- crossOrigin : 'anonymous'
1375
+ crossOrigin : 'anonymous' ,
1376
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1342
1377
} ) ;
1343
1378
}
1344
1379
@@ -1360,9 +1395,7 @@ export class WebMap extends Observable {
1360
1395
VERSION : layerInfo . version || '1.3.0'
1361
1396
} ,
1362
1397
projection : layerInfo . projection || that . baseProjection ,
1363
- tileLoadFunction : function ( imageTile , src ) {
1364
- imageTile . getImage ( ) . src = src ;
1365
- }
1398
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1366
1399
} ) ;
1367
1400
}
1368
1401
@@ -1755,13 +1788,12 @@ export class WebMap extends Observable {
1755
1788
layerInfo . origin ,
1756
1789
layerInfo . matrixIds
1757
1790
) ,
1758
- tileLoadFunction : function ( imageTile , src ) {
1791
+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
1759
1792
if ( src . indexOf ( 'tianditu.gov.cn' ) >= 0 ) {
1760
- imageTile . getImage ( ) . src = `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
1761
- return ;
1793
+ return `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
1762
1794
}
1763
- imageTile . getImage ( ) . src = src ;
1764
- }
1795
+ return src ;
1796
+ } )
1765
1797
} ) ;
1766
1798
}
1767
1799
@@ -2956,13 +2988,15 @@ export class WebMap extends Observable {
2956
2988
} ;
2957
2989
let featureType = layerInfo . featureType ;
2958
2990
let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
2991
+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
2959
2992
return new olLayer . VectorTile ( {
2960
2993
//设置避让参数
2961
2994
source : new VectorTileSuperMapRest ( {
2962
2995
url : layerInfo . url ,
2963
2996
projection : layerInfo . projection ,
2964
2997
tileType : 'ScaleXY' ,
2965
- format : format
2998
+ format : format ,
2999
+ ...requestParameters
2966
3000
} ) ,
2967
3001
style : style
2968
3002
} ) ;
@@ -5123,7 +5157,6 @@ export class WebMap extends Observable {
5123
5157
* @param {Object } layerInfo - 图层信息
5124
5158
*/
5125
5159
createMVTLayer ( layerInfo ) {
5126
- // let that = this;
5127
5160
let styles = layerInfo . styles ;
5128
5161
const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
5129
5162
const visibleResolution = this . createVisibleResolution (
@@ -5136,13 +5169,15 @@ export class WebMap extends Observable {
5136
5169
const styleResolutions = this . getStyleResolutions ( envelope ) ;
5137
5170
// const origin = [envelope.left, envelope.top];
5138
5171
let withCredentials = this . isIportalProxyServiceUrl ( styles . sprite ) ;
5172
+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( styles . sprite ) ;
5139
5173
// 创建MapBoxStyle样式
5140
5174
let mapboxStyles = new MapboxStyles ( {
5141
5175
style : styles ,
5142
5176
source : styles . name ,
5143
5177
resolutions : styleResolutions ,
5144
5178
map : this . map ,
5145
- withCredentials
5179
+ withCredentials,
5180
+ ...requestParameters
5146
5181
} ) ;
5147
5182
return new Promise ( ( resolve ) => {
5148
5183
mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5158,7 +5193,8 @@ export class WebMap extends Observable {
5158
5193
format : new MVT ( {
5159
5194
featureClass : olRenderFeature
5160
5195
} ) ,
5161
- wrapX : false
5196
+ wrapX : false ,
5197
+ ...requestParameters
5162
5198
} ) ,
5163
5199
style : mapboxStyles . featureStyleFuntion ,
5164
5200
visible : layerInfo . visible ,
0 commit comments