Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Microsoft.Toolkit.Forms.UI.Controls/MapControl/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,27 @@ public MapLoadingStatus LoadingStatus
get => (MapLoadingStatus)UwpControl.LoadingStatus;
}

private System.Collections.Generic.IList<MapElement> _mapElements;

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapElements"/>
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public System.Collections.Generic.IList<MapElement> MapElements
{
get => UwpControl.MapElements.Cast<MapElement>().ToList();
get
{
if (_mapElements == null)
{
_mapElements = new WindowsRuntimeCollection<MapElement, windows.UI.Xaml.Controls.Maps.MapElement>(
this.UwpControl.MapElements,
mp => MapElement.FromMapElement(mp),
mp => mp.UwpInstance);
}

return _mapElements;
}
}

/// <summary>
Expand Down Expand Up @@ -659,11 +672,10 @@ public MapProjection MapProjection
/// <summary>
/// Gets or sets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.Layers"/>
/// </summary>
[DefaultValue(null)]
public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer> Layers
{
get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer>)this.GetUwpControlValue();
set => this.SetUwpControlValue(value);
get => this.UwpControl.Layers;
set => this.UwpControl.Layers = value;
}

/// <summary>
Expand Down
34 changes: 28 additions & 6 deletions Microsoft.Toolkit.Sample.Wpf.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,34 @@ private void inkToolbar_ActiveToolChanged(object sender, object e)

private async void myMap_Loaded(object sender, RoutedEventArgs e)
{
// Specify a known location.
BasicGeoposition cityPosition = new BasicGeoposition() { Latitude = 47.604, Longitude = -122.329 };
var cityCenter = new Geopoint(cityPosition);

// Set the map location.
await myMap.TrySetViewAsync(cityCenter, 12).ConfigureAwait(false);
if (myMap.Layers.Count == 0)
{
// Specify a known location.
var cityPosition = new windows.Devices.Geolocation.BasicGeoposition()
{
Latitude = 47.604,
Longitude = -122.329
};
var cityCenter = new windows.Devices.Geolocation.Geopoint(cityPosition);
var icon = new windows.UI.Xaml.Controls.Maps.MapIcon()
{
Location = cityCenter,
};

var elements = new System.Collections.Generic.List<windows.UI.Xaml.Controls.Maps.MapElement>()
{
icon,
};
var layer = new windows.UI.Xaml.Controls.Maps.MapElementsLayer()
{
ZIndex = 1,
MapElements = elements,
};
myMap.Layers.Add(layer);

// Set the map location.
await myMap.TrySetViewAsync(cityCenter, 12).ConfigureAwait(false);
}
}

private void WindowsXamlHost_Loaded(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT
/// </summary>
public class MapElement
{
private windows.UI.Xaml.Controls.Maps.MapElement UwpInstance { get; }
internal windows.UI.Xaml.Controls.Maps.MapElement UwpInstance { get; }

/// <summary>
/// Initializes a new instance of the <see cref="MapElement"/> class, a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT
{
internal sealed class WindowsRuntimeCollection<T1, T2> : IList<T1>
{
private readonly IList<T2> collection;
private readonly Func<T2, T1> converter1;
private readonly Func<T1, T2> converter2;

public WindowsRuntimeCollection(IList<T2> collection, Func<T2, T1> converter1, Func<T1, T2> converter2)
{
this.collection = collection;
this.converter1 = converter1;
this.converter2 = converter2;
}

T1 IList<T1>.this[int index]
Comment thread
ocalvo marked this conversation as resolved.
{
get => this.converter1(this.collection[index]);
set => this.collection[index] = this.converter2(value);
}

int ICollection<T1>.Count => this.collection.Count;
Comment thread
ocalvo marked this conversation as resolved.

bool ICollection<T1>.IsReadOnly => this.collection.IsReadOnly;

void ICollection<T1>.Add(T1 item)
{
this.collection.Add(this.converter2(item));
}

void ICollection<T1>.Clear()
{
this.collection.Clear();
}

bool ICollection<T1>.Contains(T1 item)
{
return this.collection.Contains(this.converter2(item));
}

void ICollection<T1>.CopyTo(T1[] array, int arrayIndex)
{
this.collection.CopyTo(array.Select(e => this.converter2(e)).ToArray(), arrayIndex);
}

IEnumerator<T1> IEnumerable<T1>.GetEnumerator()
{
foreach (var e in this.collection)
{
yield return this.converter1(e);
}
}

IEnumerator IEnumerable.GetEnumerator()
{
foreach (var e in this.collection)
{
yield return this.converter1(e);
}
}

int IList<T1>.IndexOf(T1 item)
{
return this.collection.IndexOf(this.converter2(item));
}

void IList<T1>.Insert(int index, T1 item)
{
this.collection.Insert(index, this.converter2(item));
}

bool ICollection<T1>.Remove(T1 item)
{
return this.collection.Remove(this.converter2(item));
}

void IList<T1>.RemoveAt(int index)
{
this.collection.RemoveAt(index);
}
}
}
47 changes: 18 additions & 29 deletions Microsoft.Toolkit.Wpf.UI.Controls/MapControl/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ protected override void OnInitialized(EventArgs e)
Bind(nameof(ZoomLevel), ZoomLevelProperty, windows.UI.Xaml.Controls.Maps.MapControl.ZoomLevelProperty);
Bind(nameof(Center), CenterProperty, windows.UI.Xaml.Controls.Maps.MapControl.CenterProperty, new WindowsXamlHostWrapperConverter());
Bind(nameof(LoadingStatus), LoadingStatusProperty, windows.UI.Xaml.Controls.Maps.MapControl.LoadingStatusProperty, new WindowsXamlHostWrapperConverter());
Bind(nameof(MapElements), MapElementsProperty, windows.UI.Xaml.Controls.Maps.MapControl.MapElementsProperty);
Comment thread
ocalvo marked this conversation as resolved.
Bind(nameof(Pitch), PitchProperty, windows.UI.Xaml.Controls.Maps.MapControl.PitchProperty);
Bind(nameof(Routes), RoutesProperty, windows.UI.Xaml.Controls.Maps.MapControl.RoutesProperty);
Bind(nameof(TileSources), TileSourcesProperty, windows.UI.Xaml.Controls.Maps.MapControl.TileSourcesProperty);
Bind(nameof(ZoomInteractionMode), ZoomInteractionModeProperty, windows.UI.Xaml.Controls.Maps.MapControl.ZoomInteractionModeProperty, new WindowsXamlHostWrapperConverter());
Bind(nameof(TransitFeaturesVisible), TransitFeaturesVisibleProperty, windows.UI.Xaml.Controls.Maps.MapControl.TransitFeaturesVisibleProperty);
Bind(nameof(TiltInteractionMode), TiltInteractionModeProperty, windows.UI.Xaml.Controls.Maps.MapControl.TiltInteractionModeProperty, new WindowsXamlHostWrapperConverter());
Expand All @@ -95,7 +92,6 @@ protected override void OnInitialized(EventArgs e)
/* Bind(nameof(ViewPadding), ViewPaddingProperty, windows.UI.Xaml.Controls.Maps.MapControl.ViewPaddingProperty);
Bind(nameof(StyleSheet), StyleSheetProperty, windows.UI.Xaml.Controls.Maps.MapControl.StyleSheetProperty, new WindowsXamlHostWrapperConverter()); */
Bind(nameof(MapProjection), MapProjectionProperty, windows.UI.Xaml.Controls.Maps.MapControl.MapProjectionProperty, new WindowsXamlHostWrapperConverter());
Bind(nameof(Layers), LayersProperty, windows.UI.Xaml.Controls.Maps.MapControl.LayersProperty);
Bind(nameof(Region), RegionProperty, windows.UI.Xaml.Controls.Maps.MapControl.RegionProperty);

Children.OfType<WindowsXamlHostBase>().ToList().ForEach(RelocateChildToUwpControl);
Expand Down Expand Up @@ -156,11 +152,6 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj)
public static DependencyProperty LocationProperty { get; } = DependencyProperty.Register(nameof(Center), typeof(Geopoint), typeof(MapControl));
*/

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapElementsProperty"/>
/// </summary>
public static DependencyProperty MapElementsProperty { get; } = DependencyProperty.Register(nameof(MapElements), typeof(System.Collections.Generic.IList<MapElement>), typeof(MapControl));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the removal of Dependency Properties, I assume that means data binding on those will be not possible. Am I missing something?


/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapServiceTokenProperty"/>
/// </summary>
Expand All @@ -183,21 +174,11 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj)
/// </summary>
public static DependencyProperty PitchProperty { get; } = DependencyProperty.Register(nameof(Pitch), typeof(double), typeof(MapControl));

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.RoutesProperty"/>
/// </summary>
public static DependencyProperty RoutesProperty { get; } = DependencyProperty.Register(nameof(Routes), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView>), typeof(MapControl));

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.StyleProperty"/>
/// </summary>
public static new DependencyProperty StyleProperty { get; } = DependencyProperty.Register(nameof(Style), typeof(MapStyle), typeof(MapControl));

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TileSourcesProperty"/>
/// </summary>
public static DependencyProperty TileSourcesProperty { get; } = DependencyProperty.Register(nameof(TileSources), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource>), typeof(MapControl));

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TrafficFlowVisibleProperty"/>
/// </summary>
Expand Down Expand Up @@ -300,11 +281,6 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj)
public static DependencyProperty ViewPaddingProperty { get; } = DependencyProperty.Register(nameof(ViewPadding), typeof(windows.UI.Xaml.Thickness), typeof(MapControl));
*/

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.LayersProperty"/>
/// </summary>
public static DependencyProperty LayersProperty { get; } = DependencyProperty.Register(nameof(Layers), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer>), typeof(MapControl));

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.RegionProperty"/>
/// </summary>
Expand Down Expand Up @@ -618,12 +594,25 @@ public MapLoadingStatus LoadingStatus
get => (MapLoadingStatus)GetValue(LoadingStatusProperty);
}

private System.Collections.Generic.IList<MapElement> _mapElements;

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapElements"/>
/// </summary>
public System.Collections.Generic.IList<MapElement> MapElements
{
get => (System.Collections.Generic.IList<MapElement>)GetValue(MapElementsProperty);
get
{
if (_mapElements == null)
{
_mapElements = new WindowsRuntimeCollection<MapElement, windows.UI.Xaml.Controls.Maps.MapElement>(
this.UwpControl.MapElements,
mp => MapElement.FromMapElement(mp),
mp => mp.UwpInstance);
}

return _mapElements;
}
}

/// <summary>
Expand Down Expand Up @@ -655,15 +644,15 @@ public double Pitch
/// </summary>
public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView> Routes
{
get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView>)GetValue(RoutesProperty);
get => this.UwpControl.Routes;
}

/// <summary>
/// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TileSources"/>
/// </summary>
public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource> TileSources
{
get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource>)GetValue(TileSourcesProperty);
get => this.UwpControl.TileSources;
}

/// <summary>
Expand Down Expand Up @@ -822,8 +811,8 @@ public MapProjection MapProjection
/// </summary>
public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer> Layers
{
get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer>)GetValue(LayersProperty);
set => SetValue(LayersProperty, value);
get => this.UwpControl.Layers;
set => this.UwpControl.Layers = value;
}

/// <summary>
Expand Down