Reworked sample applications

This commit is contained in:
Clemens 2022-01-13 20:12:49 +01:00
parent e2f4fc13b1
commit 1d1b2942b4
9 changed files with 468 additions and 283 deletions

View file

@ -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)
{

View file

@ -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)
{

View file

@ -1,24 +1,5 @@
using MapControl;
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
{
@ -40,164 +21,8 @@ namespace SampleApplication
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>
{
{
"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 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",

View file

@ -86,7 +86,6 @@
<map:Map x:Name="map" ManipulationMode="All"
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
MapLayer="{Binding MapLayers[OpenStreetMap]}"
PointerMoved="MapPointerMoved"
PointerExited="MapPointerExited">
<map:Map.Center>
@ -116,16 +115,95 @@
</Border>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6" Background="#7FFFFFFF">
<tools:MapLayersMenuButton
Margin="2" Padding="8" ToolTipService.ToolTip="Map Layers"
Map="{Binding ElementName=map}"
MapLayers="{Binding MapLayers}"
MapOverlays="{Binding MapOverlays}"/>
<tools:MapLayersMenuButton x:Name="mapLayersMenuButton"
Margin="2" Padding="8" ToolTipService.ToolTip="Map Layers and Overlays"
Map="{Binding ElementName=map}">
<tools:MapLayerItem Text="OpenStreetMap">
<map:MapTileLayer
SourceName="OpenStreetMap"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://tile.openstreetmap.org/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap German">
<map:MapTileLayer
SourceName="OpenStreetMap German"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap French">
<map:MapTileLayer
SourceName="OpenStreetMap French"
Description="© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenTopoMap">
<map:MapTileLayer
SourceName="OpenTopoMap"
Description="© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://tile.opentopomap.org/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMTS">
<map:WmtsTileLayer
SourceName="TopPlusOpen"
Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)"
CapabilitiesUri="https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMS">
<map: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="https://sgx.geodatenzentrum.de/wms_topplus_open"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap WMS">
<map:WmsImageLayer
Description="© [terrestris GmbH &amp; Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
ServiceUri="http://ows.terrestris.de/osm/service"/>
</tools:MapLayerItem>
<tools:MapLayersMenuButton.MapOverlays>
<tools:MapLayerItem Text="Seamarks">
<map:MapTileLayer SourceName="Seamarks" MinZoomLevel="9" MaxZoomLevel="18">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Graticule">
<map:MapGraticule Opacity="0.7"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Scale">
<map:MapScale HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Sample Image">
<Image Source="10_535_330.jpg">
<map:MapPanel.BoundingBox>
<map:BoundingBox South="53.54031" West="8.08594" North="53.74871" East="8.43750"/>
</map:MapPanel.BoundingBox>
</Image>
</tools:MapLayerItem>
</tools:MapLayersMenuButton.MapOverlays>
</tools:MapLayersMenuButton>
<tools:MapProjectionsMenuButton
Margin="2" Padding="8" ToolTipService.ToolTip="Map Projections"
Map="{Binding ElementName=map}"
MapProjections="{Binding MapProjections}"/>
Map="{Binding ElementName=map}">
<tools:MapProjectionItem Text="Web Mercator">
<map:WebMercatorProjection/>
</tools:MapProjectionItem>
<tools:MapProjectionItem Text="Equirectangular">
<map:EquirectangularProjection/>
</tools:MapProjectionItem>
</tools:MapProjectionsMenuButton>
<Slider Orientation="Vertical" Margin="4,8" Height="100"
Minimum="{Binding MinZoomLevel, ElementName=map}"

View file

@ -1,11 +1,13 @@
using MapControl;
using MapControl.UiTools;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
namespace SampleApplication
{
@ -13,25 +15,63 @@ namespace SampleApplication
{
static MainPage()
{
try
{
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new MapControl.Caching.SQLiteCache(TileImageLoader.DefaultCacheFolder);
TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new MapControl.Caching.SQLiteCache(TileImageLoader.DefaultCacheFolder);
BingMapsTileLayer.ApiKey = File.ReadAllText("BingMapsApiKey.txt")?.Trim();
}
catch (Exception ex)
var bingMapsApiKeyPath = "BingMapsApiKey.txt";
if (File.Exists(bingMapsApiKeyPath))
{
Debug.WriteLine(ex.Message);
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim();
}
}
public MainPage()
{
InitializeComponent();
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
{
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Road",
Layer = new BingMapsTileLayer
{
Mode = BingMapsTileLayer.MapMode.Road,
SourceName = "Bing Maps Road",
Description = "© [Microsoft](http://www.bing.com/maps/)"
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial",
Layer = 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)
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial with Labels",
Layer = 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)
}
});
}
}
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)

View file

@ -87,7 +87,6 @@
<map:Map x:Name="map" ManipulationMode="All"
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
MapLayer="{Binding MapLayers[OpenStreetMap]}"
PointerMoved="MapPointerMoved"
PointerExited="MapPointerExited">
<map:Map.Center>
@ -117,16 +116,95 @@
</Border>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6">
<tools:MapLayersMenuButton
<tools:MapLayersMenuButton x:Name="mapLayersMenuButton"
Margin="2" Padding="8" ToolTipService.ToolTip="Map Layers and Overlays"
Map="{Binding ElementName=map}"
MapLayers="{Binding MapLayers}"
MapOverlays="{Binding MapOverlays}"/>
Map="{Binding ElementName=map}">
<tools:MapLayerItem Text="OpenStreetMap">
<map:MapTileLayer
SourceName="OpenStreetMap"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://tile.openstreetmap.org/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap German">
<map:MapTileLayer
SourceName="OpenStreetMap German"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap French">
<map:MapTileLayer
SourceName="OpenStreetMap French"
Description="© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenTopoMap">
<map:MapTileLayer
SourceName="OpenTopoMap"
Description="© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="https://tile.opentopomap.org/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMTS">
<map:WmtsTileLayer
SourceName="TopPlusOpen"
Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)"
CapabilitiesUri="https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMS">
<map: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="https://sgx.geodatenzentrum.de/wms_topplus_open"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap WMS">
<map:WmsImageLayer
Description="© [terrestris GmbH &amp; Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
ServiceUri="http://ows.terrestris.de/osm/service"/>
</tools:MapLayerItem>
<tools:MapLayersMenuButton.MapOverlays>
<tools:MapLayerItem Text="Seamarks">
<map:MapTileLayer SourceName="Seamarks" MinZoomLevel="9" MaxZoomLevel="18">
<map:MapTileLayer.TileSource>
<map:TileSource UriFormat="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"/>
</map:MapTileLayer.TileSource>
</map:MapTileLayer>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Graticule">
<map:MapGraticule Opacity="0.7"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Scale">
<map:MapScale HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Sample Image">
<Image Source="10_535_330.jpg">
<map:MapPanel.BoundingBox>
<map:BoundingBox South="53.54031" West="8.08594" North="53.74871" East="8.43750"/>
</map:MapPanel.BoundingBox>
</Image>
</tools:MapLayerItem>
</tools:MapLayersMenuButton.MapOverlays>
</tools:MapLayersMenuButton>
<tools:MapProjectionsMenuButton
<tools:MapProjectionsMenuButton x:Name="mapProjectionsMenuButton"
Margin="2" Padding="8" ToolTipService.ToolTip="Map Projections"
Map="{Binding ElementName=map}"
MapProjections="{Binding MapProjections}"/>
Map="{Binding ElementName=map}">
<tools:MapProjectionItem Text="Web Mercator">
<map:WebMercatorProjection/>
</tools:MapProjectionItem>
<tools:MapProjectionItem Text="Equirectangular">
<map:EquirectangularProjection/>
</tools:MapProjectionItem>
</tools:MapProjectionsMenuButton>
<Slider Orientation="Vertical" Margin="4,8" Height="100"
Minimum="{Binding MinZoomLevel, ElementName=map}"

View file

@ -1,9 +1,11 @@
using MapControl;
using MapControl.Caching;
using MapControl.UiTools;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
@ -14,23 +16,19 @@ namespace SampleApplication
{
static MainWindow()
{
try
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
var bingMapsApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
if (File.Exists(bingMapsApiKeyPath))
{
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
var bingMapsApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public MainWindow()
@ -39,12 +37,56 @@ namespace SampleApplication
Title = "XAML Map Control - WinUI Sample Application";
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
{
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Road",
Layer = new BingMapsTileLayer
{
Mode = BingMapsTileLayer.MapMode.Road,
SourceName = "Bing Maps Road",
Description = "© [Microsoft](http://www.bing.com/maps/)"
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial",
Layer = 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)
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial with Labels",
Layer = 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)
}
});
}
AddChartServerLayer();
if (TileImageLoader.Cache is ImageFileCache)
{
Activated += WindowActivated;
}
}
partial void AddChartServerLayer();
private async void WindowActivated(object sender, WindowActivatedEventArgs e)
{
Activated -= WindowActivated;

View file

@ -105,11 +105,10 @@
<Grid.DataContext>
<local:MapViewModel/>
</Grid.DataContext>
<map:Map x:Name="map"
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11" MouseWheelZoomDelta="1"
Center="53.5,8.2"
MapLayer="{Binding MapLayers[OpenStreetMap]}"
MouseLeftButtonDown="MapMouseLeftButtonDown"
MouseRightButtonDown="MapMouseRightButtonDown"
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave"
@ -144,16 +143,79 @@
</Border>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6">
<tools:MapLayersMenuButton
<tools:MapLayersMenuButton x:Name="mapLayersMenuButton"
Margin="2" Padding="6" FontSize="16" ToolTip="Map Layers and Overlays"
Map="{Binding ElementName=map}"
MapLayers="{Binding MapLayers}"
MapOverlays="{Binding MapOverlays}"/>
Map="{Binding ElementName=map}">
<tools:MapLayerItem Text="OpenStreetMap">
<map:MapTileLayer
TileSource="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
SourceName="OpenStreetMap"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap German">
<map:MapTileLayer
TileSource="https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png"
SourceName="OpenStreetMap German"
Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap French">
<map:MapTileLayer
TileSource="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)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenTopoMap">
<map:MapTileLayer
TileSource="https://tile.opentopomap.org/{z}/{x}/{y}.png"
SourceName="OpenTopoMap"
Description="© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMTS">
<map:WmtsTileLayer
CapabilitiesUri="https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml"
SourceName="TopPlusOpen"
Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="TopPlusOpen WMS">
<map:WmsImageLayer
ServiceUri="https://sgx.geodatenzentrum.de/wms_topplus_open"
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)"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="OpenStreetMap WMS">
<map:WmsImageLayer
ServiceUri="http://ows.terrestris.de/osm/service"
Description="© [terrestris GmbH &amp; Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/>
</tools:MapLayerItem>
<tools:MapLayersMenuButton.MapOverlays>
<tools:MapLayerItem Text="Seamarks">
<map:MapTileLayer
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
SourceName="Seamarks"
MinZoomLevel="9"
MaxZoomLevel="18"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Graticule">
<map:MapGraticule Opacity="0.7"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Scale">
<map:MapScale HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
</tools:MapLayerItem>
<tools:MapLayerItem Text="Sample Image">
<Image Source="10_535_330.jpg" map:MapPanel.BoundingBox="53.54031,8.08594,53.74871,8.43750"/>
</tools:MapLayerItem>
</tools:MapLayersMenuButton.MapOverlays>
</tools:MapLayersMenuButton>
<tools:MapProjectionsMenuButton
<tools:MapProjectionsMenuButton x:Name="mapProjectionsMenuButton"
Margin="2" Padding="6" FontSize="16" ToolTip="Map Projections"
Map="{Binding ElementName=map}"
MapProjections="{Binding MapProjections}"/>
Map="{Binding ElementName=map}">
<tools:MapProjectionItem Text="Web Mercator">
<map:WebMercatorProjection/>
</tools:MapProjectionItem>
<tools:MapProjectionItem Text="Equirectangular">
<map:EquirectangularProjection/>
</tools:MapProjectionItem>
</tools:MapProjectionsMenuButton>
<Slider Orientation="Vertical" Margin="8" Height="100"
Minimum="{Binding MinZoomLevel, ElementName=map}"

View file

@ -1,12 +1,13 @@
using MapControl;
using MapControl.Caching;
using MapControl.UiTools;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SampleApplication
{
@ -14,30 +15,68 @@ namespace SampleApplication
{
static MainWindow()
{
try
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = null;
var bingMapsApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
if (File.Exists(bingMapsApiKeyPath))
{
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = null;
var bingMapsApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public MainWindow()
{
InitializeComponent();
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
{
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Road",
Layer = new BingMapsTileLayer
{
Mode = BingMapsTileLayer.MapMode.Road,
SourceName = "Bing Maps Road",
Description = "© [Microsoft](http://www.bing.com/maps/)"
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial",
Layer = 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)
}
});
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "Bing Maps Aerial with Labels",
Layer = 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)
}
});
}
AddChartServerLayer();
if (TileImageLoader.Cache is ImageFileCache cache)
{
Loaded += async (s, e) =>
@ -48,6 +87,8 @@ namespace SampleApplication
}
}
partial void AddChartServerLayer();
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)
{
map.TargetHeading = 0d;