Index: Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs
===================================================================
diff -u -r61de56d96afe43d6ba193795c084a07fdff78b34 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs (.../BaseMap.cs) (revision 61de56d96afe43d6ba193795c084a07fdff78b34)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs (.../BaseMap.cs) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -34,6 +34,7 @@
public sealed class BaseMap : Control, IMap, IObserver
{
private readonly MapDataFactory mapDataFactory = new MapDataFactory();
+
private MapData data;
private Map map;
@@ -43,8 +44,13 @@
public BaseMap()
{
InitializeMapView();
+ TogglePanning();
}
+ public bool IsPanningEnabled { get; private set; }
+
+ public bool IsRectangleZoomingEnabled { get; private set; }
+
public MapData Data
{
get
@@ -70,11 +76,39 @@
map.ZoomToMaxExtent();
}
+ public void TogglePanning()
+ {
+ if (!IsPanningEnabled)
+ {
+ ResetDefaultInteraction();
+ map.FunctionMode = FunctionMode.Pan;
+ IsPanningEnabled = true;
+ }
+ }
+
+ public void ToggleRectangleZooming()
+ {
+ if (!IsRectangleZoomingEnabled)
+ {
+ ResetDefaultInteraction();
+ map.FunctionMode = FunctionMode.None;
+ IsRectangleZoomingEnabled = true;
+
+ map.ActivateMapFunction(new MapFunctionSelectionZoom(map));
+ }
+ }
+
public void UpdateObserver()
{
DrawFeatureSets();
}
+ private void ResetDefaultInteraction()
+ {
+ IsPanningEnabled = false;
+ IsRectangleZoomingEnabled = false;
+ }
+
///
/// Attaches the to the currently set , if there is any.
///
@@ -115,7 +149,7 @@
{
ProjectionModeDefine = ActionMode.Never,
Dock = DockStyle.Fill,
- FunctionMode = FunctionMode.Pan,
+ FunctionMode = FunctionMode.Pan
};
Controls.Add(map);
Index: Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj
===================================================================
diff -u -r516fe1be74af2aff6dc6f239cea704f899c88cb9 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 516fe1be74af2aff6dc6f239cea704f899c88cb9)
+++ Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -82,6 +82,8 @@
+
+
@@ -95,6 +97,7 @@
+
Index: Core/Components/src/Core.Components.DotSpatial/MapFunctionSelectionZoom.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/MapFunctionSelectionZoom.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/MapFunctionSelectionZoom.cs (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -0,0 +1,135 @@
+using System;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Windows.Forms;
+using DotSpatial.Controls;
+using DotSpatial.Data;
+using DotSpatial.Symbology;
+using DotSpatial.Topology;
+using Point = System.Drawing.Point;
+
+namespace Core.Components.DotSpatial
+{
+ ///
+ /// that can zoom into the map using left mouse clicks or rectangle dragging. It zooms out on right mouse clicks.
+ ///
+ /// This is a copy of with the following changes:
+ ///
+ /// It does not zoom out on right mouse clicks.
+ /// It does not zoom when the location of the cursus on is equal to the location set at
+ /// .
+ public class MapFunctionSelectionZoom : MapFunction
+ {
+ private readonly Pen selectionPen;
+ private Point currentPoint;
+ private Coordinate geoStartPoint;
+ private bool isDragging;
+ private Point startPoint = Point.Empty;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ public MapFunctionSelectionZoom(IMap inMap) : base(inMap)
+ {
+ selectionPen = new Pen(Color.Black)
+ {
+ DashStyle = DashStyle.Dash
+ };
+ YieldStyle = YieldStyles.LeftButton | YieldStyles.RightButton;
+ }
+
+ protected override void OnDraw(MapDrawArgs e)
+ {
+ if (isDragging)
+ {
+ var rectangle = Opp.RectangleFromPoints(startPoint, currentPoint);
+ rectangle.Width -= 1;
+ rectangle.Height -= 1;
+ e.Graphics.DrawRectangle(Pens.White, rectangle);
+ e.Graphics.DrawRectangle(selectionPen, rectangle);
+ }
+ base.OnDraw(e);
+ }
+
+ protected override void OnMouseDown(GeoMouseArgs e)
+ {
+ if (e.Button == MouseButtons.Left)
+ {
+ startPoint = e.Location;
+ currentPoint = startPoint;
+ geoStartPoint = e.GeographicLocation;
+ isDragging = true;
+ Map.IsBusy = true;
+ }
+ base.OnMouseDown(e);
+ }
+
+ protected override void OnMouseMove(GeoMouseArgs e)
+ {
+ if (isDragging)
+ {
+ int x = Math.Min(Math.Min(startPoint.X, currentPoint.X), e.X);
+ int y = Math.Min(Math.Min(startPoint.Y, currentPoint.Y), e.Y);
+ int mx = Math.Max(Math.Max(startPoint.X, currentPoint.X), e.X);
+ int my = Math.Max(Math.Max(startPoint.Y, currentPoint.Y), e.Y);
+ currentPoint = e.Location;
+ Map.Invalidate(new Rectangle(x, y, mx - x, my - y));
+ }
+ base.OnMouseMove(e);
+ }
+
+ protected override void OnMouseUp(GeoMouseArgs e)
+ {
+ if (!(e.Map.IsZoomedToMaxExtent && e.Button == MouseButtons.Right))
+ {
+ e.Map.IsZoomedToMaxExtent = false;
+ var handled = false;
+ currentPoint = e.Location;
+
+ Map.Invalidate();
+ if (isDragging)
+ {
+ if (startPoint == currentPoint)
+ {
+ handled = true;
+ }
+ else if (geoStartPoint != null)
+ {
+ IEnvelope env = new Envelope(geoStartPoint.X, e.GeographicLocation.X,
+ geoStartPoint.Y, e.GeographicLocation.Y);
+ if (Math.Abs(e.X - startPoint.X) > 1 && Math.Abs(e.Y - startPoint.Y) > 1)
+ {
+ e.Map.ViewExtents = env.ToExtent();
+ handled = true;
+ }
+ }
+ }
+ isDragging = false;
+
+ if (handled == false)
+ {
+ Rectangle r = e.Map.MapFrame.View;
+ var w = r.Width;
+ var h = r.Height;
+ if (e.Button == MouseButtons.Left)
+ {
+ r.Inflate(-r.Width/4, -r.Height/4);
+ // The mouse cursor should anchor the geographic location during zoom.
+ r.X += (e.X/2) - w/4;
+ r.Y += (e.Y/2) - h/4;
+ e.Map.MapFrame.View = r;
+ }
+ else if (e.Button == MouseButtons.Right)
+ {
+ startPoint = Point.Empty;
+ }
+
+ e.Map.MapFrame.ResetExtents();
+ }
+ }
+
+ base.OnMouseUp(e);
+ Map.IsBusy = false;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.Gis/IMap.cs
===================================================================
diff -u -r3aa114b55dd6caa46890a54af64fba874497c135 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/src/Core.Components.Gis/IMap.cs (.../IMap.cs) (revision 3aa114b55dd6caa46890a54af64fba874497c135)
+++ Core/Components/src/Core.Components.Gis/IMap.cs (.../IMap.cs) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -29,6 +29,16 @@
public interface IMap
{
///
+ /// Gets a value indicating whether or not the chart can be panned with the left mouse button.
+ ///
+ bool IsPanningEnabled { get; }
+
+ ///
+ /// Gets a value indicating whether or not the chart can be zoomed by rectangle with the left mouse button.
+ ///
+ bool IsRectangleZoomingEnabled { get; }
+
+ ///
/// Gets or sets the data to show in the .
///
MapData Data { get; set; }
@@ -37,5 +47,15 @@
/// Zooms to a level so that everything is in view.
///
void ZoomToAll();
+
+ ///
+ /// Toggles panning of the . Panning is invoked by clicking the left mouse-button.
+ ///
+ void TogglePanning();
+
+ ///
+ /// Toggles rectangle zooming of the . Rectangle zooming is invoked by clicking the left mouse-button.
+ ///
+ void ToggleRectangleZooming();
}
}
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs
===================================================================
diff -u -r61de56d96afe43d6ba193795c084a07fdff78b34 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision 61de56d96afe43d6ba193795c084a07fdff78b34)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -1,4 +1,25 @@
-using System;
+// 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;
using System.Linq;
using System.Windows.Forms;
@@ -170,6 +191,21 @@
}
[Test]
+ public void ToggleRectangleZooming_PanningIsEnabled_RectangleZoomingIsEnabled()
+ {
+ // Setup
+ var map = new BaseMap();
+ Assert.IsFalse(map.IsRectangleZoomingEnabled, "Precondition failed: IsRectangleZoomingEnabled is true");
+
+ // Call
+ map.ToggleRectangleZooming();
+
+ // Assert
+ Assert.IsTrue(map.IsRectangleZoomingEnabled);
+ Assert.IsFalse(map.IsPanningEnabled);
+ }
+
+ [Test]
[RequiresSTA]
public void UpdateObserver_MapInForm_MapLayersRenewed()
{
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj
===================================================================
diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -94,6 +94,9 @@
+
+ Copying.Lesser.licenseheader
+
Index: Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj
===================================================================
diff -u -r3363b60ad5713cbbbf57ff2a26a4c51a897379e2 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision 3363b60ad5713cbbbf57ff2a26a4c51a897379e2)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -91,8 +91,13 @@
..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dllTrue
+
+ ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+ True
+
+
@@ -101,6 +106,7 @@
+
@@ -126,6 +132,9 @@
+
+ Copying.Lesser.licenseheader
+ Designer
Index: Core/Components/test/Core.Components.DotSpatial.Test/MapFunctionSelectionZoomTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Test/MapFunctionSelectionZoomTest.cs (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Test/MapFunctionSelectionZoomTest.cs (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -0,0 +1,45 @@
+// 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 DotSpatial.Controls;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Core.Components.DotSpatial.Test
+{
+ [TestFixture]
+ public class MapFunctionSelectionZoomTest
+ {
+ [Test]
+ public void Constructor_Always_ExpectedValues()
+ {
+ // Setup
+ var mockingRepository = new MockRepository();
+ var mapMock = mockingRepository.StrictMock();
+
+ // Call
+ MapFunctionSelectionZoom mapFunction = new MapFunctionSelectionZoom(mapMock);
+
+ // Assert
+ Assert.IsInstanceOf(mapFunction);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Test/packages.config
===================================================================
diff -u -r287b1b719a43b0de337f8149dfa3a2a3220a375a -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Components/test/Core.Components.DotSpatial.Test/packages.config (.../packages.config) (revision 287b1b719a43b0de337f8149dfa3a2a3220a375a)
+++ Core/Components/test/Core.Components.DotSpatial.Test/packages.config (.../packages.config) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -13,4 +13,5 @@
+
\ No newline at end of file
Index: Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml
===================================================================
diff -u -r3aa114b55dd6caa46890a54af64fba874497c135 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml (.../MapRibbon.xaml) (revision 3aa114b55dd6caa46890a54af64fba874497c135)
+++ Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml (.../MapRibbon.xaml) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -26,6 +26,8 @@
+
+
Index: Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml.cs
===================================================================
diff -u -r3aa114b55dd6caa46890a54af64fba874497c135 -rdb3aa610228b657d23bba55a4ff26a1e359e9847
--- Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml.cs (.../MapRibbon.xaml.cs) (revision 3aa114b55dd6caa46890a54af64fba874497c135)
+++ Core/Plugins/src/Core.Plugins.DotSpatial/MapRibbon.xaml.cs (.../MapRibbon.xaml.cs) (revision db3aa610228b657d23bba55a4ff26a1e359e9847)
@@ -91,6 +91,8 @@
public void ValidateItems()
{
ToggleLegendViewButton.IsChecked = ToggleLegendViewCommand != null && ToggleLegendViewCommand.Checked;
+ TogglePanningButton.IsChecked = Map != null && Map.IsPanningEnabled;
+ ToggleRectangleZoomingButton.IsChecked = Map != null && Map.IsRectangleZoomingEnabled;
}
public bool IsContextualTabVisible(string tabGroupName, string tabName)
@@ -121,5 +123,17 @@
{
Map.ZoomToAll();
}
+
+ private void ButtonTogglePanning_Click(object sender, RoutedEventArgs e)
+ {
+ Map.TogglePanning();
+ ValidateItems();
+ }
+
+ private void ButtonToggleRectangleZooming_Click(object sender, RoutedEventArgs e)
+ {
+ Map.ToggleRectangleZooming();
+ ValidateItems();
+ }
}
}
\ No newline at end of file