Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Controls/Maps/src/MapElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public partial class MapElement : Element
typeof(MapElement),
5f);

/// <summary>Bindable property for <see cref="IsVisible"/>.</summary>
public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(
nameof(IsVisible),
typeof(bool),
typeof(MapElement),
true);

/// <summary>Bindable property for <see cref="ZIndex"/>.</summary>
public static readonly BindableProperty ZIndexProperty = BindableProperty.Create(
nameof(ZIndex),
typeof(int),
typeof(MapElement),
0);

/// <summary>
/// Gets or sets the stroke color. This is a bindable property.
/// </summary>
Expand All @@ -45,6 +59,28 @@ public float StrokeWidth
set => SetValue(StrokeWidthProperty, value);
}

/// <summary>
/// Gets or sets a value indicating whether the map element is visible on the map.
/// The default value is <see langword="true"/>.
/// This is a bindable property.
/// </summary>
public bool IsVisible
{
get => (bool)GetValue(IsVisibleProperty);
set => SetValue(IsVisibleProperty, value);
}

/// <summary>
/// Gets or sets the z-index of the map element, which controls its draw order relative to other elements.
/// Higher values are drawn on top of lower values. The default value is <c>0</c>.
/// This is a bindable property.
/// </summary>
public int ZIndex
{
get => (int)GetValue(ZIndexProperty);
set => SetValue(ZIndexProperty, value);
}

/// <summary>
/// Gets or sets the platform counterpart of this map element.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
9 changes: 9 additions & 0 deletions src/Controls/Maps/src/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#nullable enable

Microsoft.Maui.Controls.Maps.MapElement.IsVisible.get -> bool
Microsoft.Maui.Controls.Maps.MapElement.IsVisible.set -> void
Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.get -> int
Microsoft.Maui.Controls.Maps.MapElement.ZIndex.set -> void
Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.IsVisibleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Maps.MapElement.ZIndexProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using Microsoft.Maui.Controls.Maps;
using Microsoft.Maui.Devices.Sensors;
using Microsoft.Maui.Maps;

namespace Maui.Controls.Sample.Pages.MapsGalleries
{
public class MapElementVisibilityGallery : ContentPage

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L7

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(7,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?)
{
readonly Polygon _polygon;
readonly Polyline _polyline;
readonly Circle _circle;
readonly Label _statusLabel;

Check failure on line 12 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L12

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(12,12): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'Label' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L12

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(12,12): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'Label' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L12

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(12,12): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'Label' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L12

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(12,12): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'Label' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs

View check run for this annotation

Azure Pipelines / maui-pr

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs#L12

src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementVisibilityGallery.cs(12,12): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'Label' could not be found (are you missing a using directive or an assembly reference?)

public MapElementVisibilityGallery()
{
Title = "Element Visibility & ZIndex";

var center = new Location(47.6062, -122.3321); // Seattle

_polygon = new Polygon
{
StrokeColor = Colors.Blue,
StrokeWidth = 3,
FillColor = Color.FromRgba(0, 0, 255, 64),
ZIndex = 1,
};
_polygon.Geopath.Add(new Location(47.615, -122.345));
_polygon.Geopath.Add(new Location(47.615, -122.320));
_polygon.Geopath.Add(new Location(47.600, -122.320));
_polygon.Geopath.Add(new Location(47.600, -122.345));

_polyline = new Polyline
{
StrokeColor = Colors.Red,
StrokeWidth = 5,
ZIndex = 2,
};
_polyline.Geopath.Add(new Location(47.610, -122.350));
_polyline.Geopath.Add(new Location(47.610, -122.315));

_circle = new Circle
{
Center = center,
Radius = new Distance(500),
StrokeColor = Colors.Green,
StrokeWidth = 3,
FillColor = Color.FromRgba(0, 255, 0, 64),
ZIndex = 3,
};

var map = new Microsoft.Maui.Controls.Maps.Map(new MapSpan(center, 0.03, 0.03));
map.MapElements.Add(_polygon);
map.MapElements.Add(_polyline);
map.MapElements.Add(_circle);

_statusLabel = new Label
{
Text = "All elements visible. ZIndex: Polygon=1, Polyline=2, Circle=3",
HorizontalTextAlignment = TextAlignment.Center,
AutomationId = "StatusLabel"
};

var togglePolygonBtn = new Button { Text = "Toggle Polygon", AutomationId = "TogglePolygon" };
togglePolygonBtn.Clicked += (s, e) =>
{
_polygon.IsVisible = !_polygon.IsVisible;
UpdateStatus();
};

var togglePolylineBtn = new Button { Text = "Toggle Polyline", AutomationId = "TogglePolyline" };
togglePolylineBtn.Clicked += (s, e) =>
{
_polyline.IsVisible = !_polyline.IsVisible;
UpdateStatus();
};

var toggleCircleBtn = new Button { Text = "Toggle Circle", AutomationId = "ToggleCircle" };
toggleCircleBtn.Clicked += (s, e) =>
{
_circle.IsVisible = !_circle.IsVisible;
UpdateStatus();
};

var bringPolygonTopBtn = new Button { Text = "Polygon to Top (Z=10)", AutomationId = "PolygonTop" };
bringPolygonTopBtn.Clicked += (s, e) =>
{
_polygon.ZIndex = 10;
UpdateStatus();
};

var resetZIndexBtn = new Button { Text = "Reset ZIndex", AutomationId = "ResetZIndex" };
resetZIndexBtn.Clicked += (s, e) =>
{
_polygon.ZIndex = 1;
_polyline.ZIndex = 2;
_circle.ZIndex = 3;
UpdateStatus();
};

Content = new Grid
{
RowDefinitions =
{
new RowDefinition(GridLength.Star),
new RowDefinition(GridLength.Auto),
},
Children =
{
map,
new VerticalStackLayout
{
Spacing = 4,
Padding = new Thickness(8),
Children =
{
_statusLabel,
new HorizontalStackLayout
{
Spacing = 4,
HorizontalOptions = LayoutOptions.Center,
Children = { togglePolygonBtn, togglePolylineBtn, toggleCircleBtn }
},
new HorizontalStackLayout
{
Spacing = 4,
HorizontalOptions = LayoutOptions.Center,
Children = { bringPolygonTopBtn, resetZIndexBtn }
}
}
}.Assign(out var controls)
}
};

Grid.SetRow(controls, 1);
}

void UpdateStatus()
{
_statusLabel.Text = $"Polygon:{(_polygon.IsVisible ? "ON" : "OFF")}(Z={_polygon.ZIndex}) " +
$"Polyline:{(_polyline.IsVisible ? "ON" : "OFF")}(Z={_polyline.ZIndex}) " +
$"Circle:{(_circle.IsVisible ? "ON" : "OFF")}(Z={_circle.ZIndex})";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public MapsGallery()
GalleryBuilder.NavButton("Pins ItemsSource", () => new PinItemsSourceGallery(), Navigation),
GalleryBuilder.NavButton("Circle", () => new CircleGallery(), Navigation),
GalleryBuilder.NavButton("Polygon", () => new PolygonsGallery(), Navigation),
GalleryBuilder.NavButton("Element Visibility & ZIndex", () => new MapElementVisibilityGallery(), Navigation),
}
}
};
Expand Down
51 changes: 51 additions & 0 deletions src/Controls/tests/Core.UnitTests/MapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,57 @@ public void WorksWithNullItems()
Assert.True(IsMapWithItemsSource(itemsSource, map));
}

[Fact]
public void MapElementIsVisibleDefaultIsTrue()
{
var polygon = new Polygon();
Assert.True(polygon.IsVisible);
}

[Fact]
public void MapElementIsVisibleCanBeSet()
{
var polygon = new Polygon();
polygon.IsVisible = false;
Assert.False(polygon.IsVisible);
}

[Fact]
public void MapElementZIndexDefaultIsZero()
{
var polyline = new Polyline();
Assert.Equal(0, polyline.ZIndex);
}

[Fact]
public void MapElementZIndexCanBeSet()
{
var circle = new Circle
{
Center = new Location(0, 0),
Radius = new Distance(100)
};
circle.ZIndex = 5;
Assert.Equal(5, circle.ZIndex);
}

[Fact]
public void MapElementIsVisibleWorksOnAllTypes()
{
var polygon = new Polygon { IsVisible = false };
var polyline = new Polyline { IsVisible = false };
var circle = new Circle
{
Center = new Location(0, 0),
Radius = new Distance(100),
IsVisible = false
};

Assert.False(polygon.IsVisible);
Assert.False(polyline.IsVisible);
Assert.False(circle.IsVisible);
}

// Checks if for every item in the items source there's a corresponding pin
static bool IsMapWithItemsSource(IEnumerable itemsSource, Map map)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Core/maps/src/Core/IMapElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@ public interface IMapElement : IElement, IStroke
/// Gets or sets the platform counterpart of this map element.
/// </summary>
object? MapElementId { get; set; }

/// <summary>
/// Gets a value indicating whether the map element is visible on the map.
/// </summary>
bool IsVisible { get; }

/// <summary>
/// Gets the z-index of the map element, which controls its draw order relative to other elements.
/// Higher values are drawn on top of lower values.
/// </summary>
int ZIndex { get; }
}
}
Loading
Loading