Version 4.12.2 Fixed local file handling for UWP. All relative paths relative to ms-appx:

This commit is contained in:
ClemensF 2019-06-15 01:39:07 +02:00
parent 26bf0b5005
commit c28387f87c
14 changed files with 172 additions and 192 deletions

View file

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
#if WINDOWS_UWP #if WINDOWS_UWP
using SQLiteCommand = Microsoft.Data.Sqlite.SqliteCommand; using SQLiteCommand = Microsoft.Data.Sqlite.SqliteCommand;
@ -21,7 +22,7 @@ namespace MapControl.MBTiles
public MBTileData(string file) public MBTileData(string file)
{ {
connection = new SQLiteConnection("Data Source=" + file); connection = new SQLiteConnection("Data Source=" + Path.GetFullPath(file));
} }
public Task OpenAsync() public Task OpenAsync()

View file

@ -32,7 +32,7 @@ namespace MapControl
{ {
if (!uri.IsAbsoluteUri || uri.Scheme == "file") if (!uri.IsAbsoluteUri || uri.Scheme == "file")
{ {
image = await LoadLocalImageAsync(uri); image = await LoadImageAsync(uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString);
} }
else if (uri.Scheme == "http" || uri.Scheme == "https") else if (uri.Scheme == "http" || uri.Scheme == "https")
{ {

View file

@ -230,13 +230,13 @@ namespace MapControl
UpdateBoundingBox(); UpdateBoundingBox();
ImageSource imageSource = null; ImageSource image = null;
if (BoundingBox != null) if (BoundingBox != null)
{ {
try try
{ {
imageSource = await GetImageAsync(); image = await GetImageAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -244,7 +244,7 @@ namespace MapControl
} }
} }
SwapImages(imageSource); SwapImages(image);
updateInProgress = false; updateInProgress = false;
} }
@ -321,7 +321,7 @@ namespace MapControl
} }
} }
private void SwapImages(ImageSource imageSource) private void SwapImages(ImageSource image)
{ {
var topImage = (Image)Children[0]; var topImage = (Image)Children[0];
var bottomImage = (Image)Children[1]; var bottomImage = (Image)Children[1];
@ -329,7 +329,7 @@ namespace MapControl
Children.RemoveAt(0); Children.RemoveAt(0);
Children.Insert(1, topImage); Children.Insert(1, topImage);
topImage.Source = imageSource; topImage.Source = image;
SetBoundingBox(topImage, BoundingBox?.Clone()); SetBoundingBox(topImage, BoundingBox?.Clone());
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation topImage.BeginAnimation(OpacityProperty, new DoubleAnimation

View file

@ -6,7 +6,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -57,7 +56,7 @@ namespace MapControl
/// If the UriFormat of TileSource starts with "http" and SourceName is a non-empty string, /// If the UriFormat of TileSource starts with "http" and SourceName is a non-empty string,
/// tile images will be cached in the TileImageLoader's Cache. /// tile images will be cached in the TileImageLoader's Cache.
/// </summary> /// </summary>
public async void LoadTilesAsync(IEnumerable<Tile> tiles) public void LoadTilesAsync(IEnumerable<Tile> tiles)
{ {
tileQueue.Clear(); tileQueue.Clear();
tileQueue.Enqueue(tiles); tileQueue.Enqueue(tiles);
@ -68,9 +67,10 @@ namespace MapControl
{ {
Interlocked.Add(ref taskCount, newTasks); Interlocked.Add(ref taskCount, newTasks);
await Task while (--newTasks >= 0)
.WhenAll(Enumerable.Range(0, newTasks).Select(n => LoadTilesFromQueueAsync())) {
.ConfigureAwait(false); Task.Run(() => LoadTilesFromQueueAsync());
}
} }
} }

View file

@ -119,9 +119,9 @@ namespace MapControl
protected override async Task<ImageSource> GetImageAsync() protected override async Task<ImageSource> GetImageAsync()
{ {
var imageUri = GetImageUri(); var uri = GetImageUri();
return imageUri != null ? await ImageLoader.LoadImageAsync(imageUri) : null; return uri != null ? await ImageLoader.LoadImageAsync(uri) : null;
} }
/// <summary> /// <summary>

View file

@ -31,28 +31,18 @@ namespace MapControl
{ {
await stream.WriteAsync(buffer.AsBuffer()); await stream.WriteAsync(buffer.AsBuffer());
stream.Seek(0); stream.Seek(0);
return await LoadImageAsync(stream); return await LoadImageAsync(stream);
} }
} }
private static async Task<ImageSource> LoadImageAsync(IHttpContent content) public static async Task<ImageSource> LoadImageAsync(string path)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await LoadImageAsync(stream);
}
}
private static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
{ {
ImageSource image = null; ImageSource image = null;
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
if (File.Exists(path)) if (File.Exists(path))
{ {
var file = await StorageFile.GetFileFromPathAsync(path); var file = await StorageFile.GetFileFromPathAsync(Path.GetFullPath(path));
using (var stream = await file.OpenReadAsync()) using (var stream = await file.OpenReadAsync())
{ {
@ -63,6 +53,17 @@ namespace MapControl
return image; return image;
} }
private static async Task<ImageSource> LoadImageAsync(IHttpContent content)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await LoadImageAsync(stream);
}
}
internal class HttpBufferResponse internal class HttpBufferResponse
{ {
public readonly IBuffer Buffer; public readonly IBuffer Buffer;

View file

@ -12,18 +12,18 @@ namespace MapControl
{ {
public partial class Tile public partial class Tile
{ {
public void SetImage(ImageSource imageSource, bool fadeIn = true) public void SetImage(ImageSource image, bool fadeIn = true)
{ {
Pending = false; Pending = false;
if (fadeIn && FadeDuration > TimeSpan.Zero) if (fadeIn && FadeDuration > TimeSpan.Zero)
{ {
var bitmapImage = imageSource as BitmapImage; var bitmap = image as BitmapImage;
if (bitmapImage?.UriSource != null) if (bitmap?.UriSource != null)
{ {
bitmapImage.ImageOpened += BitmapImageOpened; bitmap.ImageOpened += BitmapImageOpened;
bitmapImage.ImageFailed += BitmapImageFailed; bitmap.ImageFailed += BitmapImageFailed;
} }
else else
{ {
@ -35,25 +35,25 @@ namespace MapControl
Image.Opacity = 1d; Image.Opacity = 1d;
} }
Image.Source = imageSource; Image.Source = image;
} }
private void BitmapImageOpened(object sender, RoutedEventArgs e) private void BitmapImageOpened(object sender, RoutedEventArgs e)
{ {
var bitmapImage = (BitmapImage)sender; var bitmap = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened; bitmap.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed; bitmap.ImageFailed -= BitmapImageFailed;
FadeIn(); FadeIn();
} }
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e) private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{ {
var bitmapImage = (BitmapImage)sender; var bitmap = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened; bitmap.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed; bitmap.ImageFailed -= BitmapImageFailed;
Image.Source = null; Image.Source = null;
} }

View file

@ -27,6 +27,7 @@ namespace MapControl
/// </summary> /// </summary>
public static Caching.IImageCache Cache { get; set; } public static Caching.IImageCache Cache { get; set; }
private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey) private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey)
{ {
var cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false); var cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false);
@ -78,7 +79,13 @@ namespace MapControl
{ {
try try
{ {
tile.SetImage(await loadImageFunc()); var image = await loadImageFunc();
if (image != null)
{
tile.SetImage(image);
}
tcs.SetResult(null); tcs.SetResult(null);
} }
catch (Exception ex) catch (Exception ex)

View file

@ -28,11 +28,6 @@ namespace MapControl
return bitmapImage; return bitmapImage;
} }
public static Task<ImageSource> LoadImageAsync(Stream stream)
{
return Task.Run(() => LoadImage(stream));
}
public static ImageSource LoadImage(byte[] buffer) public static ImageSource LoadImage(byte[] buffer)
{ {
using (var stream = new MemoryStream(buffer)) using (var stream = new MemoryStream(buffer))
@ -41,26 +36,9 @@ namespace MapControl
} }
} }
public static Task<ImageSource> LoadImageAsync(byte[] buffer) public static ImageSource LoadImage(string path)
{
return Task.Run(() => LoadImage(buffer));
}
private static async Task<ImageSource> LoadImageAsync(HttpContent content)
{
using (var stream = new MemoryStream())
{
await content.CopyToAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
return await LoadImageAsync(stream);
}
}
private static ImageSource LoadLocalImage(Uri uri)
{ {
ImageSource image = null; ImageSource image = null;
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
if (File.Exists(path)) if (File.Exists(path))
{ {
@ -73,9 +51,30 @@ namespace MapControl
return image; return image;
} }
private static Task<ImageSource> LoadLocalImageAsync(Uri uri) public static Task<ImageSource> LoadImageAsync(Stream stream)
{ {
return Task.Run(() => LoadLocalImage(uri)); return Task.Run(() => LoadImage(stream));
}
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
{
return Task.Run(() => LoadImage(buffer));
}
public static Task<ImageSource> LoadImageAsync(string path)
{
return Task.Run(() => LoadImage(path));
}
private static async Task<ImageSource> LoadImageAsync(HttpContent content)
{
using (var stream = new MemoryStream())
{
await content.CopyToAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
return LoadImage(stream);
}
} }
internal class HttpStreamResponse internal class HttpStreamResponse
@ -96,7 +95,7 @@ namespace MapControl
try try
{ {
using (var responseMessage = await HttpClient.GetAsync(uri)) using (var responseMessage = await HttpClient.GetAsync(uri).ConfigureAwait(false))
{ {
if (responseMessage.IsSuccessStatusCode) if (responseMessage.IsSuccessStatusCode)
{ {
@ -106,7 +105,7 @@ namespace MapControl
if (ImageAvailable(responseMessage.Headers)) if (ImageAvailable(responseMessage.Headers))
{ {
stream = new MemoryStream(); stream = new MemoryStream();
await responseMessage.Content.CopyToAsync(stream); await responseMessage.Content.CopyToAsync(stream).ConfigureAwait(false);
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
maxAge = responseMessage.Headers.CacheControl?.MaxAge; maxAge = responseMessage.Headers.CacheControl?.MaxAge;

View file

@ -11,18 +11,18 @@ namespace MapControl
{ {
public partial class Tile public partial class Tile
{ {
public void SetImage(ImageSource imageSource, bool fadeIn = true) public void SetImage(ImageSource image, bool fadeIn = true)
{ {
Pending = false; Pending = false;
if (fadeIn && FadeDuration > TimeSpan.Zero) if (fadeIn && FadeDuration > TimeSpan.Zero)
{ {
var bitmapSource = imageSource as BitmapSource; var bitmap = image as BitmapSource;
if (bitmapSource != null && !bitmapSource.IsFrozen && bitmapSource.IsDownloading) if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
{ {
bitmapSource.DownloadCompleted += BitmapDownloadCompleted; bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmapSource.DownloadFailed += BitmapDownloadFailed; bitmap.DownloadFailed += BitmapDownloadFailed;
} }
else else
{ {
@ -34,25 +34,25 @@ namespace MapControl
Image.Opacity = 1d; Image.Opacity = 1d;
} }
Image.Source = imageSource; Image.Source = image;
} }
private void BitmapDownloadCompleted(object sender, EventArgs e) private void BitmapDownloadCompleted(object sender, EventArgs e)
{ {
var bitmapSource = (BitmapSource)sender; var bitmap = (BitmapSource)sender;
bitmapSource.DownloadCompleted -= BitmapDownloadCompleted; bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmapSource.DownloadFailed -= BitmapDownloadFailed; bitmap.DownloadFailed -= BitmapDownloadFailed;
FadeIn(); FadeIn();
} }
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e) private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
{ {
var bitmapSource = (BitmapSource)sender; var bitmap = (BitmapSource)sender;
bitmapSource.DownloadCompleted -= BitmapDownloadCompleted; bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmapSource.DownloadFailed -= BitmapDownloadFailed; bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.Source = null; Image.Source = null;
} }

View file

@ -27,8 +27,10 @@ namespace MapControl
/// </summary> /// </summary>
public static ObjectCache Cache { get; set; } = MemoryCache.Default; public static ObjectCache Cache { get; set; } = MemoryCache.Default;
private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey) private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey)
{ {
ImageSource image = null;
DateTime expiration; DateTime expiration;
var cacheBuffer = GetCachedImage(cacheKey, out expiration); var cacheBuffer = GetCachedImage(cacheKey, out expiration);
@ -44,7 +46,7 @@ namespace MapControl
{ {
using (var stream = response.Stream) using (var stream = response.Stream)
{ {
LoadTileImage(tile, stream); image = ImageLoader.LoadImage(stream);
SetCachedImage(cacheKey, stream, GetExpiration(response.MaxAge)); SetCachedImage(cacheKey, stream, GetExpiration(response.MaxAge));
} }
} }
@ -53,26 +55,28 @@ namespace MapControl
if (cacheBuffer != null) // cached image not expired or download failed if (cacheBuffer != null) // cached image not expired or download failed
{ {
using (var stream = new MemoryStream(cacheBuffer)) image = ImageLoader.LoadImage(cacheBuffer);
{ }
LoadTileImage(tile, stream);
} if (image != null)
{
SetTileImage(tile, image);
} }
} }
private async Task LoadTileImageAsync(Tile tile, TileSource tileSource) private async Task LoadTileImageAsync(Tile tile, TileSource tileSource)
{ {
SetTileImage(tile, await tileSource.LoadImageAsync(tile.XIndex, tile.Y, tile.ZoomLevel).ConfigureAwait(false)); var image = await tileSource.LoadImageAsync(tile.XIndex, tile.Y, tile.ZoomLevel).ConfigureAwait(false);
if (image != null)
{
SetTileImage(tile, image);
}
} }
private void LoadTileImage(Tile tile, Stream stream) private void SetTileImage(Tile tile, ImageSource image)
{ {
SetTileImage(tile, ImageLoader.LoadImage(stream)); tile.Image.Dispatcher.InvokeAsync(() => tile.SetImage(image));
}
private void SetTileImage(Tile tile, ImageSource imageSource)
{
tile.Image.Dispatcher.InvokeAsync(() => tile.SetImage(imageSource));
} }
private static byte[] GetCachedImage(string cacheKey, out DateTime expiration) private static byte[] GetCachedImage(string cacheKey, out DateTime expiration)

View file

@ -2,6 +2,7 @@
// © 2019 Clemens Fischer // © 2019 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using MapControl.Projections;
using System; using System;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -19,7 +20,6 @@ using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
#endif #endif
using MapControl.Projections;
namespace MapControl.Images namespace MapControl.Images
{ {
@ -79,24 +79,11 @@ namespace MapControl.Images
public static async Task<WorldFileImage> ReadWorldFileImage(string imagePath, string worldFilePath, string projFilePath = null) public static async Task<WorldFileImage> ReadWorldFileImage(string imagePath, string worldFilePath, string projFilePath = null)
{ {
BitmapSource bitmap; var bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(imagePath);
using (var stream = File.OpenRead(imagePath))
{
#if WINDOWS_UWP
bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(stream.AsRandomAccessStream());
#else
bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(stream);
#endif
}
var transform = ReadWorldFile(worldFilePath); var transform = ReadWorldFile(worldFilePath);
MapProjection projection = null; var projection = (projFilePath != null && File.Exists(projFilePath))
? new GeoApiProjection { WKT = File.ReadAllText(projFilePath) }
if (projFilePath != null && File.Exists(projFilePath)) : null;
{
projection = new GeoApiProjection { WKT = File.ReadAllText(projFilePath) };
}
return new WorldFileImage(bitmap, transform, projection); return new WorldFileImage(bitmap, transform, projection);
} }
@ -124,16 +111,18 @@ namespace MapControl.Images
throw new ArgumentException("World file \"" + path + "\"not found."); throw new ArgumentException("World file \"" + path + "\"not found.");
} }
var parameters = File.ReadLines(path).Take(6).Select((line, i) => var parameters = File.ReadLines(path)
{ .Take(6)
double p; .Select((line, i) =>
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
{ {
throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\"."); double p;
} if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
return p; {
}) throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\".");
.ToList(); }
return p;
})
.ToList();
if (parameters.Count != 6) if (parameters.Count != 6)
{ {

View file

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
@ -21,28 +20,21 @@ namespace MapControl.Images
UseLayoutRounding = false; UseLayoutRounding = false;
} }
private async Task<List<ImageOverlay>> ReadGroundOverlaysFromFile(string docFile) private async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromFile(string docFile)
{ {
if (!Path.IsPathRooted(docFile)) docFile = Path.GetFullPath(docFile);
var file = await StorageFile.GetFileFromPathAsync(docFile);
var kmlDocument = new XmlDocument();
using (var stream = await file.OpenReadAsync())
{ {
docFile = Path.Combine(Directory.GetCurrentDirectory(), docFile); kmlDocument.Load(stream.AsStreamForRead());
} }
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
var docUri = new Uri(docFile); var docUri = new Uri(docFile);
var imageOverlays = await Task.Run(async () =>
{
var file = await StorageFile.GetFileFromPathAsync(docFile);
var kmlDocument = new XmlDocument();
using (var stream = await file.OpenReadAsync())
{
kmlDocument.Load(stream.AsStreamForRead());
}
return ReadGroundOverlays(kmlDocument).ToList();
});
foreach (var imageOverlay in imageOverlays) foreach (var imageOverlay in imageOverlays)
{ {
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath)); imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath));
@ -51,7 +43,7 @@ namespace MapControl.Images
return imageOverlays; return imageOverlays;
} }
private async Task<List<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile) private async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile)
{ {
using (var archive = ZipFile.OpenRead(archiveFile)) using (var archive = ZipFile.OpenRead(archiveFile))
{ {
@ -63,17 +55,14 @@ namespace MapControl.Images
throw new ArgumentException("No KML entry found in " + archiveFile); throw new ArgumentException("No KML entry found in " + archiveFile);
} }
var imageOverlays = await Task.Run(() => var kmlDocument = new XmlDocument();
using (var docStream = docEntry.Open())
{ {
var kmlDocument = new XmlDocument(); kmlDocument.Load(docStream);
}
using (var docStream = docEntry.Open()) var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
{
kmlDocument.Load(docStream);
}
return ReadGroundOverlays(kmlDocument).ToList();
});
foreach (var imageOverlay in imageOverlays) foreach (var imageOverlay in imageOverlays)
{ {

View file

@ -14,23 +14,16 @@ namespace MapControl.Images
{ {
public partial class GroundOverlayPanel public partial class GroundOverlayPanel
{ {
private async Task<List<ImageOverlay>> ReadGroundOverlaysFromFile(string docFile) private async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromFile(string docFile)
{ {
if (!Path.IsPathRooted(docFile)) docFile = Path.GetFullPath(docFile);
{
docFile = Path.Combine(Directory.GetCurrentDirectory(), docFile);
}
var kmlDocument = new XmlDocument();
kmlDocument.Load(docFile);
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
var docUri = new Uri(docFile); var docUri = new Uri(docFile);
var imageOverlays = await Task.Run(() =>
{
var kmlDocument = new XmlDocument();
kmlDocument.Load(docUri.ToString());
return ReadGroundOverlays(kmlDocument).ToList();
});
foreach (var imageOverlay in imageOverlays) foreach (var imageOverlay in imageOverlays)
{ {
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath)); imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath));
@ -39,48 +32,45 @@ namespace MapControl.Images
return imageOverlays; return imageOverlays;
} }
private Task<List<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile) private async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile)
{ {
return Task.Run(() => using (var archive = ZipFile.OpenRead(archiveFile))
{ {
using (var archive = ZipFile.OpenRead(archiveFile)) var docEntry = archive.GetEntry("doc.kml")
?? archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml"));
if (docEntry == null)
{ {
var docEntry = archive.GetEntry("doc.kml") throw new ArgumentException("No KML entry found in " + archiveFile);
?? archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml")); }
if (docEntry == null) var kmlDocument = new XmlDocument();
using (var docStream = docEntry.Open())
{
kmlDocument.Load(docStream);
}
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
foreach (var imageOverlay in imageOverlays)
{
var imageEntry = archive.GetEntry(imageOverlay.ImagePath);
if (imageEntry != null)
{ {
throw new ArgumentException("No KML entry found in " + archiveFile); using (var zipStream = imageEntry.Open())
} using (var memoryStream = new MemoryStream())
var kmlDocument = new XmlDocument();
using (var docStream = docEntry.Open())
{
kmlDocument.Load(docStream);
}
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
foreach (var imageOverlay in imageOverlays)
{
var imageEntry = archive.GetEntry(imageOverlay.ImagePath);
if (imageEntry != null)
{ {
using (var zipStream = imageEntry.Open()) await zipStream.CopyToAsync(memoryStream);
using (var memoryStream = new MemoryStream()) memoryStream.Position = 0;
{ imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(memoryStream);
zipStream.CopyTo(memoryStream);
memoryStream.Position = 0;
imageOverlay.ImageSource = ImageLoader.LoadImage(memoryStream);
}
} }
} }
return imageOverlays;
} }
});
return imageOverlays;
}
} }
} }
} }