Skip to content

Commit 87d5ae2

Browse files
committed
Adding Pan/Zoom/Rotate lock to LimitedViewport
1 parent ba0e1cc commit 87d5ae2

18 files changed

Lines changed: 52 additions & 100 deletions

File tree

Mapsui.UI.Android/MapControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void MapView_Touch(object sender, TouchEventArgs args)
170170

171171
double rotationDelta = 0;
172172

173-
if (!Lock .RotationLock)
173+
if (!Map.RotationLock)
174174
{
175175
_innerRotation += angle - previousAngle;
176176
_innerRotation %= 360;

Mapsui.UI.Forms/MapControl.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public void RefreshGraphics()
296296
/// <param name="screenPosition">Center of zoom out event</param>
297297
private bool OnZoomOut(Geometries.Point screenPosition)
298298
{
299-
if (Lock.ZoomLock)
299+
if (Map.ZoomLock)
300300
{
301301
return true;
302302
}
@@ -320,7 +320,7 @@ private bool OnZoomOut(Geometries.Point screenPosition)
320320
/// <param name="screenPosition">Center of zoom in event</param>
321321
private bool OnZoomIn(Geometries.Point screenPosition)
322322
{
323-
if (Lock.ZoomLock)
323+
if (Map.ZoomLock)
324324
{
325325
return true;
326326
}
@@ -457,7 +457,7 @@ private bool OnTouchMove(List<Geometries.Point> touchPoints)
457457

458458
var touchPosition = touchPoints.First();
459459

460-
if (!Lock.PanLock && _previousCenter != null && !_previousCenter.IsEmpty())
460+
if (!Map.PanLock && _previousCenter != null && !_previousCenter.IsEmpty())
461461
{
462462
_viewport.Transform(touchPosition, _previousCenter);
463463

@@ -477,7 +477,7 @@ private bool OnTouchMove(List<Geometries.Point> touchPoints)
477477

478478
double rotationDelta = 0;
479479

480-
if (!Lock.RotationLock)
480+
if (!Map.RotationLock)
481481
{
482482
_innerRotation += angle - prevAngle;
483483
_innerRotation %= 360;
@@ -498,7 +498,7 @@ private bool OnTouchMove(List<Geometries.Point> touchPoints)
498498
}
499499
}
500500

501-
_viewport.Transform(center, prevCenter, Lock.ZoomLock ? 1 : radius / prevRadius, rotationDelta);
501+
_viewport.Transform(center, prevCenter, Map.ZoomLock ? 1 : radius / prevRadius, rotationDelta);
502502

503503
(_previousCenter, _previousRadius, _previousAngle) = (center, radius, angle);
504504

Mapsui.UI.Forms/MapView.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public MapView()
6060
_mapDrawableLayer = new Layer(DrawableLayerName) { IsMapInfoLayer = true };
6161

6262
// Get defaults from MapControl
63-
RotationLock = Lock.RotationLock;
64-
ZoomLock = Lock.ZoomLock;
65-
PanLock = Lock.PanLock;
63+
RotationLock = Map.RotationLock;
64+
ZoomLock = Map.ZoomLock;
65+
PanLock = Map.PanLock;
6666

6767
// Add some events to _mapControl
6868
_mapControl.Viewport.ViewportChanged += HandlerViewportChanged;
@@ -289,15 +289,6 @@ public double ReSnapRotationDegrees
289289
set { SetValue(ReSnapRotationDegreesProperty, value); }
290290
}
291291

292-
/// <summary>
293-
/// MapLock property of MapView
294-
/// </summary>
295-
public MapLock Lock
296-
{
297-
get { return _mapControl.Lock; }
298-
set { _mapControl.Lock = value; }
299-
}
300-
301292
/// <summary>
302293
/// Enable rotation with pinch gesture
303294
/// </summary>
@@ -571,13 +562,13 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
571562
_mapControl.ReSnapRotationDegrees = ReSnapRotationDegrees;
572563

573564
if (propertyName.Equals(nameof(RotationLockProperty)) || propertyName.Equals(nameof(RotationLock)))
574-
_mapControl.Lock.RotationLock = RotationLock;
565+
_mapControl.Map.RotationLock = RotationLock;
575566

576567
if (propertyName.Equals(nameof(ZoomLockProperty)) || propertyName.Equals(nameof(ZoomLock)))
577-
_mapControl.Lock.ZoomLock = ZoomLock;
568+
_mapControl.Map.ZoomLock = ZoomLock;
578569

579570
if (propertyName.Equals(nameof(PanLockProperty)) || propertyName.Equals(nameof(PanLock)))
580-
_mapControl.Lock.PanLock = PanLock;
571+
_mapControl.Map.PanLock = PanLock;
581572

582573
if (propertyName.Equals(nameof(IsZoomButtonVisibleProperty)) || propertyName.Equals(nameof(IsZoomButtonVisible)))
583574
{

Mapsui.UI.Shared/MapControl.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ public partial class MapControl : INotifyPropertyChanged
2828
{
2929
private Map _map;
3030

31-
private MapLock _lock = new MapLock { RotationLock = true };
32-
33-
/// <summary>
34-
/// Handles, which interaction with the map is locked
35-
/// </summary>
36-
public MapLock Lock
37-
{
38-
get { return _lock; }
39-
set
40-
{
41-
if (_lock != value)
42-
{
43-
_lock = value;
44-
OnPropertyChanged();
45-
}
46-
}
47-
}
48-
4931
private double _unSnapRotationDegrees;
5032

5133
/// <summary>

Mapsui.UI.Uwp/MapControl.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,14 @@ private static SKXamlCanvas CreateRenderTarget()
119119

120120
private void MapControl_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
121121
{
122-
if (Lock.ZoomLock) return;
122+
if (Map.ZoomLock) return;
123123
if (!Viewport.HasSize) return;
124124

125125
var currentPoint = e.GetCurrentPoint(this);
126126

127127
//Needed for both MouseMove and MouseWheel event for mousewheel event
128128

129-
var mousePosition = Lock.PanLock ?
130-
new Geometries.Point(ActualWidth * 0.5, ActualHeight * 0.5) :
131-
new Geometries.Point(currentPoint.RawPosition.X, currentPoint.RawPosition.Y);
129+
var mousePosition = new Geometries.Point(currentPoint.RawPosition.X, currentPoint.RawPosition.Y);
132130

133131
if (currentPoint.Properties.MouseWheelDelta > 0)
134132
Navigator.ZoomIn(mousePosition);
@@ -188,7 +186,7 @@ private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs
188186

189187
double rotationDelta = 0;
190188

191-
if (!Lock.RotationLock)
189+
if (!Map.RotationLock)
192190
{
193191
_innerRotation += angle - prevAngle;
194192
_innerRotation %= 360;
@@ -209,10 +207,7 @@ private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs
209207
}
210208
}
211209

212-
if (Lock.PanLock)
213-
_viewport.Transform(_viewport.Center, _viewport.Center, radius / prevRadius, rotationDelta);
214-
else
215-
_viewport.Transform(center, previousCenter, radius / prevRadius, rotationDelta);
210+
_viewport.Transform(center, previousCenter, radius / prevRadius, rotationDelta);
216211

217212
RefreshGraphics();
218213

Mapsui.UI.Wpf/MapControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private void InitAnimation()
226226

227227
private void MapControlMouseWheel(object sender, MouseWheelEventArgs e)
228228
{
229-
if (Lock.ZoomLock) return;
229+
if (Map.ZoomLock) return;
230230
if (!Viewport.HasSize) return;
231231

232232
_currentMousePosition = e.GetPosition(this).ToMapsui();
@@ -386,7 +386,7 @@ private void MapControlMouseMove(object sender, MouseEventArgs e)
386386

387387
_currentMousePosition = e.GetPosition(this).ToMapsui(); //Needed for both MouseMove and MouseWheel event
388388

389-
if (_mouseDown && !Lock.PanLock)
389+
if (_mouseDown)
390390
{
391391
if (_previousMousePosition == null || _previousMousePosition.IsEmpty())
392392
{
@@ -482,7 +482,7 @@ private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
482482

483483
double rotationDelta = 0;
484484

485-
if (!Lock.RotationLock)
485+
if (!Map.RotationLock)
486486
{
487487
_innerRotation += angle - prevAngle;
488488
_innerRotation %= 360;
@@ -510,7 +510,7 @@ private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
510510

511511
private double GetDeltaScale(XamlVector scale)
512512
{
513-
if (Lock.ZoomLock) return 1;
513+
if (Map.ZoomLock) return 1;
514514
var deltaScale = (scale.X + scale.Y) / 2;
515515
if (Math.Abs(deltaScale) < Constants.Epsilon)
516516
return 1; // If there is no scaling the deltaScale will be 0.0 in Windows Phone (while it is 1.0 in wpf)

Mapsui.UI.iOS/MapControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public override void TouchesMoved(NSSet touches, UIEvent evt)
132132

133133
double rotationDelta = 0;
134134

135-
if (!Lock.RotationLock)
135+
if (!Map.RotationLock)
136136
{
137137
_innerRotation += angle - previousAngle;
138138
_innerRotation %= 360;

Mapsui.sln.DotSettings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,6 @@
240240
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mapsui/@EntryIndexedValue">True</s:Boolean>
241241
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shapefile/@EntryIndexedValue">True</s:Boolean>
242242
<s:Boolean x:Key="/Default/UserDictionary/Words/=Skia/@EntryIndexedValue">True</s:Boolean>
243-
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlite/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
243+
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlite/@EntryIndexedValue">True</s:Boolean>
244+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unrotated/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
244245

Mapsui/LimitedViewport.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public LimitedViewport()
2828

2929
public void Transform(Point position, Point previousPosition, double deltaResolution = 1, double deltaRotation = 0)
3030
{
31+
if (Map.ZoomLock) deltaResolution = 1;
32+
if (Map.PanLock) position = previousPosition;
3133
_viewport.Transform(position, previousPosition, deltaResolution, deltaRotation);
3234
Limiter.Limit(_viewport, Map.Resolutions, Map.Envelope);
3335
}
@@ -40,24 +42,28 @@ public void SetSize(double width, double height)
4042

4143
public virtual void SetCenter(double x, double y)
4244
{
45+
if (Map.PanLock) return;
4346
_viewport.SetCenter(x, y);
4447
Limiter.LimitExtent(_viewport, Map.Envelope);
4548
}
4649

4750
public void SetCenter(ReadOnlyPoint center)
4851
{
52+
if (Map.PanLock) return;
4953
_viewport.SetCenter(center);
5054
Limiter.LimitExtent(_viewport, Map.Envelope);
5155
}
5256

5357
public void SetResolution(double resolution)
5458
{
59+
if (Map.ZoomLock) return;
5560
resolution = Limiter.LimitResolution(resolution, _viewport.Width, _viewport.Height, Map.Resolutions, Map.Envelope);
5661
_viewport.SetResolution(resolution);
5762
}
5863

5964
public void SetRotation(double rotation)
6065
{
66+
if (Map.RotationLock) return;
6167
_viewport.SetRotation(rotation);
6268
Limiter.LimitExtent(_viewport, Map.Envelope);
6369
}

Mapsui/Map.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public Map()
4949
Layers = new LayerCollection();
5050
}
5151

52+
/// <summary>
53+
/// When true the user can not pan (move) the map.
54+
/// </summary>
55+
public bool PanLock { get; set; }
56+
57+
/// <summary>
58+
/// When true the user an not rotate the map
59+
/// </summary>
60+
public bool ZoomLock { get; set; }
61+
62+
/// <summary>
63+
/// When true the user can not zoom into the map
64+
/// </summary>
65+
public bool RotationLock { get; set; }
66+
5267
/// <summary>
5368
/// List of Widgets belonging to map
5469
/// </summary>

0 commit comments

Comments
 (0)