@@ -131,6 +131,7 @@ export class WebMap extends Observable {
131
131
this . webMap = options . webMap ;
132
132
this . tileFormat = options . tileFormat && options . tileFormat . toLowerCase ( ) ;
133
133
this . restDataSingleRequestCount = options . restDataSingleRequestCount || 1000 ;
134
+ this . tileRequestParameters = options . tileRequestParameters ;
134
135
this . createMap ( options . mapSetting ) ;
135
136
if ( this . webMap ) {
136
137
// webmap有可能是url地址,有可能是webmap对象
@@ -590,7 +591,8 @@ export class WebMap extends Observable {
590
591
let options = {
591
592
serverType,
592
593
url,
593
- tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid
594
+ tileGrid : TileSuperMapRest . optionsFromMapJSON ( url , result ) . tileGrid ,
595
+ tileLoadFunction : me . getCustomTileLoadFunction ( )
594
596
} ;
595
597
if ( url && ! CommonUtil . isInTheSameDomain ( url ) && ! this . isIportalProxyServiceUrl ( url ) ) {
596
598
options . tileProxy = me . server + 'apps/viewer/getUrlResource.png?url=' ;
@@ -1178,6 +1180,36 @@ export class WebMap extends Observable {
1178
1180
break ;
1179
1181
}
1180
1182
}
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
+
1181
1213
/**
1182
1214
* @private
1183
1215
* @function WebMap.prototype.createDynamicTiledSource
@@ -1208,7 +1240,8 @@ export class WebMap extends Observable {
1208
1240
// crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
1209
1241
// extent: this.baseLayerExtent,
1210
1242
// prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1211
- format : layerInfo . format
1243
+ format : layerInfo . format ,
1244
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1212
1245
} ;
1213
1246
if ( ! isBaseLayer && ! this . isCustomProjection ( this . baseProjection ) ) {
1214
1247
options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
@@ -1322,7 +1355,8 @@ export class WebMap extends Observable {
1322
1355
return new XYZ ( {
1323
1356
url : layerInfo . url ,
1324
1357
wrapX : false ,
1325
- crossOrigin : 'anonymous'
1358
+ crossOrigin : 'anonymous' ,
1359
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1326
1360
} ) ;
1327
1361
}
1328
1362
@@ -1368,7 +1402,8 @@ export class WebMap extends Observable {
1368
1402
wrapX : false ,
1369
1403
crossOrigin : 'anonymous' ,
1370
1404
tileGrid : this . _getTileGrid ( { origin, resolutions, tileSize } ) ,
1371
- projection : this . baseProjection
1405
+ projection : this . baseProjection ,
1406
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1372
1407
} ;
1373
1408
return new XYZ ( options ) ;
1374
1409
}
@@ -1399,9 +1434,7 @@ export class WebMap extends Observable {
1399
1434
VERSION : layerInfo . version || '1.3.0'
1400
1435
} ,
1401
1436
projection : layerInfo . projection || that . baseProjection ,
1402
- tileLoadFunction : function ( imageTile , src ) {
1403
- imageTile . getImage ( ) . src = src ;
1404
- }
1437
+ tileLoadFunction : this . getCustomTileLoadFunction ( )
1405
1438
} ) ;
1406
1439
}
1407
1440
@@ -1794,13 +1827,12 @@ export class WebMap extends Observable {
1794
1827
layerInfo . origin ,
1795
1828
layerInfo . matrixIds
1796
1829
) ,
1797
- tileLoadFunction : function ( imageTile , src ) {
1830
+ tileLoadFunction : this . getCustomTileLoadFunction ( function ( src ) {
1798
1831
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' ] } ` ;
1801
1833
}
1802
- imageTile . getImage ( ) . src = src ;
1803
- }
1834
+ return src ;
1835
+ } )
1804
1836
} ) ;
1805
1837
}
1806
1838
@@ -1951,7 +1983,7 @@ export class WebMap extends Observable {
1951
1983
await that . addLayer ( layer , null , layerIndex ) ;
1952
1984
that . layerAdded ++ ;
1953
1985
that . sendMapToUser ( len ) ;
1954
- return ;
1986
+ continue ;
1955
1987
}
1956
1988
if (
1957
1989
layer . layerType === 'MARKER' ||
@@ -2996,13 +3028,15 @@ export class WebMap extends Observable {
2996
3028
} ;
2997
3029
let featureType = layerInfo . featureType ;
2998
3030
let style = await StyleUtils . toOpenLayersStyle ( this . getDataVectorTileStyle ( featureType ) , featureType ) ;
3031
+ const requestParameters = this . tileRequestParameters && this . tileRequestParameters ( layerInfo . url ) ;
2999
3032
return new olLayer . VectorTile ( {
3000
3033
//设置避让参数
3001
3034
source : new VectorTileSuperMapRest ( {
3002
3035
url : layerInfo . url ,
3003
3036
projection : layerInfo . projection ,
3004
3037
tileType : 'ScaleXY' ,
3005
- format : format
3038
+ format : format ,
3039
+ ...requestParameters
3006
3040
} ) ,
3007
3041
style : style
3008
3042
} ) ;
@@ -5119,7 +5153,6 @@ export class WebMap extends Observable {
5119
5153
* @param {Object } layerInfo - 图层信息
5120
5154
*/
5121
5155
createMVTLayer ( layerInfo ) {
5122
- // let that = this;
5123
5156
let styles = layerInfo . styles ;
5124
5157
const indexbounds = styles && styles . metadata && styles . metadata . indexbounds ;
5125
5158
const visibleResolution = this . createVisibleResolution (
@@ -5131,14 +5164,22 @@ export class WebMap extends Observable {
5131
5164
const envelope = this . getEnvelope ( indexbounds , layerInfo . bounds ) ;
5132
5165
const styleResolutions = this . getStyleResolutions ( envelope ) ;
5133
5166
// 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 ) ;
5135
5174
// 创建MapBoxStyle样式
5136
5175
let mapboxStyles = new MapboxStyles ( {
5176
+ baseUrl,
5137
5177
style : styles ,
5138
5178
source : styles . name ,
5139
5179
resolutions : styleResolutions ,
5140
5180
map : this . map ,
5141
- withCredentials
5181
+ withCredentials,
5182
+ ...requestParameters
5142
5183
} ) ;
5143
5184
return new Promise ( ( resolve ) => {
5144
5185
mapboxStyles . on ( 'styleloaded' , function ( ) {
@@ -5148,13 +5189,15 @@ export class WebMap extends Observable {
5148
5189
//设置避让参数
5149
5190
declutter : true ,
5150
5191
source : new VectorTileSuperMapRest ( {
5192
+ baseUrl,
5151
5193
style : styles ,
5152
5194
withCredentials,
5153
5195
projection : layerInfo . projection ,
5154
5196
format : new MVT ( {
5155
5197
featureClass : olRenderFeature
5156
5198
} ) ,
5157
- wrapX : false
5199
+ wrapX : false ,
5200
+ ...requestParameters
5158
5201
} ) ,
5159
5202
style : mapboxStyles . featureStyleFuntion ,
5160
5203
visible : layerInfo . visible ,
0 commit comments