@@ -166,6 +166,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
166166 this . options = options ;
167167 this . mapOptions = mapOptions ;
168168 this . _mapResourceInfo = { } ;
169+ this . _relatedInfo = options . relatedInfo !== undefined ? options . relatedInfo : { } ;
169170 this . _sprite = '' ;
170171 this . _spriteDatas = { } ;
171172 this . _appendLayers = false ;
@@ -189,12 +190,11 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
189190 this . _appendLayers = true ;
190191 this . map = map ;
191192 // 处理图层管理添加 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
198198 } ) ;
199199 }
200200 this . _initLayers ( ) ;
@@ -344,22 +344,26 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
344344 * @function WebMap.prototype._initLayers
345345 * @description emit 图层加载成功事件。
346346 */
347- _initLayers ( ) {
347+ async _initLayers ( ) {
348348 if ( this . map . getCRS && this . map . getCRS ( ) . epsgCode !== this . _baseProjection ) {
349349 this . fire ( 'projectionisnotmatch' ) ;
350350 return ;
351351 }
352+ await this . _getSpriteDatas ( ) ;
352353 if ( Object . prototype . toString . call ( this . mapId ) === '[object Object]' ) {
353354 this . mapParams = {
354355 title : this . _mapInfo . name ,
355- description : ''
356+ description : this . _relatedInfo . description
356357 } ;
358+ if ( this . _relatedInfo . projectInfo ) {
359+ this . _mapResourceInfo = JSON . parse ( this . _relatedInfo . projectInfo ) ;
360+ }
357361 this . _createMapRelatedInfo ( ) ;
358362 this . _addLayersToMap ( ) ;
359363 return ;
360364 }
361- Promise . all ( [ this . _getMapRelatedInfo ( ) , this . _getSpriteDatas ( ) ] )
362- . then ( ( [ relatedInfo ] ) => {
365+ this . _getMapRelatedInfo ( )
366+ . then ( ( relatedInfo ) => {
363367 this . mapParams = {
364368 title : this . _mapInfo . name ,
365369 description : relatedInfo . description
@@ -642,17 +646,30 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
642646 if ( ! sprite ) {
643647 return ;
644648 }
649+
650+ const spriteUrls = [ ] ;
645651 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+ } ) ;
654657 }
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+ } ) ;
656673 }
657674
658675 _createLegendInfo ( ) {
0 commit comments