@@ -52,11 +52,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
5252
5353 clean ( removeMap = true ) {
5454 if ( this . map ) {
55+ if ( this . _sourceListModel ) {
56+ this . _sourceListModel . destroy ( ) ;
57+ this . _sourceListModel = null ;
58+ }
5559 this . stopCanvg ( ) ;
5660 removeMap && this . map . remove ( ) ;
5761 this . map = null ;
5862 this . _legendList = [ ] ;
59- this . _sourceListModel = null ;
6063 this . center = null ;
6164 this . zoom = null ;
6265 if ( this . _dataflowService ) {
@@ -2229,6 +2232,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
22292232 _sendMapToUser ( count , layersLen ) {
22302233 if ( count === layersLen ) {
22312234 this . addLayersSucceededLen = this . _cacheLayerId . size ;
2235+ this . _changeSourceListModel ( ) ;
22322236 const appreciableLayers = this . getLayers ( ) ;
22332237 const layerOptions = this . _getSelfAppreciableLayers ( appreciableLayers ) ;
22342238 this . _rectifyLayersOrder ( layerOptions . layers ) ;
@@ -2772,41 +2776,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
27722776 const matchInsertIndex = matchIndex < 0 ? renderLayerList . length : matchIndex ;
27732777 renderLayerList . splice ( matchInsertIndex , 0 , ...renderLayers ) ;
27742778 }
2775- const layersFromMapInfo = [ ] ;
2776- const layerList = [ this . _mapInfo . baseLayer ] . concat ( this . _mapInfo . layers ) ;
2777- if ( this . _graticuleLayer ) {
2778- const { id : layerID , visible } = this . _graticuleLayer ;
2779- layerList . push ( { layerID, visible, name : 'GraticuleLayer' } ) ;
2780- }
2781- // this._mapInfo.layers 是有序的
2782- layerList . forEach ( ( layerInfo ) => {
2783- const targetLayerId = layerInfo . layerID || layerInfo . name ;
2784- const targetLayerVisible =
2785- layerInfo . visible === void 0 || layerInfo . visible === 'visible' || layerInfo . visible === true ;
2786- const matchLayers = this . _cacheLayerId . get ( targetLayerId ) ;
2787- if ( matchLayers ) {
2788- const renderLayers = matchLayers . map ( ( item ) => item . layerId ) ;
2789- if ( ! renderLayers . length ) {
2790- return ;
2791- }
2792- layersFromMapInfo . push ( {
2793- ...layerInfo ,
2794- id : targetLayerId ,
2795- visible : targetLayerVisible ,
2796- renderLayers,
2797- reused : matchLayers . some ( ( item ) => item . reused )
2798- } ) ;
2799- }
2800- } ) ;
2801- this . _changeSourceListModel ( layersFromMapInfo ) ;
2802- const appreciableLayers = this . getLayers ( ) ;
2803- if ( this . addLayersSucceededLen && this . _cacheLayerId . size !== this . addLayersSucceededLen ) {
2779+ if ( this . addLayersSucceededLen && this . _cacheLayerId . size <= this . expectLayerLen ) {
2780+ this . _changeSourceListModel ( ) ;
2781+ const appreciableLayers = this . getLayers ( ) ;
28042782 const selfAppreciableLayers = this . getSelfAppreciableLayers ( appreciableLayers ) ;
28052783 const topLayerBeforeId = this . _findTopLayerBeforeId ( selfAppreciableLayers ) ;
28062784 this . _rectifyLayersOrder ( selfAppreciableLayers , topLayerBeforeId ) ;
2807- this . addLayersSucceededLen = this . _cacheLayerId . size ;
2785+ this . fire ( 'layeraddchanged' , this . _getSelfAppreciableLayers ( appreciableLayers ) ) ;
28082786 }
2809- this . fire ( 'layeraddchanged' , this . _getSelfAppreciableLayers ( appreciableLayers ) ) ;
28102787 }
28112788
28122789 _findTopLayerBeforeId ( selfAppreciableLayers ) {
@@ -2831,22 +2808,53 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
28312808 }
28322809 }
28332810
2834- _changeSourceListModel ( layersFromMapInfo ) {
2811+ _changeSourceListModel ( ) {
2812+ const layersFromMapInfo = [ ] ;
2813+ const layerList = [ this . _mapInfo . baseLayer ] . concat ( this . _mapInfo . layers ) ;
2814+ if ( this . _graticuleLayer ) {
2815+ const { id : layerID , visible } = this . _graticuleLayer ;
2816+ layerList . push ( { layerID, visible, name : 'GraticuleLayer' } ) ;
2817+ }
2818+ // this._mapInfo.layers 是有序的
2819+ layerList . forEach ( ( layerInfo ) => {
2820+ const targetLayerId = layerInfo . layerID || layerInfo . name ;
2821+ const targetLayerVisible =
2822+ layerInfo . visible === void 0 || layerInfo . visible === 'visible' || layerInfo . visible === true ;
2823+ const matchLayers = this . _cacheLayerId . get ( targetLayerId ) ;
2824+ if ( matchLayers ) {
2825+ const renderLayers = matchLayers . map ( ( item ) => item . layerId ) ;
2826+ if ( ! renderLayers . length ) {
2827+ return ;
2828+ }
2829+ layersFromMapInfo . push ( {
2830+ ...layerInfo ,
2831+ id : targetLayerId ,
2832+ visible : targetLayerVisible ,
2833+ renderLayers,
2834+ reused : matchLayers . some ( ( item ) => item . reused )
2835+ } ) ;
2836+ }
2837+ } ) ;
28352838 if ( ! this . _sourceListModel ) {
28362839 this . _sourceListModel = new SourceListModelV2 ( {
28372840 map : this . map ,
28382841 layers : layersFromMapInfo ,
28392842 appendLayers : this . _appendLayers
28402843 } ) ;
2841- } else {
2842- this . _sourceListModel . setSelfLayers ( layersFromMapInfo ) ;
2844+ this . _sourceListModel . on ( {
2845+ layerupdatechanged : ( params ) => {
2846+ this . fire ( 'layerupdatechanged' , params ) ;
2847+ }
2848+ } ) ;
2849+ return ;
28432850 }
2851+ this . _sourceListModel . setSelfLayers ( layersFromMapInfo ) ;
28442852 }
28452853
28462854 _getSelfAppreciableLayers ( appreciableLayers ) {
28472855 return {
28482856 layers : this . getSelfAppreciableLayers ( appreciableLayers ) ,
2849- allLoaded : this . _cacheLayerId . size === this . addLayersSucceededLen
2857+ allLoaded : this . _cacheLayerId . size === this . expectLayerLen
28502858 } ;
28512859 }
28522860
0 commit comments