@@ -130,6 +130,7 @@ export class WebMap extends Observable {
130130 this . webMap = options . webMap ;
131131 this . tileFormat = options . tileFormat && options . tileFormat . toLowerCase ( ) ;
132132 this . restDataSingleRequestCount = options . restDataSingleRequestCount || 1000 ;
133+ this . tileRequestParameters = options . tileRequestParameters ;
133134 this . createMap ( options . mapSetting ) ;
134135 if ( this . webMap ) {
135136 // webmap有可能是url地址,有可能是webmap对象
@@ -589,7 +590,8 @@ export class WebMap extends Observable {
589590 let options = {
590591 serverType,
591592 url,
592- tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid
593+ tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid ,
594+ tileLoadFunction : me . getCustomTileLoadFunction ( )
593595 } ;
594596 if ( url && ! CommonUtil . isInTheSameDomain ( url ) && ! this . isIportalProxyServiceUrl ( url ) ) {
595597 options . tileProxy = me . server + 'apps/viewer/getUrlResource.png?url=' ;
@@ -1176,6 +1178,36 @@ export class WebMap extends Observable {
11761178 break ;
11771179 }
11781180 }
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+
11791211 /**
11801212 * @private
11811213 * @function WebMap.prototype.createDynamicTiledSource
@@ -1206,7 +1238,8 @@ export class WebMap extends Observable {
12061238 // crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
12071239 // extent: this.baseLayerExtent,
12081240 // prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1209- format : layerInfo . format
1241+ format : layerInfo . format ,
1242+ tileLoadFunction : this . getCustomTileLoadFunction ( )
12101243 } ;
12111244 if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
12121245 options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1320,7 +1353,8 @@ export class WebMap extends Observable {
13201353 return new XYZ ( {
13211354 url : layerInfo . url ,
13221355 wrapX : false ,
1323- crossOrigin : 'anonymous'
1356+ crossOrigin : 'anonymous' ,
1357+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13241358 } ) ;
13251359 }
13261360
@@ -1339,7 +1373,8 @@ export class WebMap extends Observable {
13391373 urls,
13401374 wrapX : false ,
13411375 crossOrigin : 'anonymous' ,
1342- tileGrid
1376+ tileGrid,
1377+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13431378 } ) ;
13441379 }
13451380
@@ -1361,9 +1396,7 @@ export class WebMap extends Observable {
13611396 VERSION : layerInfo . version || '1.3.0'
13621397 } ,
13631398 projection : layerInfo . projection || that . baseProjection ,
1364- tileLoadFunction : function ( imageTile , src ) {
1365- imageTile . getImage ( ) . src = src ;
1366- }
1399+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13671400 } ) ;
13681401 }
13691402
@@ -1756,13 +1789,12 @@ export class WebMap extends Observable {
17561789 layerInfo . origin ,
17571790 layerInfo . matrixIds
17581791 ) ,
1759- tileLoadFunction : function ( imageTile , src ) {
1792+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
17601793 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' ] } ` ;
17631795 }
1764- imageTile . getImage ( ) . src = src ;
1765- }
1796+ return src ;
1797+ } )
17661798 } ) ;
17671799 }
17681800
@@ -2958,13 +2990,15 @@ export class WebMap extends Observable {
29582990 } ;
29592991 let featureType = layerInfo . featureType ;
29602992 let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
2993+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
29612994 return new olLayer . VectorTile ( {
29622995 //设置避让参数
29632996 source : new VectorTileSuperMapRest ( {
29642997 url : layerInfo . url ,
29652998 projection : layerInfo . projection ,
29662999 tileType : 'ScaleXY' ,
2967- format : format
3000+ format : format ,
3001+ ...requestParameters
29683002 } ) ,
29693003 style : style
29703004 } ) ;
@@ -5081,7 +5115,6 @@ export class WebMap extends Observable {
50815115 * @param {Object } layerInfo - 图层信息
50825116 */
50835117 createMVTLayer ( layerInfo ) {
5084- // let that = this;
50855118 let styles = layerInfo . styles ;
50865119 const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
50875120 const visibleResolution = this . createVisibleResolution (
@@ -5094,13 +5127,15 @@ export class WebMap extends Observable {
50945127 const styleResolutions = this . getStyleResolutions ( envelope ) ;
50955128 // const origin = [envelope.left, envelope.top];
50965129 let withCredentials = this . isIportalProxyServiceUrl ( styles . sprite ) ;
5130+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( styles . sprite ) ;
50975131 // 创建MapBoxStyle样式
50985132 let mapboxStyles = new MapboxStyles ( {
50995133 style : styles ,
51005134 source : styles . name ,
51015135 resolutions : styleResolutions ,
51025136 map : this . map ,
5103- withCredentials
5137+ withCredentials,
5138+ ...requestParameters
51045139 } ) ;
51055140 return new Promise ( ( resolve ) => {
51065141 mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5116,7 +5151,8 @@ export class WebMap extends Observable {
51165151 format : new MVT ( {
51175152 featureClass : olRenderFeature
51185153 } ) ,
5119- wrapX : false
5154+ wrapX : false ,
5155+ ...requestParameters
51205156 } ) ,
51215157 style : mapboxStyles . featureStyleFuntion ,
51225158 visible : layerInfo . visible ,
0 commit comments