mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
96 lines
2.6 KiB
C#
96 lines
2.6 KiB
C#
#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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|