@@ -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.createXYZTileSource
@@ -1191,7 +1223,8 @@ export class WebMap extends Observable {
11911223 urls,
11921224 wrapX : false ,
11931225 crossOrigin : 'anonymous' ,
1194- tileGrid
1226+ tileGrid,
1227+ tileLoadFunction : this . getCustomTileLoadFunction ( )
11951228 } ) ;
11961229 }
11971230 /**
@@ -1224,7 +1257,8 @@ export class WebMap extends Observable {
12241257 // crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
12251258 // extent: this.baseLayerExtent,
12261259 // prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1227- format : layerInfo . format
1260+ format : layerInfo . format ,
1261+ tileLoadFunction : this . getCustomTileLoadFunction ( )
12281262 } ;
12291263 if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
12301264 options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1338,7 +1372,8 @@ export class WebMap extends Observable {
13381372 return new XYZ ( {
13391373 url : layerInfo . url ,
13401374 wrapX : false ,
1341- crossOrigin : 'anonymous'
1375+ crossOrigin : 'anonymous' ,
1376+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13421377 } ) ;
13431378 }
13441379
@@ -1360,9 +1395,7 @@ export class WebMap extends Observable {
13601395 VERSION : layerInfo . version || '1.3.0'
13611396 } ,
13621397 projection : layerInfo . projection || that . baseProjection ,
1363- tileLoadFunction : function ( imageTile , src ) {
1364- imageTile . getImage ( ) . src = src ;
1365- }
1398+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13661399 } ) ;
13671400 }
13681401
@@ -1755,13 +1788,12 @@ export class WebMap extends Observable {
17551788 layerInfo . origin ,
17561789 layerInfo . matrixIds
17571790 ) ,
1758- tileLoadFunction : function ( imageTile , src ) {
1791+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
17591792 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' ] } ` ;
17621794 }
1763- imageTile . getImage ( ) . src = src ;
1764- }
1795+ return src ;
1796+ } )
17651797 } ) ;
17661798 }
17671799
@@ -2956,13 +2988,15 @@ export class WebMap extends Observable {
29562988 } ;
29572989 let featureType = layerInfo . featureType ;
29582990 let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
2991+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
29592992 return new olLayer . VectorTile ( {
29602993 //设置避让参数
29612994 source : new VectorTileSuperMapRest ( {
29622995 url : layerInfo . url ,
29632996 projection : layerInfo . projection ,
29642997 tileType : 'ScaleXY' ,
2965- format : format
2998+ format : format ,
2999+ ...requestParameters
29663000 } ) ,
29673001 style : style
29683002 } ) ;
@@ -5123,7 +5157,6 @@ export class WebMap extends Observable {
51235157 * @param {Object } layerInfo - 图层信息
51245158 */
51255159 createMVTLayer ( layerInfo ) {
5126- // let that = this;
51275160 let styles = layerInfo . styles ;
51285161 const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
51295162 const visibleResolution = this . createVisibleResolution (
@@ -5136,13 +5169,15 @@ export class WebMap extends Observable {
51365169 const styleResolutions = this . getStyleResolutions ( envelope ) ;
51375170 // const origin = [envelope.left, envelope.top];
51385171 let withCredentials = this . isIportalProxyServiceUrl ( styles . sprite ) ;
5172+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( styles . sprite ) ;
51395173 // 创建MapBoxStyle样式
51405174 let mapboxStyles = new MapboxStyles ( {
51415175 style : styles ,
51425176 source : styles . name ,
51435177 resolutions : styleResolutions ,
51445178 map : this . map ,
5145- withCredentials
5179+ withCredentials,
5180+ ...requestParameters
51465181 } ) ;
51475182 return new Promise ( ( resolve ) => {
51485183 mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5158,7 +5193,8 @@ export class WebMap extends Observable {
51585193 format : new MVT ( {
51595194 featureClass : olRenderFeature
51605195 } ) ,
5161- wrapX : false
5196+ wrapX : false ,
5197+ ...requestParameters
51625198 } ) ,
51635199 style : mapboxStyles . featureStyleFuntion ,
51645200 visible : layerInfo . visible ,
0 commit comments