Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj
===================================================================
diff -u -r884543108a6db82b36fca454624a7e9aacaf801d -r1d8207d879e9aca8d34bd5b62410c04229c7d0d5
--- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 884543108a6db82b36fca454624a7e9aacaf801d)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -91,6 +91,9 @@
Properties\GlobalAssembly.cs
+
+ UserControl
+ Component
Index: Core/Components/src/Core.Components.DotSpatial.Forms/DotSpatialMap.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial.Forms/DotSpatialMap.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/DotSpatialMap.cs (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -0,0 +1,86 @@
+// 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 DotSpatial.Controls;
+using DotSpatial.Data;
+
+namespace Core.Components.DotSpatial.Forms
+{
+ ///
+ /// The DotSpatial Map Control for 2D applications.
+ ///
+ /// This class was introduced to prevent a when zooming in on
+ /// an extent smaller than 1e-7 and should be removed when DotSpatial solved the issue.
+ public class DotSpatialMap : Map
+ {
+ private const double minExt = 1e-7;
+
+ ///
+ /// Fires the ViewExtentsChanged event. Corrects the ViewExtent if it is smaller than 1e-7. If ZoomOutFartherThanMaxExtent is set, it corrects the
+ /// ViewExtent if it is bigger then 1e+9. Otherwise it corrects the ViewExtent if it is bigger than the Maps extent + 10%.
+ ///
+ /// The source of the event.
+ /// An object that contains extent data.
+ /// Corrects the with a minimum extent of 1e-7.
+ protected override void OnViewExtentsChanged(object sender, ExtentArgs args)
+ {
+ if (ViewExtents.Width < minExt || ViewExtents.Height < minExt) // the current height or width is smaller than minExt
+ {
+ var x = ViewExtents.Center.X;
+ var y = ViewExtents.Center.Y;
+ var newExtents = new Extent(x - minExt/2, y - minExt/2, x + minExt/2, y + minExt/2); // resize to stay above the minExt
+ if (ExtentEquals(newExtents, ViewExtents))
+ {
+ return;
+ }
+ ViewExtents = newExtents;
+ return;
+ }
+ base.OnViewExtentsChanged(sender, args);
+ }
+
+ private static bool ExtentEquals(IExtent obj, IExtent other)
+ {
+ if (obj == null || other == null)
+ {
+ return false;
+ }
+ if (Math.Abs(obj.MinX - other.MinX) > minExt)
+ {
+ return false;
+ }
+ if (Math.Abs(obj.MaxX - other.MaxX) > minExt)
+ {
+ return false;
+ }
+ if (Math.Abs(obj.MinY - other.MinY) > minExt)
+ {
+ return false;
+ }
+ if (Math.Abs(obj.MaxY - other.MaxY) > minExt)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs
===================================================================
diff -u -r229b43aff2a2f984ae50b83ce39fa7928d02bdcd -r1d8207d879e9aca8d34bd5b62410c04229c7d0d5
--- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 229b43aff2a2f984ae50b83ce39fa7928d02bdcd)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -165,7 +165,7 @@
private void InitializeMapView()
{
- map = new Map
+ map = new DotSpatialMap
{
ProjectionModeDefine = ActionMode.Never,
Dock = DockStyle.Fill,
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj
===================================================================
diff -u -r40b67559fd19ba271c3366042ffeeace8bc3435d -r1d8207d879e9aca8d34bd5b62410c04229c7d0d5
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 40b67559fd19ba271c3366042ffeeace8bc3435d)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -93,9 +93,11 @@
+
+
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -0,0 +1,55 @@
+// 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.Windows.Forms;
+using DotSpatial.Data;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+
+namespace Core.Components.DotSpatial.Forms.Test
+{
+ [TestFixture]
+ public class DotSpatialMapTest
+ {
+ [Test]
+ [RequiresSTA]
+ public void ToggleRectangleZooming_Always_CorrectlySetsMapFunctions()
+ {
+ using (var form = new Form())
+ {
+ // Setup
+ var mapControl = new MapControl();
+ form.Controls.Add(mapControl);
+ form.Show();
+ var minExt = 1e-8;
+
+ var map = (DotSpatialMap) new ControlTester("Map").TheObject;
+
+ // Call
+ TestDelegate test = () => { map.ViewExtents = new Extent(1 + minExt, 2 + minExt, 1 + minExt, 2 + minExt); };
+
+ // Assert
+ Assert.DoesNotThrow(test);
+ Assert.AreEqual(map.ViewExtents, map.ViewExtents);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs
===================================================================
diff -u -r229b43aff2a2f984ae50b83ce39fa7928d02bdcd -r1d8207d879e9aca8d34bd5b62410c04229c7d0d5
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 229b43aff2a2f984ae50b83ce39fa7928d02bdcd)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 1d8207d879e9aca8d34bd5b62410c04229c7d0d5)
@@ -571,6 +571,7 @@
}
}
+ [Test]
[RequiresSTA]
[TestCase(MouseButtons.Right)]
[TestCase(MouseButtons.Middle)]
@@ -597,6 +598,7 @@
}
}
+ [Test]
[TestCase(true)]
[TestCase(false)]
public void ToggleRectangleZooming_Always_ChangesState(bool isRectangleZooming)
@@ -624,6 +626,7 @@
}
}
+ [Test]
[TestCase(true)]
[TestCase(false)]
public void TogglePanning_Always_ChangesState(bool isPanning)
@@ -651,6 +654,7 @@
}
}
+ [Test]
[TestCase(true)]
[TestCase(false)]
public void ToggleMouseCoordinatesVisibility_Always_ChangesState(bool isShowingCoordinates)