Index: src/DeltaShell/DeltaShell.Plugins.SharpMapGis/BackGroundMapLayer.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/DeltaShell/DeltaShell.Plugins.SharpMapGis/BackGroundMapLayer.cs (.../BackGroundMapLayer.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/DeltaShell/DeltaShell.Plugins.SharpMapGis/BackGroundMapLayer.cs (.../BackGroundMapLayer.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -16,51 +16,80 @@ /// public class BackGroundMapLayer : GroupLayer // TODO: rename to BackgroundMapLayer { - private static readonly ILog log = LogManager.GetLogger(typeof(BackGroundMapLayer)); - + private Map lastUpdatedMap; // TODO: what is this for?? private Map backgroundMap; private bool backgroundMapChanged; + public BackGroundMapLayer() + { + Selectable = false; + } + + public BackGroundMapLayer(Map map) : this() + { + BackgroundMap = map; + } + + [NoNotifyCollectionChange] + public override IEventedList Layers + { + get + { + if (backgroundMapChanged) + { + backgroundMapChanged = false; + UpdateLayers(); + } + + return base.Layers; + } + + set + { + base.Layers = value; + } + } + + public override bool ReadOnly + { + get + { + return true; + } + } + /// /// Map used a basis for this grouplayer /// [NoNotifyPropertyChange] public Map BackgroundMap { - get { return backgroundMap; } + get + { + return backgroundMap; + } set { UnsubscribeFromBackgroundMap(); backgroundMap = value; SubscribeToBackgroundMap(); - + // mark background map as dirty to make sure that layers will be updated (using lazy way) backgroundMapChanged = true; RenderRequired = true; } } - public BackGroundMapLayer() - { - Selectable = false; - } - - public BackGroundMapLayer(Map map):this() - { - BackgroundMap = map; - - } - public void UnsubscribeFromBackgroundMap() { - if(backgroundMap == null) + if (backgroundMap == null) { return; } - ((INotifyCollectionChange)backgroundMap).CollectionChanged -= BackgroundMapCollectionChanged; + ((INotifyCollectionChange) backgroundMap).CollectionChanged -= BackgroundMapCollectionChanged; } public void SubscribeToBackgroundMap() @@ -70,37 +99,31 @@ return; } - ((INotifyCollectionChange)backgroundMap).CollectionChanged += BackgroundMapCollectionChanged; + ((INotifyCollectionChange) backgroundMap).CollectionChanged += BackgroundMapCollectionChanged; } - void BackgroundMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) - { - backgroundMapChanged = true; - RenderRequired = true; - } - public void UpdateLayers() { if (BackgroundMap == null) { Layers.Clear(); return; } - + Name = string.Format(Resources.BackGroundMapLayer_UpdateLayers_Background_BackgroundMapName, BackgroundMap.Name); // check if we need to update layers bool updateLayers = false; - if(Layers.Count != backgroundMap.Layers.Count) + if (Layers.Count != backgroundMap.Layers.Count) { updateLayers = true; } else { for (var i = 0; i < Layers.Count; i++) { - if(Layers[i].DataSource != backgroundMap.Layers[i].DataSource + if (Layers[i].DataSource != backgroundMap.Layers[i].DataSource || Layers[i].Visible != backgroundMap.Layers[i].Visible) { updateLayers = true; @@ -109,7 +132,7 @@ } } - if(!updateLayers) + if (!updateLayers) { return; } @@ -129,7 +152,7 @@ Layers.Clear(); foreach (var layer in BackgroundMap.Layers) { - var clone = (ILayer)layer.Clone(); + var clone = (ILayer) layer.Clone(); clone.Selectable = false; Layers.Add(clone); } @@ -145,33 +168,14 @@ //set the map of the group layer to check if it was changed after lastUpdatedMap = BackgroundMap; //set renderrequired to true because we want the treeview and legendview to update... - + SubscribeToBackgroundMap(); } - [NoNotifyCollectionChange] - public override IEventedList Layers + private void BackgroundMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { - get - { - if(backgroundMapChanged) - { - backgroundMapChanged = false; - UpdateLayers(); - } - - return base.Layers; - } - - set { base.Layers = value; } + backgroundMapChanged = true; + RenderRequired = true; } - - public override bool ReadOnly - { - get - { - return true; - } - } } } \ No newline at end of file