@@ -52,11 +52,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
52
52
53
53
clean ( removeMap = true ) {
54
54
if ( this . map ) {
55
+ if ( this . _sourceListModel ) {
56
+ this . _sourceListModel . destroy ( ) ;
57
+ this . _sourceListModel = null ;
58
+ }
55
59
this . stopCanvg ( ) ;
56
60
removeMap && this . map . remove ( ) ;
57
61
this . map = null ;
58
62
this . _legendList = [ ] ;
59
- this . _sourceListModel = null ;
60
63
this . center = null ;
61
64
this . zoom = null ;
62
65
if ( this . _dataflowService ) {
@@ -2229,6 +2232,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
2229
2232
_sendMapToUser ( count , layersLen ) {
2230
2233
if ( count === layersLen ) {
2231
2234
this . addLayersSucceededLen = this . _cacheLayerId . size ;
2235
+ this . _changeSourceListModel ( ) ;
2232
2236
const appreciableLayers = this . getLayers ( ) ;
2233
2237
const layerOptions = this . _getSelfAppreciableLayers ( appreciableLayers ) ;
2234
2238
this . _rectifyLayersOrder ( layerOptions . layers ) ;
@@ -2772,41 +2776,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
2772
2776
const matchInsertIndex = matchIndex < 0 ? renderLayerList . length : matchIndex ;
2773
2777
renderLayerList . splice ( matchInsertIndex , 0 , ...renderLayers ) ;
2774
2778
}
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 ( ) ;
2804
2782
const selfAppreciableLayers = this . getSelfAppreciableLayers ( appreciableLayers ) ;
2805
2783
const topLayerBeforeId = this . _findTopLayerBeforeId ( selfAppreciableLayers ) ;
2806
2784
this . _rectifyLayersOrder ( selfAppreciableLayers , topLayerBeforeId ) ;
2807
- this . addLayersSucceededLen = this . _cacheLayerId . size ;
2785
+ this . fire ( 'layeraddchanged' , this . _getSelfAppreciableLayers ( appreciableLayers ) ) ;
2808
2786
}
2809
- this . fire ( 'layeraddchanged' , this . _getSelfAppreciableLayers ( appreciableLayers ) ) ;
2810
2787
}
2811
2788
2812
2789
_findTopLayerBeforeId ( selfAppreciableLayers ) {
@@ -2831,22 +2808,53 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
2831
2808
}
2832
2809
}
2833
2810
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
+ } ) ;
2835
2838
if ( ! this . _sourceListModel ) {
2836
2839
this . _sourceListModel = new SourceListModelV2 ( {
2837
2840
map : this . map ,
2838
2841
layers : layersFromMapInfo ,
2839
2842
appendLayers : this . _appendLayers
2840
2843
} ) ;
2841
- } else {
2842
- this . _sourceListModel . setSelfLayers ( layersFromMapInfo ) ;
2844
+ this . _sourceListModel . on ( {
2845
+ layerupdatechanged : ( params ) => {
2846
+ this . fire ( 'layerupdatechanged' , params ) ;
2847
+ }
2848
+ } ) ;
2849
+ return ;
2843
2850
}
2851
+ this . _sourceListModel . setSelfLayers ( layersFromMapInfo ) ;
2844
2852
}
2845
2853
2846
2854
_getSelfAppreciableLayers ( appreciableLayers ) {
2847
2855
return {
2848
2856
layers : this . getSelfAppreciableLayers ( appreciableLayers ) ,
2849
- allLoaded : this . _cacheLayerId . size === this . addLayersSucceededLen
2857
+ allLoaded : this . _cacheLayerId . size === this . expectLayerLen
2850
2858
} ;
2851
2859
}
2852
2860
0 commit comments