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)
|
|
|
|
|
|
|
2017-10-07 17:43:28 +02:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MBTileLayer : MapTileLayer
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty FileProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(File), typeof(string), typeof(MBTileLayer),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MBTileLayer)o).FilePropertyChanged((string)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public MBTileLayer()
|
|
|
|
|
|
: this(new TileImageLoader())
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MBTileLayer(ITileImageLoader tileImageLoader)
|
|
|
|
|
|
: base(tileImageLoader)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string File
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (string)GetValue(FileProperty); }
|
|
|
|
|
|
set { SetValue(FileProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void FilePropertyChanged(string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
MBTileSource ts;
|
|
|
|
|
|
|
|
|
|
|
|
if (file != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ts = new MBTileSource(file);
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("name"))
|
|
|
|
|
|
{
|
|
|
|
|
|
SourceName = ts.Metadata["name"];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("description"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Description = ts.Metadata["description"];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("minzoom"))
|
|
|
|
|
|
{
|
|
|
|
|
|
int minZoom;
|
|
|
|
|
|
if (int.TryParse(ts.Metadata["minzoom"], out minZoom))
|
|
|
|
|
|
{
|
|
|
|
|
|
MinZoomLevel = minZoom;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("maxzoom"))
|
|
|
|
|
|
{
|
|
|
|
|
|
int maxZoom;
|
|
|
|
|
|
if (int.TryParse(ts.Metadata["maxzoom"], out maxZoom))
|
|
|
|
|
|
{
|
|
|
|
|
|
MaxZoomLevel = maxZoom;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TileSource = ts;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ((ts = TileSource as MBTileSource) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(TileSourceProperty);
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("name"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(SourceNameProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("description"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(DescriptionProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("minzoom"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(MinZoomLevelProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ts.Metadata.ContainsKey("maxzoom"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearValue(MaxZoomLevelProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|