mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Reworked sample applications
This commit is contained in:
parent
e2f4fc13b1
commit
1d1b2942b4
9 changed files with 468 additions and 283 deletions
|
|
@ -2,78 +2,84 @@
|
|||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Markup;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
#endif
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(Layer))]
|
||||
#else
|
||||
[ContentProperty(nameof(Layer))]
|
||||
#endif
|
||||
public class MapLayerItem
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public UIElement Layer { get; set; }
|
||||
}
|
||||
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(MapLayers))]
|
||||
#else
|
||||
[ContentProperty(nameof(MapLayers))]
|
||||
#endif
|
||||
public class MapLayersMenuButton : MenuButton
|
||||
{
|
||||
public MapLayersMenuButton()
|
||||
: base("\uE81E")
|
||||
{
|
||||
((INotifyCollectionChanged)MapLayers).CollectionChanged += (s, e) => InitializeMenu();
|
||||
((INotifyCollectionChanged)MapOverlays).CollectionChanged += (s, e) => InitializeMenu();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MapProperty = DependencyProperty.Register(
|
||||
nameof(Map), typeof(MapBase), typeof(MapLayersMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapLayersMenuButton)o).InitializeMenu()));
|
||||
|
||||
public static readonly DependencyProperty MapLayersProperty = DependencyProperty.Register(
|
||||
nameof(MapLayers), typeof(IDictionary<string, UIElement>), typeof(MapLayersMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapLayersMenuButton)o).InitializeMenu()));
|
||||
|
||||
public static readonly DependencyProperty MapOverlaysProperty = DependencyProperty.Register(
|
||||
nameof(MapOverlays), typeof(IDictionary<string, UIElement>), typeof(MapLayersMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapLayersMenuButton)o).InitializeMenu()));
|
||||
|
||||
public MapBase Map
|
||||
{
|
||||
get { return (MapBase)GetValue(MapProperty); }
|
||||
set { SetValue(MapProperty, value); }
|
||||
}
|
||||
|
||||
public IDictionary<string, UIElement> MapLayers
|
||||
{
|
||||
get { return (IDictionary<string, UIElement>)GetValue(MapLayersProperty); }
|
||||
set { SetValue(MapLayersProperty, value); }
|
||||
}
|
||||
public Collection<MapLayerItem> MapLayers { get; } = new ObservableCollection<MapLayerItem>();
|
||||
|
||||
public IDictionary<string, UIElement> MapOverlays
|
||||
{
|
||||
get { return (IDictionary<string, UIElement>)GetValue(MapOverlaysProperty); }
|
||||
set { SetValue(MapOverlaysProperty, value); }
|
||||
}
|
||||
public Collection<MapLayerItem> MapOverlays { get; } = new ObservableCollection<MapLayerItem>();
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
if (Map != null && MapLayers != null)
|
||||
if (Map != null)
|
||||
{
|
||||
var menu = CreateMenu();
|
||||
|
||||
foreach (var layer in MapLayers)
|
||||
foreach (var item in MapLayers)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(layer.Key, layer.Value, MapLayerClicked));
|
||||
menu.Items.Add(CreateMenuItem(item.Text, item.Layer, MapLayerClicked));
|
||||
}
|
||||
|
||||
var initialLayer = MapLayers.Values.FirstOrDefault();
|
||||
var initialLayer = MapLayers.Select(l => l.Layer).FirstOrDefault();
|
||||
|
||||
if (MapOverlays != null && MapOverlays.Any())
|
||||
if (MapOverlays.Count > 0)
|
||||
{
|
||||
if (initialLayer != null)
|
||||
{
|
||||
menu.Items.Add(CreateSeparator());
|
||||
}
|
||||
|
||||
foreach (var overlay in MapOverlays)
|
||||
foreach (var item in MapOverlays)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(overlay.Key, overlay.Value, MapOverlayClicked));
|
||||
menu.Items.Add(CreateMenuItem(item.Text, item.Layer, MapOverlayClicked));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +123,7 @@ namespace MapControl.UiTools
|
|||
{
|
||||
int index = 1;
|
||||
|
||||
foreach (var overlay in MapOverlays.Values)
|
||||
foreach (var overlay in MapOverlays.Select(l => l.Layer))
|
||||
{
|
||||
if (overlay == layer)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,57 +2,70 @@
|
|||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Markup;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
#endif
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(Projection))]
|
||||
#else
|
||||
[ContentProperty(nameof(Projection))]
|
||||
#endif
|
||||
public class MapProjectionItem
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public MapProjection Projection { get; set; }
|
||||
}
|
||||
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(MapProjections))]
|
||||
#else
|
||||
[ContentProperty(nameof(MapProjections))]
|
||||
#endif
|
||||
public class MapProjectionsMenuButton : MenuButton
|
||||
{
|
||||
public MapProjectionsMenuButton()
|
||||
: base("\uE809")
|
||||
{
|
||||
((INotifyCollectionChanged)MapProjections).CollectionChanged += (s, e) => InitializeMenu();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MapProperty = DependencyProperty.Register(
|
||||
nameof(Map), typeof(MapBase), typeof(MapProjectionsMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapProjectionsMenuButton)o).InitializeMenu()));
|
||||
|
||||
public static readonly DependencyProperty MapProjectionsProperty = DependencyProperty.Register(
|
||||
nameof(MapProjections), typeof(IDictionary<string, MapProjection>), typeof(MapProjectionsMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapProjectionsMenuButton)o).InitializeMenu()));
|
||||
|
||||
public MapBase Map
|
||||
{
|
||||
get { return (MapBase)GetValue(MapProperty); }
|
||||
set { SetValue(MapProperty, value); }
|
||||
}
|
||||
|
||||
public IDictionary<string, MapProjection> MapProjections
|
||||
{
|
||||
get { return (IDictionary<string, MapProjection>)GetValue(MapProjectionsProperty); }
|
||||
set { SetValue(MapProjectionsProperty, value); }
|
||||
}
|
||||
public Collection<MapProjectionItem> MapProjections { get; } = new ObservableCollection<MapProjectionItem>();
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
if (Map != null && MapProjections != null)
|
||||
if (Map != null)
|
||||
{
|
||||
var menu = CreateMenu();
|
||||
|
||||
foreach (var projection in MapProjections)
|
||||
foreach (var item in MapProjections)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(projection.Key, projection.Value, MapProjectionClicked));
|
||||
menu.Items.Add(CreateMenuItem(item.Text, item.Projection, MapProjectionClicked));
|
||||
}
|
||||
|
||||
var initialProjection = MapProjections.Values.FirstOrDefault();
|
||||
var initialProjection = MapProjections.Select(p => p.Projection).FirstOrDefault();
|
||||
|
||||
if (initialProjection != null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue