Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Map circles #7401

Merged
merged 6 commits into from Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,6 +13,7 @@
<Picker.Items>
<x:String>Polyline</x:String>
<x:String>Polygon</x:String>
<x:String>Circle</x:String>
</Picker.Items>
</Picker>
<Button Clicked="AddClicked"
Expand Down
43 changes: 42 additions & 1 deletion Xamarin.Forms.Controls/GalleryPages/MapElementsGallery.xaml.cs
Expand Up @@ -16,13 +16,15 @@ public partial class MapElementsGallery : ContentPage
enum SelectedElementType
{
Polyline,
Polygon
Polygon,
Circle
}

SelectedElementType _selectedType;

Polyline _polyline;
Polygon _polygon;
Circle _circle;

Random _random = new Random();

Expand Down Expand Up @@ -58,8 +60,17 @@ public MapElementsGallery()
}
};

_circle = new Circle
{
Center = new Position(42.352364, -71.067177),
Radius = Distance.FromMiles(100.0),
StrokeColor = Color.FromRgb(31, 174, 206),
FillColor = Color.FromRgba(31, 174, 206, 127)
};

Map.MapElements.Add(_polyline);
Map.MapElements.Add(_polygon);
Map.MapElements.Add(_circle);

ElementPicker.SelectedIndex = 0;
}
Expand All @@ -74,6 +85,16 @@ void MapClicked(object sender, MapClickedEventArgs e)
case SelectedElementType.Polygon:
_polygon.Geopath.Add(e.Position);
break;
case SelectedElementType.Circle:
if (_circle.Center == default(Position))
{
_circle.Center = e.Position;
}
else
{
_circle.Radius = Distance.BetweenPositions(_circle.Center, e.Position);
}
break;
}
}

Expand All @@ -92,6 +113,9 @@ void AddClicked(object sender, EventArgs e)
case SelectedElementType.Polygon:
Map.MapElements.Add(_polygon = new Polygon());
break;
case SelectedElementType.Circle:
Map.MapElements.Add(_circle = new Circle());
break;
}
}

Expand All @@ -114,6 +138,14 @@ void RemoveClicked(object sender, EventArgs e)
if (_polygon == null)
Map.MapElements.Add(_polygon = new Polygon());

break;
case SelectedElementType.Circle:
Map.MapElements.Remove(_circle);
_circle = Map.MapElements.OfType<Circle>().LastOrDefault();

if (_circle == null)
Map.MapElements.Add(_circle = new Circle());

break;
}
}
Expand All @@ -129,6 +161,9 @@ void ChangeColorClicked(object sender, EventArgs e)
case SelectedElementType.Polygon:
_polygon.StrokeColor = newColor;
break;
case SelectedElementType.Circle:
_circle.StrokeColor = newColor;
break;
}
}

Expand All @@ -143,6 +178,9 @@ void ChangeWidthClicked(object sender, EventArgs e)
case SelectedElementType.Polygon:
_polygon.StrokeWidth = newWidth;
break;
case SelectedElementType.Circle:
_circle.StrokeWidth = newWidth;
break;
}
}

Expand All @@ -154,6 +192,9 @@ void ChangeFillClicked(object sender, EventArgs e)
case SelectedElementType.Polygon:
_polygon.FillColor = newColor;
break;
case SelectedElementType.Circle:
_circle.FillColor = newColor;
break;
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions Xamarin.Forms.Core.UnitTests/DistanceTests.cs
Expand Up @@ -58,6 +58,21 @@ public void ConstructFromMiles()
Assert.True(Math.Abs(distance.Kilometers - 6378.09999805) < EPSILON_FOR_LARGE_MILES_TO_KM);
}

[Test]
public void ConstructFromPositions()
{
const double EPSILON = 0.001;

Position position1 = new Position(37.403992, -122.034988);
Position position2 = new Position(37.776691, -122.416534);

Distance distance = Distance.BetweenPositions(position1, position2);

Assert.True(Math.Abs(distance.Meters - 53363.08) < EPSILON);
Assert.True(Math.Abs(distance.Kilometers - 53.36308) < EPSILON);
Assert.True(Math.Abs(distance.Miles - 33.15828) < EPSILON);
}

[Test]
public void EqualityOp([Range(5, 9)] double x, [Range(5, 9)] double y)
{
Expand Down