mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.15.1: Simplified MBTiles.
This commit is contained in:
parent
cf9d94ca9d
commit
08e1823e06
|
|
@ -38,63 +38,43 @@ namespace MapControl.MBTiles
|
|||
|
||||
private async Task FilePropertyChanged(string file)
|
||||
{
|
||||
var mbTileSource = TileSource as MBTileSource;
|
||||
(TileSource as MBTileSource)?.Dispose();
|
||||
|
||||
if (mbTileSource != null)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
ClearValue(TileSourceProperty);
|
||||
|
||||
if (mbTileSource.Name != null)
|
||||
{
|
||||
ClearValue(SourceNameProperty);
|
||||
}
|
||||
|
||||
if (mbTileSource.Description != null)
|
||||
{
|
||||
ClearValue(DescriptionProperty);
|
||||
}
|
||||
|
||||
if (mbTileSource.MinZoom.HasValue)
|
||||
{
|
||||
ClearValue(MinZoomLevelProperty);
|
||||
}
|
||||
|
||||
if (mbTileSource.MaxZoom.HasValue)
|
||||
{
|
||||
ClearValue(MaxZoomLevelProperty);
|
||||
}
|
||||
}
|
||||
|
||||
mbTileSource.Dispose();
|
||||
}
|
||||
ClearValue(TileSourceProperty);
|
||||
ClearValue(SourceNameProperty);
|
||||
ClearValue(DescriptionProperty);
|
||||
ClearValue(MinZoomLevelProperty);
|
||||
ClearValue(MaxZoomLevelProperty);
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
mbTileSource = await MBTileSource.CreateAsync(file);
|
||||
var tiledata = await MBTileData.CreateAsync(file);
|
||||
var metadata = await tiledata.ReadMetadataAsync();
|
||||
string s;
|
||||
int minZoom;
|
||||
int maxZoom;
|
||||
|
||||
if (mbTileSource.Name != null)
|
||||
if (metadata.TryGetValue("name", out s))
|
||||
{
|
||||
SourceName = mbTileSource.Name;
|
||||
SourceName = s;
|
||||
}
|
||||
|
||||
if (mbTileSource.Description != null)
|
||||
if (metadata.TryGetValue("description", out s))
|
||||
{
|
||||
Description = mbTileSource.Description;
|
||||
Description = s;
|
||||
}
|
||||
|
||||
if (mbTileSource.MinZoom.HasValue)
|
||||
if (metadata.TryGetValue("minzoom", out s) && int.TryParse(s, out minZoom))
|
||||
{
|
||||
MinZoomLevel = mbTileSource.MinZoom.Value;
|
||||
MinZoomLevel = minZoom;
|
||||
}
|
||||
|
||||
if (mbTileSource.MaxZoom.HasValue)
|
||||
if (metadata.TryGetValue("maxzoom", out s) && int.TryParse(s, out maxZoom))
|
||||
{
|
||||
MaxZoomLevel = mbTileSource.MaxZoom.Value;
|
||||
MaxZoomLevel = maxZoom;
|
||||
}
|
||||
|
||||
TileSource = mbTileSource;
|
||||
TileSource = new MBTileSource(tiledata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
@ -16,52 +15,10 @@ namespace MapControl.MBTiles
|
|||
public sealed class MBTileSource : TileSource, IDisposable
|
||||
{
|
||||
public MBTileData TileData { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
public string Format { get; }
|
||||
public int? MinZoom { get; }
|
||||
public int? MaxZoom { get; }
|
||||
|
||||
private MBTileSource(MBTileData tiledata, IDictionary<string, string> metadata)
|
||||
public MBTileSource(MBTileData tiledata)
|
||||
{
|
||||
TileData = tiledata;
|
||||
|
||||
string s;
|
||||
int minZoom;
|
||||
int maxZoom;
|
||||
|
||||
if (metadata.TryGetValue("name", out s))
|
||||
{
|
||||
Name = s;
|
||||
}
|
||||
|
||||
if (metadata.TryGetValue("description", out s))
|
||||
{
|
||||
Description = s;
|
||||
}
|
||||
|
||||
if (metadata.TryGetValue("format", out s))
|
||||
{
|
||||
Format = s;
|
||||
}
|
||||
|
||||
if (metadata.TryGetValue("minzoom", out s) && int.TryParse(s, out minZoom))
|
||||
{
|
||||
MinZoom = minZoom;
|
||||
}
|
||||
|
||||
if (metadata.TryGetValue("maxzoom", out s) && int.TryParse(s, out maxZoom))
|
||||
{
|
||||
MaxZoom = maxZoom;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<MBTileSource> CreateAsync(string file)
|
||||
{
|
||||
var tiledata = await MBTileData.CreateAsync(file);
|
||||
var metadata = await tiledata.ReadMetadataAsync();
|
||||
|
||||
return new MBTileSource(tiledata, metadata);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
Loading…
Reference in a new issue