Index: Core/Components/src/Core.Components.Gis/Helpers/MapDataCollectionHelper.cs =================================================================== diff -u -rad09bf3ef6fa7e53040d7e53fa68540f2f1e3336 -r19a92a9c3ec9073afdf1f13bf4d0acb83e996e26 --- Core/Components/src/Core.Components.Gis/Helpers/MapDataCollectionHelper.cs (.../MapDataCollectionHelper.cs) (revision ad09bf3ef6fa7e53040d7e53fa68540f2f1e3336) +++ Core/Components/src/Core.Components.Gis/Helpers/MapDataCollectionHelper.cs (.../MapDataCollectionHelper.cs) (revision 19a92a9c3ec9073afdf1f13bf4d0acb83e996e26) @@ -47,6 +47,22 @@ return GetMapDataRecursively(mapDataCollection).ToDictionary(child => child, child => child.IsVisible); } + /// + /// Gets the visibility states of the child of . + /// + /// The collection to get the child states from. + /// A dictionary with the child map data collection and visibility states. + /// Thrown when is null. + public static Dictionary GetNestedCollectionVisibilityStates(MapDataCollection mapDataCollection) + { + if (mapDataCollection == null) + { + throw new ArgumentNullException(nameof(mapDataCollection)); + } + + return GetMapDataCollectionRecursively(mapDataCollection).ToDictionary(child => child, child => child.GetVisibility()); + } + private static IEnumerable GetMapDataRecursively(MapDataCollection mapDataCollection) { var mapDataList = new List(); @@ -64,5 +80,22 @@ return mapDataList; } + + private static IEnumerable GetMapDataCollectionRecursively(MapDataCollection mapDataCollection) + { + var mapDataCollectionList = new List(); + + foreach (MapData mapData in mapDataCollection.Collection) + { + var nestedMapDataCollection = mapData as MapDataCollection; + if (nestedMapDataCollection != null) + { + mapDataCollectionList.AddRange(GetMapDataCollectionRecursively(nestedMapDataCollection)); + mapDataCollectionList.Add(nestedMapDataCollection); + } + } + + return mapDataCollectionList; + } } -} +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Helpers/MapDataCollectionHelperTest.cs =================================================================== diff -u -rc0b11bd2f03f6e836efa4cdc640ea974113712ec -r19a92a9c3ec9073afdf1f13bf4d0acb83e996e26 --- Core/Components/test/Core.Components.Gis.Test/Helpers/MapDataCollectionHelperTest.cs (.../MapDataCollectionHelperTest.cs) (revision c0b11bd2f03f6e836efa4cdc640ea974113712ec) +++ Core/Components/test/Core.Components.Gis.Test/Helpers/MapDataCollectionHelperTest.cs (.../MapDataCollectionHelperTest.cs) (revision 19a92a9c3ec9073afdf1f13bf4d0acb83e996e26) @@ -58,7 +58,7 @@ [Test] public void GetChildVisibilityStates_MapDataCollectionWithChildren_ReturnsDictionary() { - // Setup + // Setup var mapDataCollection = new MapDataCollection("test"); var mapData1 = new TestFeatureBasedMapData(); var mapData2 = new TestFeatureBasedMapData @@ -97,5 +97,63 @@ }; CollectionAssert.AreEqual(expectedDictionary, states); } + + [Test] + public void GetNestedCollectionVisibilityStates_MapDataCollectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => MapDataCollectionHelper.GetNestedCollectionVisibilityStates(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("mapDataCollection", exception.ParamName); + } + + [Test] + public void GetNestedCollectionVisibilityStates_MapDataCollectionWithoutChildren_ReturnsEmptyDictionary() + { + // Setup + var mapDataCollection = new MapDataCollection("test"); + + // Call + Dictionary states = MapDataCollectionHelper.GetNestedCollectionVisibilityStates(mapDataCollection); + + // Assert + CollectionAssert.IsEmpty(states); + } + + [Test] + public void GetNestedCollectionVisibilityStates_MapDataCollectionWithChildren_ReturnsDictionary() + { + // Setup + var mapDataCollection = new MapDataCollection("test"); + var mapData1 = new TestFeatureBasedMapData(); + var mapData2 = new TestFeatureBasedMapData + { + IsVisible = false + }; + var mapData3 = new TestFeatureBasedMapData + { + IsVisible = false + }; + var nestedCollection = new MapDataCollection("nested"); + nestedCollection.Add(mapData3); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(nestedCollection); + + // Call + Dictionary states = MapDataCollectionHelper.GetNestedCollectionVisibilityStates(mapDataCollection); + + // Assert + var expectedDictionary = new Dictionary + { + { + nestedCollection, MapDataCollectionVisibility.NotVisible + } + }; + CollectionAssert.AreEqual(expectedDictionary, states); + } } } \ No newline at end of file