mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Update GroundOverlay.cs
This commit is contained in:
parent
6a2177b3d4
commit
9a3da275c0
|
|
@ -129,43 +129,39 @@ namespace MapControl
|
||||||
|
|
||||||
private static async Task<List<ImageOverlay>> LoadImageOverlaysFromArchive(string archiveFilePath)
|
private static async Task<List<ImageOverlay>> LoadImageOverlaysFromArchive(string archiveFilePath)
|
||||||
{
|
{
|
||||||
List<ImageOverlay> imageOverlays;
|
|
||||||
|
|
||||||
using (var archive = ZipFile.OpenRead(archiveFilePath))
|
using (var archive = ZipFile.OpenRead(archiveFilePath))
|
||||||
{
|
{
|
||||||
var docEntry = archive.GetEntry("doc.kml") ??
|
var docEntry = archive.GetEntry("doc.kml") ??
|
||||||
archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml")) ??
|
archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml")) ??
|
||||||
throw new ArgumentException($"No KML entry found in {archiveFilePath}.");
|
throw new ArgumentException($"No KML entry found in {archiveFilePath}.");
|
||||||
|
XDocument document;
|
||||||
|
|
||||||
using (var docStream = docEntry.Open())
|
using (var docStream = docEntry.Open())
|
||||||
{
|
{
|
||||||
imageOverlays = await ReadImageOverlays(docStream);
|
document = await LoadXDocument(docStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
await LoadImageOverlays(imageOverlays, imageOverlay => imageOverlay.LoadImage(archive));
|
return await LoadImageOverlays(document, imageOverlay => imageOverlay.LoadImage(archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageOverlays;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<List<ImageOverlay>> LoadImageOverlaysFromFile(string docFilePath)
|
private static async Task<List<ImageOverlay>> LoadImageOverlaysFromFile(string docFilePath)
|
||||||
{
|
{
|
||||||
List<ImageOverlay> imageOverlays;
|
|
||||||
|
|
||||||
var docUri = new Uri(FilePath.GetFullPath(docFilePath));
|
var docUri = new Uri(FilePath.GetFullPath(docFilePath));
|
||||||
|
XDocument document;
|
||||||
|
|
||||||
using (var docStream = File.OpenRead(docUri.AbsolutePath))
|
using (var docStream = File.OpenRead(docUri.AbsolutePath))
|
||||||
{
|
{
|
||||||
imageOverlays = await ReadImageOverlays(docStream);
|
document = await LoadXDocument(docStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
await LoadImageOverlays(imageOverlays, imageOverlay => imageOverlay.LoadImage(docUri));
|
return await LoadImageOverlays(document, imageOverlay => imageOverlay.LoadImage(docUri));
|
||||||
|
|
||||||
return imageOverlays;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Task LoadImageOverlays(List<ImageOverlay> imageOverlays, Func<ImageOverlay, Task> loadFunc)
|
private static async Task<List<ImageOverlay>> LoadImageOverlays(XDocument document, Func<ImageOverlay, Task> loadFunc)
|
||||||
{
|
{
|
||||||
|
var imageOverlays = ReadImageOverlays(document);
|
||||||
|
|
||||||
var semaphore = new SemaphoreSlim(MaxLoadTasks);
|
var semaphore = new SemaphoreSlim(MaxLoadTasks);
|
||||||
|
|
||||||
var tasks = imageOverlays.Select(async imageOverlay =>
|
var tasks = imageOverlays.Select(async imageOverlay =>
|
||||||
|
|
@ -181,16 +177,13 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return Task.WhenAll(tasks);
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
|
return imageOverlays;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<List<ImageOverlay>> ReadImageOverlays(Stream docStream)
|
private static List<ImageOverlay> ReadImageOverlays(XDocument document)
|
||||||
{
|
{
|
||||||
#if NETFRAMEWORK
|
|
||||||
var document = await Task.Run(() => XDocument.Load(docStream, LoadOptions.None));
|
|
||||||
#else
|
|
||||||
var document = await XDocument.LoadAsync(docStream, LoadOptions.None, System.Threading.CancellationToken.None);
|
|
||||||
#endif
|
|
||||||
var rootElement = document.Root;
|
var rootElement = document.Root;
|
||||||
var ns = rootElement.Name.Namespace;
|
var ns = rootElement.Name.Namespace;
|
||||||
var docElement = rootElement.Element(ns + "Document") ?? rootElement;
|
var docElement = rootElement.Element(ns + "Document") ?? rootElement;
|
||||||
|
|
@ -267,5 +260,14 @@ namespace MapControl
|
||||||
|
|
||||||
return new LatLonBox(south, west, north, east, rotation);
|
return new LatLonBox(south, west, north, east, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Task<XDocument> LoadXDocument(Stream docStream)
|
||||||
|
{
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
return Task.Run(() => XDocument.Load(docStream, LoadOptions.None));
|
||||||
|
#else
|
||||||
|
return XDocument.LoadAsync(docStream, LoadOptions.None, System.Threading.CancellationToken.None);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue