@@ -3378,20 +3378,31 @@ export class WebMap extends Observable {
3378
3378
* @param {object } mapInfo - 地图信息
3379
3379
*/
3380
3380
getMBStyle ( mapInfo ) {
3381
- let baseLayer = mapInfo . baseLayer ,
3382
- url = baseLayer . dataSource . url ,
3383
- layerInfo = { } ;
3384
- return FetchRequest . get ( this . getRequestUrl ( url ) ) . then ( result => {
3381
+ let _this = this ,
3382
+ baseLayer = mapInfo . baseLayer ,
3383
+ dataSource = baseLayer . dataSource || { } ,
3384
+ { url, serverId } = dataSource ,
3385
+ layerInfo = { } ,
3386
+ styleUrl ;
3387
+ styleUrl = serverId !== undefined ? `${ this . server } web/datas/${ serverId } /download` : url ;
3388
+ return FetchRequest . get ( this . getRequestUrl ( styleUrl ) , null , {
3389
+ withCredentials : this . withCredentials ,
3390
+ withoutFormatSuffix : true ,
3391
+ headers : {
3392
+ 'Content-Type' : 'application/json;chartset=uft-8'
3393
+ }
3394
+ } ) . then ( result => {
3385
3395
return result . json ( ) ;
3386
3396
} ) . then ( styles => {
3397
+ _this . _matchStyleObject ( styles ) ;
3387
3398
let extent = styles . metadata . mapbounds ;
3388
3399
baseLayer . extent = extent ; // 这里把extent保存一下
3389
3400
3390
3401
layerInfo . projection = mapInfo . projection ,
3391
3402
layerInfo . epsgCode = mapInfo . projection ,
3392
3403
layerInfo . visible = baseLayer . visible ,
3393
3404
layerInfo . name = baseLayer . name ,
3394
- layerInfo . url = url ,
3405
+ layerInfo . url = styleUrl ,
3395
3406
layerInfo . sourceType = 'VECTOR_TILE' ,
3396
3407
layerInfo . layerType = 'VECTOR_TILE' ,
3397
3408
layerInfo . styles = styles ,
@@ -3408,6 +3419,23 @@ export class WebMap extends Observable {
3408
3419
} )
3409
3420
}
3410
3421
3422
+ /**
3423
+ * @private
3424
+ * @function mapboxgl.supermap.WebMap.prototype._matchStyleObject
3425
+ * @description 恢复 style 为标准格式。
3426
+ * @param {Object } style - mapbox 样式。
3427
+ */
3428
+ _matchStyleObject ( style ) {
3429
+ let { sprite, glyphs } = style ;
3430
+ if ( sprite && typeof sprite === 'object' ) {
3431
+ style . sprite = Object . values ( sprite ) [ 0 ] ;
3432
+ }
3433
+ if ( glyphs && typeof glyphs === 'object' ) {
3434
+ style . glyphs = Object . values ( glyphs ) [ 0 ] ;
3435
+ }
3436
+ }
3437
+
3438
+
3411
3439
/**
3412
3440
* @private
3413
3441
* @function ol.supermap.WebMap.prototype.createMVTLayer
0 commit comments