2018-08-08 23:31:52 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// <20> 2018 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2018-12-09 17:14:32 +01:00
|
|
|
|
namespace MapControl.MBTiles
|
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),
|
2018-08-15 23:29:03 +02:00
|
|
|
|
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); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
private async Task FilePropertyChanged(string file)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
var mbTileSource = TileSource as MBTileSource;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource != null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (file == null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
ClearValue(TileSourceProperty);
|
2017-10-07 17:43:28 +02:00
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.Name != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(SourceNameProperty);
|
|
|
|
|
|
}
|
2017-10-07 17:43:28 +02:00
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.Description != null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
ClearValue(DescriptionProperty);
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.MinZoom.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(MinZoomLevelProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mbTileSource.MaxZoom.HasValue)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
ClearValue(MaxZoomLevelProperty);
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
mbTileSource.Dispose();
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
2018-08-15 23:29:03 +02:00
|
|
|
|
|
|
|
|
|
|
if (file != null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
mbTileSource = new MBTileSource(file);
|
2017-10-07 17:43:28 +02:00
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
await mbTileSource.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
if (mbTileSource.Name != null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
SourceName = mbTileSource.Name;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.Description != null)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
Description = mbTileSource.Description;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.MinZoom.HasValue)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
MinZoomLevel = mbTileSource.MinZoom.Value;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-15 23:29:03 +02:00
|
|
|
|
if (mbTileSource.MaxZoom.HasValue)
|
2017-10-07 17:43:28 +02:00
|
|
|
|
{
|
2018-08-15 23:29:03 +02:00
|
|
|
|
MaxZoomLevel = mbTileSource.MaxZoom.Value;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
2018-08-15 23:29:03 +02:00
|
|
|
|
|
|
|
|
|
|
TileSource = mbTileSource;
|
2017-10-07 17:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|