Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs
===================================================================
diff -u -r99f3b343f5ac4aed453d9f6d291217de76ef5314 -r41af8c6e09c689cd4195e25bffca11ecb77b9035
--- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 99f3b343f5ac4aed453d9f6d291217de76ef5314)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 41af8c6e09c689cd4195e25bffca11ecb77b9035)
@@ -36,7 +36,7 @@
///
/// This class describes a map view with configured projection and function mode.
///
- public sealed class MapControl : Control, IMapControl, IObserver
+ public sealed class MapControl : Control, IMapControl
{
private readonly Cursor defaultCursor = Cursors.Default;
private readonly MapFeatureLayerFactory mapFeatureLayerFactory = new MapFeatureLayerFactory();
@@ -46,6 +46,8 @@
private MapFunctionSelectionZoom mapFunctionSelectionZoom;
private MouseCoordinatesMapExtension mouseCoordinatesMapExtension;
+ private readonly RecursiveObserver mapDataObserver;
+
///
/// Creates a new instance of .
///
@@ -55,8 +57,12 @@
TogglePanning();
Data = new MapDataCollection("Root");
- Data.Attach(this);
+ mapDataObserver = new RecursiveObserver(DrawFeatureSets, mdc => mdc.Collection)
+ {
+ Observable = Data
+ };
+
DrawFeatureSets();
}
@@ -116,15 +122,12 @@
Data = null;
}
- public void UpdateObserver()
- {
- DrawFeatureSets();
- }
-
protected override void Dispose(bool disposing)
{
map.Dispose();
mouseCoordinatesMapExtension.Dispose();
+ mapDataObserver.Dispose();
+
base.Dispose(disposing);
}
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs
===================================================================
diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -r41af8c6e09c689cd4195e25bffca11ecb77b9035
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 41af8c6e09c689cd4195e25bffca11ecb77b9035)
@@ -94,30 +94,49 @@
}
[Test]
- public void UpdateObserver_UpdateData_UpdateMap()
+ public void GivenMapControlWithMapData_WhenNestedMapDataAdded_MapControlUpdated()
{
- // Setup
+ // Given
using (var map = new MapControl())
{
var mapView = map.Controls.OfType