Skip to content

Commit a3ff0c5

Browse files
committed
Moving MapControl.GetPinchValues from shared to iOS and Android
1 parent 0a4e825 commit a3ff0c5

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

Mapsui.UI.Android/MapControl.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
using Android.OS;
77
using Android.Util;
88
using Android.Views;
9+
using Mapsui.Geometries.Utilities;
910
using Mapsui.Logging;
1011
using Mapsui.Widgets;
1112
using SkiaSharp.Views.Android;
1213
using Math = System.Math;
14+
using Point = Mapsui.Geometries.Point;
1315

1416
namespace Mapsui.UI.Android
1517
{
@@ -327,5 +329,29 @@ protected override void Dispose(bool disposing)
327329
Unsubscribe();
328330
base.Dispose(disposing);
329331
}
332+
333+
private static (Point centre, double radius, double angle) GetPinchValues(List<Point> locations)
334+
{
335+
if (locations.Count < 2)
336+
throw new ArgumentException();
337+
338+
double centerX = 0;
339+
double centerY = 0;
340+
341+
foreach (var location in locations)
342+
{
343+
centerX += location.X;
344+
centerY += location.Y;
345+
}
346+
347+
centerX = centerX / locations.Count;
348+
centerY = centerY / locations.Count;
349+
350+
var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);
351+
352+
var angle = Math.Atan2(locations[1].Y - locations[0].Y, locations[1].X - locations[0].X) * 180.0 / Math.PI;
353+
354+
return (new Point(centerX, centerY), radius, angle);
355+
}
330356
}
331357
}

Mapsui.UI.Shared/MapControl.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Mapsui.Geometries;
2-
using Mapsui.Geometries.Utilities;
32
using System;
4-
using System.Collections.Generic;
53
using System.ComponentModel;
64
using System.Net;
75
using Mapsui.Fetcher;
@@ -61,30 +59,6 @@ public void Unsubscribe()
6159
UnsubscribeFromMapEvents(_map);
6260
}
6361

64-
private static (Point centre, double radius, double angle) GetPinchValues(List<Point> locations)
65-
{
66-
if (locations.Count < 2)
67-
throw new ArgumentException();
68-
69-
double centerX = 0;
70-
double centerY = 0;
71-
72-
foreach (var location in locations)
73-
{
74-
centerX += location.X;
75-
centerY += location.Y;
76-
}
77-
78-
centerX = centerX / locations.Count;
79-
centerY = centerY / locations.Count;
80-
81-
var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);
82-
83-
var angle = Math.Atan2(locations[1].Y - locations[0].Y, locations[1].X - locations[0].X) * 180.0 / Math.PI;
84-
85-
return (new Point(centerX, centerY), radius, angle);
86-
}
87-
8862
/// <summary>
8963
/// Subscribe to map events
9064
/// </summary>

Mapsui.UI.iOS/MapControl.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
using Foundation;
33
using UIKit;
44
using System;
5+
using System.Collections.Generic;
56
using System.ComponentModel;
67
using System.Linq;
78
using CoreGraphics;
89
using Mapsui.Geometries;
10+
using Mapsui.Geometries.Utilities;
911
using Mapsui.Widgets;
1012
using SkiaSharp.Views.iOS;
1113

@@ -258,5 +260,29 @@ protected override void Dispose(bool disposing)
258260
Unsubscribe();
259261
base.Dispose(disposing);
260262
}
263+
264+
private static (Point centre, double radius, double angle) GetPinchValues(List<Point> locations)
265+
{
266+
if (locations.Count < 2)
267+
throw new ArgumentException();
268+
269+
double centerX = 0;
270+
double centerY = 0;
271+
272+
foreach (var location in locations)
273+
{
274+
centerX += location.X;
275+
centerY += location.Y;
276+
}
277+
278+
centerX = centerX / locations.Count;
279+
centerY = centerY / locations.Count;
280+
281+
var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);
282+
283+
var angle = Math.Atan2(locations[1].Y - locations[0].Y, locations[1].X - locations[0].X) * 180.0 / Math.PI;
284+
285+
return (new Point(centerX, centerY), radius, angle);
286+
}
261287
}
262288
}

0 commit comments

Comments
 (0)