diff --git a/MBTiles/Shared/MBTileLayer.cs b/MBTiles/Shared/MBTileLayer.cs index e0745dbe..f49ea2d9 100644 --- a/MBTiles/Shared/MBTileLayer.cs +++ b/MBTiles/Shared/MBTileLayer.cs @@ -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); } } } diff --git a/MBTiles/Shared/MBTileSource.cs b/MBTiles/Shared/MBTileSource.cs index 8fd393ae..c3166c69 100644 --- a/MBTiles/Shared/MBTileSource.cs +++ b/MBTiles/Shared/MBTileSource.cs @@ -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 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 CreateAsync(string file) - { - var tiledata = await MBTileData.CreateAsync(file); - var metadata = await tiledata.ReadMetadataAsync(); - - return new MBTileSource(tiledata, metadata); } public void Dispose()