@@ -276,34 +276,38 @@ export class WebMap extends mapboxgl.Evented {
276276 * @description emit 图层加载成功事件。
277277 */
278278 async _addLayersToMap ( ) {
279- const { sources, layers, layerCatalog, catalogs } = this . _setUniqueId ( this . _mapInfo , this . _mapResourceInfo ) ;
280- Object . assign ( this . _mapInfo , {
281- sources,
282- layers,
283- metadata : Object . assign ( this . _mapInfo . metadata , { layerCatalog } )
284- } ) ;
285- Object . assign ( this . _mapResourceInfo , { catalogs } ) ;
286- const mapboxglLayers = layers . filter ( ( layer ) => ! isMapboxUnSupportLayer ( layer ) ) ;
287- mapboxglLayers . forEach ( ( layer ) => {
288- layer . source && ! this . map . getSource ( layer . source ) && this . map . addSource ( layer . source , sources [ layer . source ] ) ;
289- // L7才会用到此属性
290- if ( layer . type === 'symbol' && ( layer . layout || { } ) [ 'text-z-offset' ] === 0 ) {
291- delete layer . layout [ 'text-z-offset' ] ;
292- }
293- this . map . addLayer ( layer ) ;
294- } ) ;
295- const l7Layers = layers . filter ( ( layer ) => isMapboxUnSupportLayer ( layer ) ) ;
296- if ( l7Layers . length > 0 ) {
297- await addL7Layers ( {
298- map : this . map ,
299- webMapInfo : { ...this . _mapInfo , layers, sources } ,
300- l7Layers,
301- spriteDatas : this . _spriteDatas ,
302- options : this . options
279+ try {
280+ const { sources, layers, layerCatalog, catalogs } = this . _setUniqueId ( this . _mapInfo , this . _mapResourceInfo ) ;
281+ Object . assign ( this . _mapInfo , {
282+ sources,
283+ layers,
284+ metadata : Object . assign ( this . _mapInfo . metadata , { layerCatalog } )
303285 } ) ;
286+ Object . assign ( this . _mapResourceInfo , { catalogs } ) ;
287+ const mapboxglLayers = layers . filter ( ( layer ) => ! isMapboxUnSupportLayer ( layer ) ) ;
288+ mapboxglLayers . forEach ( ( layer ) => {
289+ layer . source && ! this . map . getSource ( layer . source ) && this . map . addSource ( layer . source , sources [ layer . source ] ) ;
290+ // L7才会用到此属性
291+ if ( layer . type === 'symbol' && ( layer . layout || { } ) [ 'text-z-offset' ] === 0 ) {
292+ delete layer . layout [ 'text-z-offset' ] ;
293+ }
294+ this . map . addLayer ( layer ) ;
295+ } ) ;
296+ const l7Layers = layers . filter ( ( layer ) => isMapboxUnSupportLayer ( layer ) ) ;
297+ if ( l7Layers . length > 0 ) {
298+ await addL7Layers ( {
299+ map : this . map ,
300+ webMapInfo : { ...this . _mapInfo , layers, sources } ,
301+ l7Layers,
302+ spriteDatas : this . _spriteDatas ,
303+ options : this . options
304+ } ) ;
305+ }
306+ this . _createLegendInfo ( ) ;
307+ this . _sendMapToUser ( ) ;
308+ } catch ( error ) {
309+ this . fire ( 'getlayersfailed' , { error, map : this . map } ) ;
304310 }
305- this . _createLegendInfo ( ) ;
306- this . _sendMapToUser ( ) ;
307311 }
308312
309313 /**
@@ -553,7 +557,7 @@ export class WebMap extends mapboxgl.Evented {
553557 _generateLayerCatalog ( ) {
554558 const { layerCatalog } = this . _mapInfo . metadata ;
555559 const layerIdsFromCatalog = layerCatalog . reduce ( ( ids , item ) => {
556- const list = this . _collectChildrenKey ( [ item ] , 'id' ) ;
560+ const list = this . _collectChildrenKey ( [ item ] , [ 'id' , 'parts' ] ) ;
557561 ids . push ( ...list ) ;
558562 return ids ;
559563 } , [ ] ) ;
@@ -602,18 +606,28 @@ export class WebMap extends mapboxgl.Evented {
602606
603607 _updateLayerVisible ( catalogs ) {
604608 for ( const data of catalogs ) {
605- const list = this . _collectChildrenKey ( [ data ] , 'visible' ) ;
609+ const list = this . _collectChildrenKey ( [ data ] , [ 'visible' ] ) ;
606610 data . visible = list . every ( ( item ) => item ) ;
607611 }
608612 }
609613
610- _collectChildrenKey ( catalogs , key , list = [ ] ) {
614+ _collectChildrenKey ( catalogs , keys , list = [ ] ) {
611615 for ( const data of catalogs ) {
612616 if ( data . type === 'group' ) {
613- this . _collectChildrenKey ( data . children , key , list ) ;
617+ this . _collectChildrenKey ( data . children , keys , list ) ;
614618 continue ;
615619 }
616- list . push ( data [ key ] ) ;
620+ keys . forEach ( item => {
621+ if ( ! ( item in data ) ) {
622+ return ;
623+ }
624+ const value = data [ item ] ;
625+ if ( value instanceof Array ) {
626+ list . push ( ...value ) ;
627+ return ;
628+ }
629+ list . push ( value ) ;
630+ } ) ;
617631 }
618632 return list ;
619633 }
0 commit comments