mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.12.2 Improved ImageLoader/TileImageLoader
This commit is contained in:
parent
4a7e384152
commit
fefc4e3294
9 changed files with 102 additions and 171 deletions
|
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
|
@ -119,7 +120,49 @@ namespace MapControl.Images
|
|||
}
|
||||
}
|
||||
|
||||
private IEnumerable<ImageOverlay> ReadGroundOverlays(XmlDocument kmlDocument)
|
||||
private static async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromArchiveAsync(string archiveFile)
|
||||
{
|
||||
using (var archive = ZipFile.OpenRead(archiveFile))
|
||||
{
|
||||
var docEntry = archive.GetEntry("doc.kml")
|
||||
?? archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml"));
|
||||
|
||||
if (docEntry == null)
|
||||
{
|
||||
throw new ArgumentException("No KML entry found in " + archiveFile);
|
||||
}
|
||||
|
||||
var kmlDocument = new XmlDocument();
|
||||
|
||||
using (var docStream = docEntry.Open())
|
||||
{
|
||||
kmlDocument.Load(docStream);
|
||||
}
|
||||
|
||||
var imageOverlays = await Task.Run(() => ReadGroundOverlays(kmlDocument).ToList());
|
||||
|
||||
foreach (var imageOverlay in imageOverlays)
|
||||
{
|
||||
var imageEntry = archive.GetEntry(imageOverlay.ImagePath);
|
||||
|
||||
if (imageEntry != null)
|
||||
{
|
||||
using (var zipStream = imageEntry.Open())
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
await zipStream.CopyToAsync(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(memoryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageOverlays;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<ImageOverlay> ReadGroundOverlays(XmlDocument kmlDocument)
|
||||
{
|
||||
foreach (XmlElement groundOverlayElement in kmlDocument.GetElementsByTagName("GroundOverlay"))
|
||||
{
|
||||
|
|
@ -150,7 +193,7 @@ namespace MapControl.Images
|
|||
}
|
||||
}
|
||||
|
||||
private string ReadImagePath(XmlElement element)
|
||||
private static string ReadImagePath(XmlElement element)
|
||||
{
|
||||
string href = null;
|
||||
|
||||
|
|
@ -167,7 +210,7 @@ namespace MapControl.Images
|
|||
return href;
|
||||
}
|
||||
|
||||
private LatLonBox ReadLatLonBox(XmlElement element)
|
||||
private static LatLonBox ReadLatLonBox(XmlElement element)
|
||||
{
|
||||
double north = double.NaN;
|
||||
double south = double.NaN;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue