Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -r706d036ccdfef7da602fc13c992d75569e8c5d34 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 706d036ccdfef7da602fc13c992d75569e8c5d34) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -246,7 +246,7 @@ private void DrawInitialMapData() { - foreach (FeatureBasedMapData featureBasedMapData in GetFeatureBasedMapDataRecursively(Data)) + foreach (FeatureBasedMapData featureBasedMapData in Data.GetFeatureBasedMapDataRecursively()) { DrawMapData(featureBasedMapData); } @@ -266,7 +266,7 @@ private void HandleMapDataCollectionChange() { - var mapDataThatShouldBeDrawn = GetFeatureBasedMapDataRecursively(Data).ToList(); + var mapDataThatShouldBeDrawn = Data.GetFeatureBasedMapDataRecursively().ToList(); var drawnMapDataLookup = drawnMapDataList.ToDictionary(dmd => dmd.FeatureBasedMapData, dmd => dmd); DrawMissingMapDataOnCollectionChange(mapDataThatShouldBeDrawn, drawnMapDataLookup); @@ -332,25 +332,6 @@ map.Layers.Remove(drawnMapDataToRemove.FeatureBasedMapDataLayer); } - private static IEnumerable GetFeatureBasedMapDataRecursively(MapDataCollection mapDataCollection) - { - var featureBasedMapDataList = new List(); - - foreach (MapData mapData in mapDataCollection.Collection) - { - var nestedMapDataCollection = mapData as MapDataCollection; - if (nestedMapDataCollection != null) - { - featureBasedMapDataList.AddRange(GetFeatureBasedMapDataRecursively(nestedMapDataCollection)); - continue; - } - - featureBasedMapDataList.Add((FeatureBasedMapData) mapData); - } - - return featureBasedMapDataList; - } - private void MapFunctionActivateFunction(object sender, EventArgs e) { map.Cursor = defaultCursor; Index: Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -42,6 +42,7 @@ + Index: Core/Components/src/Core.Components.Gis/Data/MapDataCollectionExtensions.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/MapDataCollectionExtensions.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/MapDataCollectionExtensions.cs (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; + +namespace Core.Components.Gis.Data +{ + /// + /// Exentions methods for . + /// + public static class MapDataCollectionExtensions + { + /// + /// Gets all the recursively in the given . + /// + /// The collection to get all from. + /// An of . + /// Thrown when is null. + public static IEnumerable GetFeatureBasedMapDataRecursively(this MapDataCollection mapDataCollection) + { + if (mapDataCollection == null) + { + throw new ArgumentNullException(nameof(mapDataCollection)); + } + + var featureBasedMapDataList = new List(); + + foreach (MapData mapData in mapDataCollection.Collection) + { + var nestedMapDataCollection = mapData as MapDataCollection; + if (nestedMapDataCollection != null) + { + featureBasedMapDataList.AddRange(GetFeatureBasedMapDataRecursively(nestedMapDataCollection)); + continue; + } + + featureBasedMapDataList.Add((FeatureBasedMapData)mapData); + } + + return featureBasedMapDataList; + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -46,6 +46,7 @@ Properties\GlobalAssembly.cs + Index: Core/Components/test/Core.Components.Gis.Test/Data/MapDataCollectionExtensionsTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/MapDataCollectionExtensionsTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/MapDataCollectionExtensionsTest.cs (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -0,0 +1,71 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Components.Gis.Data; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data +{ + [TestFixture] + public class MapDataCollectionExtensionsTest + { + [Test] + public void GetFeatureBasedMapDataRecursively_MapDataCollectionNull_ThrowArgumentNullException() + { + // Setup + MapDataCollection collection = null; + + // Call + TestDelegate test = () => collection.GetFeatureBasedMapDataRecursively(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("mapDataCollection", exception.ParamName); + } + + [Test] + public void GetFeatureBasedMapDataRecursively_CollectionWithNestedData_ReturnAllFeatureBasedMapData() + { + // Setup + var line = new MapLineData("line"); + var polygon = new MapPolygonData("polygon"); + var nestedCollection = new MapDataCollection("nested"); + nestedCollection.Add(line); + nestedCollection.Add(polygon); + + var collection = new MapDataCollection("test"); + var point = new MapPointData("point"); + collection.Add(point); + collection.Add(nestedCollection); + + // Call + FeatureBasedMapData[] featureBasedMapDatas = collection.GetFeatureBasedMapDataRecursively().ToArray(); + + // Assert + Assert.AreEqual(3, featureBasedMapDatas.Length); + Assert.IsInstanceOf(featureBasedMapDatas[0]); + Assert.IsInstanceOf(featureBasedMapDatas[1]); + Assert.IsInstanceOf(featureBasedMapDatas[2]); + } + } +} \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -rdf867fb9bd84169c6a7f095f8483ccf5778d66c5 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision df867fb9bd84169c6a7f095f8483ccf5778d66c5) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Controls.TreeView; @@ -189,14 +190,16 @@ private StrictContextMenuItem CreateZoomToExtentsItem(MapDataCollection nodeData) { + var enabled = nodeData.GetFeatureBasedMapDataRecursively().Any(fbmd => fbmd.IsVisible); + return new StrictContextMenuItem($"&{MapResources.Ribbon_ZoomToAll}", - nodeData.IsVisible ? + enabled ? MapResources.MapLegendView_CreateZoomToExtentsItem_MapDataCollection_ZoomToAll_Tooltip : - MapResources.MapLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip, + MapResources.MapLegendView_CreateZoomToExtentsItem_MapDataCollection_ZoomToAllDisabled_Tooltip, MapResources.ZoomToAllIcon, (sender, args) => { MapControl?.ZoomToAllVisibleLayers(nodeData); }) { - Enabled = nodeData.IsVisible + Enabled = enabled }; } Index: Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs =================================================================== diff -u -rdf867fb9bd84169c6a7f095f8483ccf5778d66c5 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision df867fb9bd84169c6a7f095f8483ccf5778d66c5) +++ Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -283,6 +283,16 @@ } /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet er minstens één kaartlaag in deze kaartlagenmap zichtbaar zijn.. + /// + public static string MapLegendView_CreateZoomToExtentsItem_MapDataCollection_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("MapLegendView_CreateZoomToExtentsItem_MapDataCollection_ZoomToAllDisabled_Tooltip" + + "", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze kaartlaag precies in het beeld past.. /// public static string MapLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { Index: Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx =================================================================== diff -u -rdf867fb9bd84169c6a7f095f8483ccf5778d66c5 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx (.../Resources.resx) (revision df867fb9bd84169c6a7f095f8483ccf5778d66c5) +++ Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx (.../Resources.resx) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -256,6 +256,9 @@ Om het zoomniveau aan te passen moet de laag zichtbaar zijn. + + Om het zoomniveau aan te passen moet er minstens één kaartlaag in deze kaartlagenmap zichtbaar zijn. + Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze kaartlagenmap precies in het beeld passen. Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -rdf867fb9bd84169c6a7f095f8483ccf5778d66c5 -r6e008d39203d261ead7023eeab03f641915eab14 --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision df867fb9bd84169c6a7f095f8483ccf5778d66c5) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 6e008d39203d261ead7023eeab03f641915eab14) @@ -274,13 +274,15 @@ } [Test] - public void ContextMenuStrip_VisibleMapDataCollection_CallsContextMenuBuilderMethods() + public void ContextMenuStrip_MapDataCollectionWithVisibleFeatureBasedmapData_CallsContextMenuBuilderMethods() { // Setup - var mapDataCollection = new MapDataCollection("test data") + var mapPointData = new MapPointData("test") { IsVisible = true }; + var mapDataCollection = new MapDataCollection("test data"); + mapDataCollection.Add(mapPointData); var applicationFeatureCommandsStub = mocks.Stub(); var importCommandHandlerMock = mocks.Stub(); @@ -333,13 +335,15 @@ } [Test] - public void ContextMenuStrip_InvisibleMapDataCollection_CallsContextMenuBuilderMethods() + public void ContextMenuStrip_InvisibleFeatureBasedMapDataInMapDataCollection_CallsContextMenuBuilderMethods() { // Setup - var mapDataCollection = new MapDataCollection("test data") + var pointData = new MapPointData("test data") { IsVisible = false }; + var mapDataCollection = new MapDataCollection("test data"); + mapDataCollection.Add(pointData); var applicationFeatureCommandsStub = mocks.Stub(); var importCommandHandlerMock = mocks.Stub(); @@ -373,7 +377,7 @@ TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, "&Zoom naar alles", - "Om het zoomniveau aan te passen moet de laag zichtbaar zijn.", + "Om het zoomniveau aan te passen moet er minstens één kaartlaag in deze kaartlagenmap zichtbaar zijn.", Resources.ZoomToAllIcon, false); @@ -396,10 +400,9 @@ public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() { // Setup - var mapData = new MapDataCollection("A") - { - IsVisible = true - }; + var mapData = new MapDataCollection("A"); + var pointData = new MapPointData("B"); + mapData.Add(pointData); var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder);