@@ -234,13 +234,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
234234 const copyLayer = { ...matchLayer , ...layerInfo , id : copyLayerId } ;
235235 if ( l7LayerUtil . isL7Layer ( copyLayer ) ) {
236236 const layers = [ copyLayer ] ;
237- await l7LayerUtil . addL7Layers ( {
238- map : this . map ,
239- webMapInfo : { ...this . _mapInfo , layers, sources : this . _mapInfo . sources } ,
240- l7Layers : layers ,
241- spriteDatas : this . _spriteDatas ,
242- options : this . options
243- } ) ;
237+ const params = this . _getAddL7LayersParams ( layers , this . _mapInfo . sources , layers ) ;
238+ await l7LayerUtil . addL7Layers ( params ) ;
244239 } else {
245240 if ( typeof copyLayer . source === 'object' ) {
246241 this . map . addSource ( copyLayer . id , copyLayer . source ) ;
@@ -286,18 +281,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
286281 const fontFamilys = this . _getLabelFontFamily ( ) ;
287282 // 初始化 map
288283 const mapOptions = {
289- transformRequest : ( url , resourceType ) => {
290- const res = { url } ;
291- if (
292- resourceType === 'Tile' &&
293- this . options . iportalServiceProxyUrl &&
294- url . indexOf ( this . options . iportalServiceProxyUrl ) >= 0
295- ) {
296- res . credentials = 'include' ;
297- }
298- return res ;
299- } ,
300284 ...this . mapOptions ,
285+ transformRequest : this . _getTransformRequest ( ) ,
301286 container : this . options . target ,
302287 crs : this . _baseProjection ,
303288 center,
@@ -323,6 +308,23 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
323308 } ) ;
324309 }
325310
311+ _getTransformRequest ( ) {
312+ if ( this . mapOptions . transformRequest ) {
313+ return this . mapOptions . transformRequest ;
314+ }
315+ return ( url , resourceType ) => {
316+ if ( resourceType === 'Tile' ) {
317+ const withCredentials = this . options . iportalServiceProxyUrl && url . indexOf ( this . options . iportalServiceProxyUrl ) >= 0 ;
318+ return {
319+ url : url ,
320+ credentials : withCredentials ? 'include' : undefined ,
321+ ...( this . options . tileTransformRequest && this . options . tileTransformRequest ( url ) )
322+ } ;
323+ }
324+ return { url } ;
325+ }
326+ }
327+
326328 _setBaseProjection ( ) {
327329 let crs = this . _mapInfo . crs ;
328330 let baseProjection = crs ;
@@ -441,16 +443,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
441443 } ) ;
442444 const l7Layers = layers . filter ( ( layer ) => l7LayerUtil . isL7Layer ( layer ) ) ;
443445 if ( l7Layers . length > 0 ) {
444- await l7LayerUtil . addL7Layers ( {
445- map : this . map ,
446- webMapInfo : { ...this . _mapInfo , layers, sources } ,
447- l7Layers,
448- spriteDatas : this . _spriteDatas ,
449- options : {
450- ...this . options ,
451- emitterEvent : this . fire . bind ( this )
452- }
453- } ) ;
446+ const params = this . _getAddL7LayersParams ( layers , sources , l7Layers ) ;
447+ await l7LayerUtil . addL7Layers ( params ) ;
454448 }
455449 this . _createLegendInfo ( ) ;
456450 this . _sendMapToUser ( ) ;
@@ -460,6 +454,20 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
460454 }
461455 }
462456
457+ _getAddL7LayersParams ( layers , sources , l7Layers ) {
458+ return {
459+ map : this . map ,
460+ webMapInfo : { ...this . _mapInfo , layers, sources } ,
461+ l7Layers,
462+ spriteDatas : this . _spriteDatas ,
463+ options : {
464+ ...this . options ,
465+ emitterEvent : this . fire . bind ( this ) ,
466+ transformRequest : this . _getTransformRequest ( )
467+ }
468+ }
469+ }
470+
463471 /**
464472 * @private
465473 * @function WebMapV3.prototype._setUniqueId
0 commit comments