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
9ce981a6ee
commit
32491a8e31
22 changed files with 947 additions and 706 deletions
|
|
@ -1,182 +0,0 @@
|
|||
using MapControl;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
#if WINUI
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif UWP
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class MapLayers : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
// See https://wiki.openstreetmap.org/wiki/Tile_servers for a list of free OpenStreetMap Tile Servers
|
||||
|
||||
private readonly Dictionary<string, UIElement> mapLayers = new Dictionary<string, UIElement>
|
||||
{
|
||||
{
|
||||
"OpenStreetMap",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://tile.openstreetmap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap German",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap German",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap French",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap French",
|
||||
Description = "© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenTopoMap",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://tile.opentopomap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenTopoMap",
|
||||
Description = "© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 17
|
||||
}
|
||||
},
|
||||
{
|
||||
"Seamarks",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenSeaMap",
|
||||
MinZoomLevel = 9,
|
||||
MaxZoomLevel = 18
|
||||
}
|
||||
},
|
||||
{
|
||||
"Bing Maps Road",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.Road,
|
||||
SourceName = "Bing Maps Road",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Bing Maps Aerial",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.Aerial,
|
||||
SourceName = "Bing Maps Aerial",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
||||
MapForeground = new SolidColorBrush(Colors.White),
|
||||
MapBackground = new SolidColorBrush(Colors.Black)
|
||||
}
|
||||
},
|
||||
{
|
||||
"Bing Maps Aerial with Labels",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.AerialWithLabels,
|
||||
SourceName = "Bing Maps Hybrid",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
||||
MapForeground = new SolidColorBrush(Colors.White),
|
||||
MapBackground = new SolidColorBrush(Colors.Black)
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMTS",
|
||||
new WmtsTileLayer
|
||||
{
|
||||
SourceName = "TopPlusOpen",
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)",
|
||||
CapabilitiesUri = new Uri("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml")
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)",
|
||||
ServiceUri = new Uri("https://sgx.geodatenzentrum.de/wms_topplus_open")
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
ServiceUri = new Uri("http://ows.terrestris.de/osm/service")
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
private string currentMapLayerName = "OpenStreetMap";
|
||||
|
||||
public string CurrentMapLayerName
|
||||
{
|
||||
get { return currentMapLayerName; }
|
||||
set
|
||||
{
|
||||
currentMapLayerName = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentMapLayerName)));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentMapLayer)));
|
||||
}
|
||||
}
|
||||
|
||||
public UIElement CurrentMapLayer
|
||||
{
|
||||
get { return mapLayers[currentMapLayerName]; }
|
||||
}
|
||||
|
||||
public UIElement SeamarksLayer
|
||||
{
|
||||
get { return mapLayers["Seamarks"]; }
|
||||
}
|
||||
|
||||
public List<string> MapLayerNames { get; } = new List<string>
|
||||
{
|
||||
"OpenStreetMap",
|
||||
"OpenStreetMap German",
|
||||
"OpenStreetMap French",
|
||||
"OpenTopoMap",
|
||||
"TopPlusOpen WMTS",
|
||||
"TopPlusOpen WMS",
|
||||
"OpenStreetMap WMS",
|
||||
};
|
||||
|
||||
public MapLayers()
|
||||
{
|
||||
// Add Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
|
||||
// (http://msdn.microsoft.com/en-us/library/ff701716.aspx).
|
||||
// A Bing Maps API Key (http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
|
||||
// for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
|
||||
|
||||
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
|
||||
{
|
||||
MapLayerNames.Add("Bing Maps Road");
|
||||
MapLayerNames.Add("Bing Maps Aerial");
|
||||
MapLayerNames.Add("Bing Maps Aerial with Labels");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
158
SampleApps/Shared/MapLayersMenuButton.cs
Normal file
158
SampleApps/Shared/MapLayersMenuButton.cs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
using MapControl;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class MapLayersMenuButton : MenuButton
|
||||
{
|
||||
public MapLayersMenuButton()
|
||||
{
|
||||
#if WINUI || UWP
|
||||
Content = new FontIcon
|
||||
{
|
||||
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
||||
Glyph = "\uE81E"
|
||||
};
|
||||
#else
|
||||
FontFamily = new FontFamily("Segoe MDL2 Assets");
|
||||
Content = "\uE81E";
|
||||
#endif
|
||||
}
|
||||
|
||||
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 IDictionary<string, UIElement> MapOverlays
|
||||
{
|
||||
get { return (IDictionary<string, UIElement>)GetValue(MapOverlaysProperty); }
|
||||
set { SetValue(MapOverlaysProperty, value); }
|
||||
}
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
if (Map != null && MapLayers != null)
|
||||
{
|
||||
var menu = CreateMenu();
|
||||
|
||||
foreach (var layer in MapLayers)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(layer.Key, layer.Value, MapLayerClicked));
|
||||
}
|
||||
|
||||
var initialLayer = MapLayers.Values.FirstOrDefault();
|
||||
|
||||
if (MapOverlays != null && MapOverlays.Any())
|
||||
{
|
||||
if (initialLayer != null)
|
||||
{
|
||||
menu.Items.Add(CreateSeparator());
|
||||
}
|
||||
|
||||
foreach (var overlay in MapOverlays)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(overlay.Key, overlay.Value, MapOverlayClicked));
|
||||
}
|
||||
}
|
||||
|
||||
if (initialLayer != null)
|
||||
{
|
||||
SetMapLayer(initialLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MapLayerClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var item = (FrameworkElement)sender;
|
||||
var layer = (UIElement)item.Tag;
|
||||
|
||||
SetMapLayer(layer);
|
||||
}
|
||||
|
||||
private void MapOverlayClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var item = (FrameworkElement)sender;
|
||||
var layer = (UIElement)item.Tag;
|
||||
|
||||
ToggleMapOverlay(layer);
|
||||
}
|
||||
|
||||
private void SetMapLayer(UIElement layer)
|
||||
{
|
||||
Map.MapLayer = layer;
|
||||
|
||||
UpdateCheckedStates();
|
||||
}
|
||||
|
||||
private void ToggleMapOverlay(UIElement layer)
|
||||
{
|
||||
if (Map.Children.Contains(layer))
|
||||
{
|
||||
Map.Children.Remove(layer);
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = 1;
|
||||
|
||||
foreach (var overlay in MapOverlays.Values)
|
||||
{
|
||||
if (overlay == layer)
|
||||
{
|
||||
Map.Children.Insert(index, layer);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Map.Children.Contains(overlay))
|
||||
{
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpdateCheckedStates();
|
||||
}
|
||||
|
||||
private void UpdateCheckedStates()
|
||||
{
|
||||
foreach (var item in GetMenuItems())
|
||||
{
|
||||
item.IsChecked = Map.Children.Contains((UIElement)item.Tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
SampleApps/Shared/MapProjectionsMenuButton.cs
Normal file
94
SampleApps/Shared/MapProjectionsMenuButton.cs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
using MapControl;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class MapProjectionsMenuButton : MenuButton
|
||||
{
|
||||
public MapProjectionsMenuButton()
|
||||
{
|
||||
#if WINUI || UWP
|
||||
Content = new FontIcon
|
||||
{
|
||||
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
||||
Glyph = "\uE809"
|
||||
};
|
||||
#else
|
||||
FontFamily = new FontFamily("Segoe MDL2 Assets");
|
||||
Content = "\uE809";
|
||||
#endif
|
||||
}
|
||||
|
||||
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); }
|
||||
}
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
if (Map != null && MapProjections != null)
|
||||
{
|
||||
var menu = CreateMenu();
|
||||
|
||||
foreach (var projection in MapProjections)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(projection.Key, projection.Value, MapProjectionClicked));
|
||||
}
|
||||
|
||||
var initialProjection = MapProjections.Values.FirstOrDefault();
|
||||
|
||||
if (initialProjection != null)
|
||||
{
|
||||
SetMapProjection(initialProjection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MapProjectionClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var item = (FrameworkElement)sender;
|
||||
var projection = (MapProjection)item.Tag;
|
||||
|
||||
SetMapProjection(projection);
|
||||
}
|
||||
|
||||
private void SetMapProjection(MapProjection projection)
|
||||
{
|
||||
Map.MapProjection = projection;
|
||||
|
||||
foreach (var item in GetMenuItems())
|
||||
{
|
||||
item.IsChecked = Map.MapProjection == (MapProjection)item.Tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +1,233 @@
|
|||
using MapControl;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if WINUI
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
#elif UWP
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class ViewModelBase : INotifyPropertyChanged
|
||||
public class PointItem
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public string Name { get; set; }
|
||||
|
||||
protected void RaisePropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
public Location Location { get; set; }
|
||||
}
|
||||
|
||||
public class PointItem : ViewModelBase
|
||||
{
|
||||
private string name;
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set
|
||||
{
|
||||
name = value;
|
||||
RaisePropertyChanged(nameof(Name));
|
||||
}
|
||||
}
|
||||
|
||||
private Location location;
|
||||
public Location Location
|
||||
{
|
||||
get { return location; }
|
||||
set
|
||||
{
|
||||
location = value;
|
||||
RaisePropertyChanged(nameof(Location));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Polyline
|
||||
public class PolylineItem
|
||||
{
|
||||
public LocationCollection Locations { get; set; }
|
||||
}
|
||||
|
||||
public class MapViewModel : ViewModelBase
|
||||
public class MapViewModel
|
||||
{
|
||||
private Location mapCenter = new Location(53.5, 8.2);
|
||||
public Location MapCenter
|
||||
public List<PointItem> Points { get; } = new List<PointItem>();
|
||||
public List<PointItem> Pushpins { get; } = new List<PointItem>();
|
||||
public List<PolylineItem> Polylines { get; } = new List<PolylineItem>();
|
||||
|
||||
public Dictionary<string, MapProjection> MapProjections { get; } = new Dictionary<string, MapProjection>
|
||||
{
|
||||
{ "Web Mercator", new WebMercatorProjection() },
|
||||
{ "World Mercator", new WorldMercatorProjection() },
|
||||
{ "Equirectangular", new EquirectangularProjection() },
|
||||
{ "Orthographic", new OrthographicProjection() },
|
||||
{ "Gnomonic", new GnomonicProjection() },
|
||||
{ "Stereographic", new StereographicProjection() }
|
||||
};
|
||||
|
||||
public Dictionary<string, UIElement> MapLayers { get; } = new Dictionary<string, UIElement>
|
||||
{
|
||||
get { return mapCenter; }
|
||||
set
|
||||
{
|
||||
mapCenter = value;
|
||||
RaisePropertyChanged(nameof(MapCenter));
|
||||
"OpenStreetMap",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://tile.openstreetmap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap German",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap German",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap French",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap French",
|
||||
Description = "© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenTopoMap",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://tile.opentopomap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenTopoMap",
|
||||
Description = "© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 17
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMTS",
|
||||
new WmtsTileLayer
|
||||
{
|
||||
SourceName = "TopPlusOpen",
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)",
|
||||
CapabilitiesUri = new Uri("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml")
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)",
|
||||
ServiceUri = new Uri("https://sgx.geodatenzentrum.de/wms_topplus_open")
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
ServiceUri = new Uri("http://ows.terrestris.de/osm/service")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ObservableCollection<PointItem> Points { get; } = new ObservableCollection<PointItem>();
|
||||
public ObservableCollection<PointItem> Pushpins { get; } = new ObservableCollection<PointItem>();
|
||||
public ObservableCollection<Polyline> Polylines { get; } = new ObservableCollection<Polyline>();
|
||||
|
||||
public MapLayers MapLayers { get; } = new MapLayers();
|
||||
public Dictionary<string, UIElement> MapOverlays { get; } = new Dictionary<string, UIElement>
|
||||
{
|
||||
{
|
||||
"Sample Image",
|
||||
new Image()
|
||||
},
|
||||
{
|
||||
"Seamarks",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenSeaMap",
|
||||
MinZoomLevel = 9,
|
||||
MaxZoomLevel = 18
|
||||
}
|
||||
},
|
||||
{
|
||||
"Graticule",
|
||||
new MapGraticule
|
||||
{
|
||||
Opacity = 0.75
|
||||
}
|
||||
},
|
||||
{
|
||||
"Scale",
|
||||
new MapScale
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Bottom
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public MapViewModel()
|
||||
{
|
||||
// Add Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
|
||||
// (http://msdn.microsoft.com/en-us/library/ff701716.aspx).
|
||||
// A Bing Maps API Key (http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
|
||||
// for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
|
||||
|
||||
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
|
||||
{
|
||||
MapLayers.Add(
|
||||
"Bing Maps Road",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.Road,
|
||||
SourceName = "Bing Maps Road",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)"
|
||||
});
|
||||
|
||||
MapLayers.Add(
|
||||
"Bing Maps Aerial",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.Aerial,
|
||||
SourceName = "Bing Maps Aerial",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
||||
MapForeground = new SolidColorBrush(Colors.White),
|
||||
MapBackground = new SolidColorBrush(Colors.Black)
|
||||
});
|
||||
|
||||
MapLayers.Add(
|
||||
"Bing Maps Aerial with Labels",
|
||||
new BingMapsTileLayer
|
||||
{
|
||||
Mode = BingMapsTileLayer.MapMode.AerialWithLabels,
|
||||
SourceName = "Bing Maps Hybrid",
|
||||
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
||||
MapForeground = new SolidColorBrush(Colors.White),
|
||||
MapBackground = new SolidColorBrush(Colors.Black)
|
||||
});
|
||||
}
|
||||
|
||||
var sampleImage = (Image)MapOverlays["Sample Image"];
|
||||
#if WINUI || UWP
|
||||
sampleImage.Source = new BitmapImage(new Uri("ms-appx:///10_535_330.jpg"));
|
||||
#else
|
||||
sampleImage.Source = new BitmapImage(new Uri("pack://siteoforigin:,,,/10_535_330.jpg"));
|
||||
#endif
|
||||
MapPanel.SetBoundingBox(sampleImage, new BoundingBox(53.54031, 8.08594, 53.74871, 8.43750));
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Steinbake Leitdamm",
|
||||
Location = new Location(53.51217, 8.16603)
|
||||
});
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Buhne 2",
|
||||
Location = new Location(53.50926, 8.15815)
|
||||
});
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Buhne 4",
|
||||
Location = new Location(53.50468, 8.15343)
|
||||
});
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Buhne 6",
|
||||
Location = new Location(53.50092, 8.15267)
|
||||
});
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Buhne 8",
|
||||
Location = new Location(53.49871, 8.15321)
|
||||
});
|
||||
|
||||
Points.Add(new PointItem
|
||||
{
|
||||
Name = "Buhne 10",
|
||||
|
|
@ -101,27 +239,31 @@ namespace SampleApplication
|
|||
Name = "WHV - Eckwarderhörne",
|
||||
Location = new Location(53.5495, 8.1877)
|
||||
});
|
||||
|
||||
Pushpins.Add(new PointItem
|
||||
{
|
||||
Name = "JadeWeserPort",
|
||||
Location = new Location(53.5914, 8.14)
|
||||
});
|
||||
|
||||
Pushpins.Add(new PointItem
|
||||
{
|
||||
Name = "Kurhaus Dangast",
|
||||
Location = new Location(53.447, 8.1114)
|
||||
});
|
||||
|
||||
Pushpins.Add(new PointItem
|
||||
{
|
||||
Name = "Eckwarderhörne",
|
||||
Location = new Location(53.5207, 8.2323)
|
||||
});
|
||||
|
||||
Polylines.Add(new Polyline
|
||||
Polylines.Add(new PolylineItem
|
||||
{
|
||||
Locations = LocationCollection.Parse("53.5140,8.1451 53.5123,8.1506 53.5156,8.1623 53.5276,8.1757 53.5491,8.1852 53.5495,8.1877 53.5426,8.1993 53.5184,8.2219 53.5182,8.2386 53.5195,8.2387")
|
||||
});
|
||||
Polylines.Add(new Polyline
|
||||
|
||||
Polylines.Add(new PolylineItem
|
||||
{
|
||||
Locations = LocationCollection.Parse("53.5978,8.1212 53.6018,8.1494 53.5859,8.1554 53.5852,8.1531 53.5841,8.1539 53.5802,8.1392 53.5826,8.1309 53.5867,8.1317 53.5978,8.1212")
|
||||
});
|
||||
|
|
|
|||
73
SampleApps/Shared/MenuButton.cs
Normal file
73
SampleApps/Shared/MenuButton.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class MenuButton : Button
|
||||
{
|
||||
#if WINUI || UWP
|
||||
protected MenuFlyout CreateMenu()
|
||||
{
|
||||
var menu = new MenuFlyout();
|
||||
Flyout = menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
protected IEnumerable<ToggleMenuFlyoutItem> GetMenuItems()
|
||||
{
|
||||
return ((MenuFlyout)Flyout).Items.OfType<ToggleMenuFlyoutItem>();
|
||||
}
|
||||
|
||||
protected static ToggleMenuFlyoutItem CreateMenuItem(string text, object item, RoutedEventHandler click)
|
||||
{
|
||||
var menuItem = new ToggleMenuFlyoutItem { Text = text, Tag = item };
|
||||
menuItem.Click += click;
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
protected static MenuFlyoutSeparator CreateSeparator()
|
||||
{
|
||||
return new MenuFlyoutSeparator();
|
||||
}
|
||||
#else
|
||||
protected ContextMenu CreateMenu()
|
||||
{
|
||||
var menu = new ContextMenu();
|
||||
ContextMenu = menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
protected IEnumerable<MenuItem> GetMenuItems()
|
||||
{
|
||||
return ContextMenu.Items.OfType<MenuItem>();
|
||||
}
|
||||
|
||||
protected static MenuItem CreateMenuItem(string text, object item, RoutedEventHandler click)
|
||||
{
|
||||
var menuItem = new MenuItem { Header = text, Tag = item };
|
||||
menuItem.Click += click;
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
protected static Separator CreateSeparator()
|
||||
{
|
||||
return new Separator();
|
||||
}
|
||||
|
||||
protected MenuButton()
|
||||
{
|
||||
Click += (s, e) => ContextMenu.IsOpen = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue