@@ -235,13 +235,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
235235 const copyLayer = { ...matchLayer , ...layerInfo , id : copyLayerId } ;
236236 if ( l7LayerUtil . isL7Layer ( copyLayer ) ) {
237237 const layers = [ copyLayer ] ;
238- await l7LayerUtil . addL7Layers ( {
239- map : this . map ,
240- webMapInfo : { ...this . _mapInfo , layers, sources : this . _mapInfo . sources } ,
241- l7Layers : layers ,
242- spriteDatas : this . _spriteDatas ,
243- options : this . options
244- } ) ;
238+ const params = this . _getAddL7LayersParams ( layers , this . _mapInfo . sources , layers ) ;
239+ await l7LayerUtil . addL7Layers ( params ) ;
245240 } else {
246241 if ( typeof copyLayer . source === 'object' ) {
247242 this . map . addSource ( copyLayer . id , copyLayer . source ) ;
@@ -287,18 +282,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
287282 const fontFamilys = this . _getLabelFontFamily ( ) ;
288283 // 初始化 map
289284 const mapOptions = {
290- transformRequest : ( url , resourceType ) => {
291- const res = { url } ;
292- if (
293- resourceType === 'Tile' &&
294- this . options . iportalServiceProxyUrl &&
295- url . indexOf ( this . options . iportalServiceProxyUrl ) >= 0
296- ) {
297- res . credentials = 'include' ;
298- }
299- return res ;
300- } ,
301285 ...this . mapOptions ,
286+ transformRequest : this . _getTransformRequest ( ) ,
302287 container : this . options . target ,
303288 crs : this . _baseProjection ,
304289 center,
@@ -324,6 +309,23 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
324309 } ) ;
325310 }
326311
312+ _getTransformRequest ( ) {
313+ if ( this . mapOptions . transformRequest ) {
314+ return this . mapOptions . transformRequest ;
315+ }
316+ return ( url , resourceType ) => {
317+ if ( resourceType === 'Tile' ) {
318+ const withCredentials = this . options . iportalServiceProxyUrl && url . indexOf ( this . options . iportalServiceProxyUrl ) >= 0 ;
319+ return {
320+ url : url ,
321+ credentials : withCredentials ? 'include' : undefined ,
322+ ...( this . options . tileTransformRequest && this . options . tileTransformRequest ( url ) )
323+ } ;
324+ }
325+ return { url } ;
326+ }
327+ }
328+
327329 _registerMapCRS ( mapInfo ) {
328330 const { crs } = mapInfo ;
329331 let epsgCode = crs ;
@@ -423,16 +425,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
423425 } ) ;
424426 const l7Layers = layers . filter ( ( layer ) => l7LayerUtil . isL7Layer ( layer ) ) ;
425427 if ( l7Layers . length > 0 ) {
426- await l7LayerUtil . addL7Layers ( {
427- map : this . map ,
428- webMapInfo : { ...this . _mapInfo , layers, sources } ,
429- l7Layers,
430- spriteDatas : this . _spriteDatas ,
431- options : {
432- ...this . options ,
433- emitterEvent : this . fire . bind ( this )
434- }
435- } ) ;
428+ const params = this . _getAddL7LayersParams ( layers , sources , l7Layers ) ;
429+ await l7LayerUtil . addL7Layers ( params ) ;
436430 }
437431 this . _createLegendInfo ( ) ;
438432 this . _sendMapToUser ( ) ;
@@ -442,6 +436,20 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
442436 }
443437 }
444438
439+ _getAddL7LayersParams ( layers , sources , l7Layers ) {
440+ return {
441+ map : this . map ,
442+ webMapInfo : { ...this . _mapInfo , layers, sources } ,
443+ l7Layers,
444+ spriteDatas : this . _spriteDatas ,
445+ options : {
446+ ...this . options ,
447+ emitterEvent : this . fire . bind ( this ) ,
448+ transformRequest : this . _getTransformRequest ( )
449+ }
450+ }
451+ }
452+
445453 /**
446454 * @private
447455 * @function WebMapV3.prototype._setUniqueId
0 commit comments