@@ -131,6 +131,7 @@ export class WebMap extends Observable {
131131 this . webMap = options . webMap ;
132132 this . tileFormat = options . tileFormat && options . tileFormat . toLowerCase ( ) ;
133133 this . restDataSingleRequestCount = options . restDataSingleRequestCount || 1000 ;
134+ this . tileRequestParameters = options . tileRequestParameters ;
134135 this . createMap ( options . mapSetting ) ;
135136 if ( this . webMap ) {
136137 // webmap有可能是url地址,有可能是webmap对象
@@ -590,7 +591,8 @@ export class WebMap extends Observable {
590591 let options = {
591592 serverType,
592593 url,
593- tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid
594+ tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid ,
595+ tileLoadFunction : me . getCustomTileLoadFunction ( )
594596 } ;
595597 if ( url && ! CommonUtil . isInTheSameDomain ( url ) && ! this . isIportalProxyServiceUrl ( url ) ) {
596598 options . tileProxy = me . server + 'apps/viewer/getUrlResource.png?url=' ;
@@ -1178,6 +1180,36 @@ export class WebMap extends Observable {
11781180 break ;
11791181 }
11801182 }
1183+
1184+ getCustomTileLoadFunction ( transformImageUrl ) {
1185+ const that = this ;
1186+ if ( this . tileRequestParameters ) {
1187+ return function ( imageTile , url ) {
1188+ const src = transformImageUrl ? transformImageUrl ( url ) : url ;
1189+ const requestParameters = that . tileRequestParameters ( src ) ;
1190+ if ( requestParameters ) {
1191+ FetchRequest . get ( src , null , {
1192+ ...requestParameters ,
1193+ withoutFormatSuffix : true
1194+ } )
1195+ . then ( function ( response ) {
1196+ return response . blob ( ) ;
1197+ } )
1198+ . then ( function ( blob ) {
1199+ const imageUrl = URL . createObjectURL ( blob ) ;
1200+ imageTile . getImage ( ) . src = imageUrl ;
1201+ } )
1202+ . catch ( function ( error ) {
1203+ console . error ( 'Error fetching the image:' , error ) ;
1204+ imageTile . setState ( 'error' ) ;
1205+ } ) ;
1206+ } else {
1207+ imageTile . getImage ( ) . src = src ;
1208+ }
1209+ }
1210+ }
1211+ }
1212+
11811213 /**
11821214 * @private
11831215 * @function WebMap.prototype.createDynamicTiledSource
@@ -1208,7 +1240,8 @@ export class WebMap extends Observable {
12081240 // crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
12091241 // extent: this.baseLayerExtent,
12101242 // prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1211- format : layerInfo . format
1243+ format : layerInfo . format ,
1244+ tileLoadFunction : this . getCustomTileLoadFunction ( )
12121245 } ;
12131246 if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
12141247 options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1322,7 +1355,8 @@ export class WebMap extends Observable {
13221355 return new XYZ ( {
13231356 url : layerInfo . url ,
13241357 wrapX : false ,
1325- crossOrigin : 'anonymous'
1358+ crossOrigin : 'anonymous' ,
1359+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13261360 } ) ;
13271361 }
13281362
@@ -1368,7 +1402,8 @@ export class WebMap extends Observable {
13681402 wrapX : false ,
13691403 crossOrigin : 'anonymous' ,
13701404 tileGrid : this . _getTileGrid ( { origin, resolutions, tileSize } ) ,
1371- projection : this . baseProjection
1405+ projection : this . baseProjection ,
1406+ tileLoadFunction : this . getCustomTileLoadFunction ( )
13721407 } ;
13731408 return new XYZ ( options ) ;
13741409 }
@@ -1399,9 +1434,7 @@ export class WebMap extends Observable {
13991434 VERSION : layerInfo . version || '1.3.0'
14001435 } ,
14011436 projection : layerInfo . projection || that . baseProjection ,
1402- tileLoadFunction : function ( imageTile , src ) {
1403- imageTile . getImage ( ) . src = src ;
1404- }
1437+ tileLoadFunction : this . getCustomTileLoadFunction ( )
14051438 } ) ;
14061439 }
14071440
@@ -1794,13 +1827,12 @@ export class WebMap extends Observable {
17941827 layerInfo . origin ,
17951828 layerInfo . matrixIds
17961829 ) ,
1797- tileLoadFunction : function ( imageTile , src ) {
1830+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
17981831 if ( src . indexOf ( 'tianditu.gov.cn' ) >= 0 ) {
1799- imageTile . getImage ( ) . src = `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
1800- return ;
1832+ return `${ src } &tk=${ CommonUtil . getParameters ( layerInfo . url ) [ 'tk' ] } ` ;
18011833 }
1802- imageTile . getImage ( ) . src = src ;
1803- }
1834+ return src ;
1835+ } )
18041836 } ) ;
18051837 }
18061838
@@ -1951,7 +1983,7 @@ export class WebMap extends Observable {
19511983 await that . addLayer ( layer , null , layerIndex ) ;
19521984 that . layerAdded ++ ;
19531985 that . sendMapToUser ( len ) ;
1954- return ;
1986+ continue ;
19551987 }
19561988 if (
19571989 layer . layerType === 'MARKER' ||
@@ -2996,13 +3028,15 @@ export class WebMap extends Observable {
29963028 } ;
29973029 let featureType = layerInfo . featureType ;
29983030 let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
3031+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
29993032 return new olLayer . VectorTile ( {
30003033 //设置避让参数
30013034 source : new VectorTileSuperMapRest ( {
30023035 url : layerInfo . url ,
30033036 projection : layerInfo . projection ,
30043037 tileType : 'ScaleXY' ,
3005- format : format
3038+ format : format ,
3039+ ...requestParameters
30063040 } ) ,
30073041 style : style
30083042 } ) ;
@@ -5119,7 +5153,6 @@ export class WebMap extends Observable {
51195153 * @param {Object } layerInfo - 图层信息
51205154 */
51215155 createMVTLayer ( layerInfo ) {
5122- // let that = this;
51235156 let styles = layerInfo . styles ;
51245157 const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
51255158 const visibleResolution = this . createVisibleResolution (
@@ -5131,14 +5164,22 @@ export class WebMap extends Observable {
51315164 const envelope = this . getEnvelope ( indexbounds , layerInfo . bounds ) ;
51325165 const styleResolutions = this . getStyleResolutions ( envelope ) ;
51335166 // const origin = [envelope.left, envelope.top];
5134- let withCredentials = this . isIportalProxyServiceUrl ( styles . sprite ) ;
5167+ let baseUrl = layerInfo . url && layerInfo . url . split ( '?' ) [ 0 ] ;
5168+ let spriteUrl = styles . sprite ;
5169+ if ( ! CommonUtil . isAbsoluteURL ( styles . sprite ) ) {
5170+ spriteUrl = CommonUtil . relative2absolute ( styles . sprite , baseUrl ) ;
5171+ }
5172+ let withCredentials = this . isIportalProxyServiceUrl ( spriteUrl ) ;
5173+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( spriteUrl ) ;
51355174 // 创建MapBoxStyle样式
51365175 let mapboxStyles = new MapboxStyles ( {
5176+ baseUrl,
51375177 style : styles ,
51385178 source : styles . name ,
51395179 resolutions : styleResolutions ,
51405180 map : this . map ,
5141- withCredentials
5181+ withCredentials,
5182+ ...requestParameters
51425183 } ) ;
51435184 return new Promise ( ( resolve ) => {
51445185 mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5148,13 +5189,15 @@ export class WebMap extends Observable {
51485189 //设置避让参数
51495190 declutter : true ,
51505191 source : new VectorTileSuperMapRest ( {
5192+ baseUrl,
51515193 style : styles ,
51525194 withCredentials,
51535195 projection : layerInfo . projection ,
51545196 format : new MVT ( {
51555197 featureClass : olRenderFeature
51565198 } ) ,
5157- wrapX : false
5199+ wrapX : false ,
5200+ ...requestParameters
51585201 } ) ,
51595202 style : mapboxStyles . featureStyleFuntion ,
51605203 visible : layerInfo . visible ,
0 commit comments