XAML-Map-Control/MBTiles/Shared/MBTileLayer.cs

104 lines
2.9 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// <20> 2019 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Threading.Tasks;
2017-10-07 17:43:28 +02:00
#if WINDOWS_UWP
using Windows.UI.Xaml;
#else
using System.Windows;
#endif
namespace MapControl.MBTiles
2017-10-07 17:43:28 +02:00
{
/// <summary>
/// MapTileLayer that uses an MBTiles SQLite Database. See https://wiki.openstreetmap.org/wiki/MBTiles.
/// </summary>
2017-10-07 17:43:28 +02:00
public class MBTileLayer : MapTileLayer
{
public static readonly DependencyProperty FileProperty = DependencyProperty.Register(
nameof(File), typeof(string), typeof(MBTileLayer),
new PropertyMetadata(null, async (o, e) => await ((MBTileLayer)o).FilePropertyChanged((string)e.NewValue)));
2017-10-07 17:43:28 +02:00
public MBTileLayer()
: this(new TileImageLoader())
{
}
public MBTileLayer(ITileImageLoader tileImageLoader)
: base(tileImageLoader)
{
}
public string File
{
get { return (string)GetValue(FileProperty); }
set { SetValue(FileProperty, value); }
}
private async Task FilePropertyChanged(string file)
2017-10-07 17:43:28 +02:00
{
var mbTileSource = TileSource as MBTileSource;
2017-10-07 17:43:28 +02:00
if (mbTileSource != null)
2017-10-07 17:43:28 +02:00
{
if (file == null)
2017-10-07 17:43:28 +02:00
{
ClearValue(TileSourceProperty);
2017-10-07 17:43:28 +02:00
if (mbTileSource.Name != null)
{
ClearValue(SourceNameProperty);
}
2017-10-07 17:43:28 +02:00
if (mbTileSource.Description != null)
2017-10-07 17:43:28 +02:00
{
ClearValue(DescriptionProperty);
2017-10-07 17:43:28 +02:00
}
if (mbTileSource.MinZoom.HasValue)
{
ClearValue(MinZoomLevelProperty);
}
if (mbTileSource.MaxZoom.HasValue)
2017-10-07 17:43:28 +02:00
{
ClearValue(MaxZoomLevelProperty);
2017-10-07 17:43:28 +02:00
}
}
mbTileSource.Dispose();
2017-10-07 17:43:28 +02:00
}
if (file != null)
2017-10-07 17:43:28 +02:00
{
mbTileSource = new MBTileSource(file);
2017-10-07 17:43:28 +02:00
await mbTileSource.Initialize();
if (mbTileSource.Name != null)
2017-10-07 17:43:28 +02:00
{
SourceName = mbTileSource.Name;
2017-10-07 17:43:28 +02:00
}
if (mbTileSource.Description != null)
2017-10-07 17:43:28 +02:00
{
Description = mbTileSource.Description;
2017-10-07 17:43:28 +02:00
}
if (mbTileSource.MinZoom.HasValue)
2017-10-07 17:43:28 +02:00
{
MinZoomLevel = mbTileSource.MinZoom.Value;
2017-10-07 17:43:28 +02:00
}
if (mbTileSource.MaxZoom.HasValue)
2017-10-07 17:43:28 +02:00
{
MaxZoomLevel = mbTileSource.MaxZoom.Value;
2017-10-07 17:43:28 +02:00
}
TileSource = mbTileSource;
2017-10-07 17:43:28 +02:00
}
}
}
}