@@ -166,6 +166,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
166
166
this . options = options ;
167
167
this . mapOptions = mapOptions ;
168
168
this . _mapResourceInfo = { } ;
169
+ this . _relatedInfo = options . relatedInfo !== undefined ? options . relatedInfo : { } ;
169
170
this . _sprite = '' ;
170
171
this . _spriteDatas = { } ;
171
172
this . _appendLayers = false ;
@@ -189,12 +190,11 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
189
190
this . _appendLayers = true ;
190
191
this . map = map ;
191
192
// 处理图层管理添加 sprite
192
- const { sources, sprite } = this . _mapInfo ;
193
- if ( sprite && sources ) {
194
- Object . keys ( sources ) . forEach ( ( sourceName ) => {
195
- if ( sources [ sourceName ] . type === 'vector' ) {
196
- this . map . style . addSprite ( sourceName , sprite ) ;
197
- }
193
+ const sprite = this . _mapInfo . sprite ;
194
+ if ( sprite ) {
195
+ this . _sprite = sprite ;
196
+ this . map . addStyle ( {
197
+ sprite
198
198
} ) ;
199
199
}
200
200
this . _initLayers ( ) ;
@@ -344,22 +344,26 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
344
344
* @function WebMap.prototype._initLayers
345
345
* @description emit 图层加载成功事件。
346
346
*/
347
- _initLayers ( ) {
347
+ async _initLayers ( ) {
348
348
if ( this . map . getCRS && this . map . getCRS ( ) . epsgCode !== this . _baseProjection ) {
349
349
this . fire ( 'projectionisnotmatch' ) ;
350
350
return ;
351
351
}
352
+ await this . _getSpriteDatas ( ) ;
352
353
if ( Object . prototype . toString . call ( this . mapId ) === '[object Object]' ) {
353
354
this . mapParams = {
354
355
title : this . _mapInfo . name ,
355
- description : ''
356
+ description : this . _relatedInfo . description
356
357
} ;
358
+ if ( this . _relatedInfo . projectInfo ) {
359
+ this . _mapResourceInfo = JSON . parse ( this . _relatedInfo . projectInfo ) ;
360
+ }
357
361
this . _createMapRelatedInfo ( ) ;
358
362
this . _addLayersToMap ( ) ;
359
363
return ;
360
364
}
361
- Promise . all ( [ this . _getMapRelatedInfo ( ) , this . _getSpriteDatas ( ) ] )
362
- . then ( ( [ relatedInfo ] ) => {
365
+ this . _getMapRelatedInfo ( )
366
+ . then ( ( relatedInfo ) => {
363
367
this . mapParams = {
364
368
title : this . _mapInfo . name ,
365
369
description : relatedInfo . description
@@ -642,17 +646,30 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
642
646
if ( ! sprite ) {
643
647
return ;
644
648
}
649
+
650
+ const spriteUrls = [ ] ;
645
651
if ( typeof sprite === 'string' ) {
646
- const url = sprite . replace ( / .+ ( w e b \/ m a p s \/ .+ ) / , `${ this . options . server } $1` ) ;
647
- return FetchRequest . get ( url , null , { withCredentials : this . options . withCredentials } )
648
- . then ( ( response ) => {
649
- return response . json ( ) ;
650
- } )
651
- . then ( ( res ) => {
652
- this . _spriteDatas = res ;
653
- } ) ;
652
+ spriteUrls . push ( sprite ) ;
653
+ } else if ( typeof sprite === 'object' ) {
654
+ Object . keys ( sprite ) . forEach ( ( sourceId ) => {
655
+ spriteUrls . push ( sprite [ sourceId ] ) ;
656
+ } ) ;
654
657
}
655
- this . _spriteDatas = sprite ;
658
+
659
+ return Promise . all ( spriteUrls . map ( ( url ) => this . _getSpriteData ( url ) ) ) . then ( ( allResults ) => {
660
+ allResults . forEach ( ( result ) => {
661
+ this . _spriteDatas = { ...this . _spriteDatas , ...result } ;
662
+ } ) ;
663
+ return ;
664
+ } ) ;
665
+ }
666
+
667
+ _getSpriteData ( sprite ) {
668
+ const url = sprite . replace ( / .+ ( w e b \/ m a p s \/ .+ ) / , `${ this . options . server } $1` ) ;
669
+ return FetchRequest . get ( url , null , { withCredentials : this . options . withCredentials } )
670
+ . then ( ( response ) => {
671
+ return response . json ( ) ;
672
+ } ) ;
656
673
}
657
674
658
675
_createLegendInfo ( ) {
0 commit comments