2018-12-09 17:14:32 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// <20> 2019 Clemens Fischer
|
2018-12-09 17:14:32 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2019-07-16 20:13:52 +02:00
|
|
|
|
using System;
|
2018-12-09 17:14:32 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2019-07-16 20:13:52 +02:00
|
|
|
|
using System.IO.Compression;
|
2018-12-09 17:14:32 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl.Images
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class GroundOverlayPanel
|
|
|
|
|
|
{
|
2019-07-13 19:53:03 +02:00
|
|
|
|
private static Task<List<ImageOverlay>> ReadGroundOverlaysFromFileAsync(string docFile)
|
2019-06-17 18:09:28 +02:00
|
|
|
|
{
|
2019-07-13 19:53:03 +02:00
|
|
|
|
return Task.Run(() =>
|
2018-12-09 17:14:32 +01:00
|
|
|
|
{
|
2019-07-13 19:53:03 +02:00
|
|
|
|
docFile = Path.GetFullPath(docFile);
|
2018-12-09 17:14:32 +01:00
|
|
|
|
|
2019-06-15 01:39:07 +02:00
|
|
|
|
var kmlDocument = new XmlDocument();
|
2019-07-13 19:53:03 +02:00
|
|
|
|
kmlDocument.Load(docFile);
|
2018-12-09 17:14:32 +01:00
|
|
|
|
|
2019-06-15 01:39:07 +02:00
|
|
|
|
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
|
2019-07-13 19:53:03 +02:00
|
|
|
|
var docDir = Path.GetDirectoryName(docFile);
|
2018-12-09 17:14:32 +01:00
|
|
|
|
|
2019-06-15 01:39:07 +02:00
|
|
|
|
foreach (var imageOverlay in imageOverlays)
|
|
|
|
|
|
{
|
2019-07-13 19:53:03 +02:00
|
|
|
|
imageOverlay.ImageSource = ImageLoader.LoadImage(Path.Combine(docDir, imageOverlay.ImagePath));
|
2018-12-09 17:14:32 +01:00
|
|
|
|
}
|
2019-06-15 01:39:07 +02:00
|
|
|
|
|
|
|
|
|
|
return imageOverlays;
|
2019-07-13 19:53:03 +02:00
|
|
|
|
});
|
2018-12-09 17:14:32 +01:00
|
|
|
|
}
|
2019-07-16 20:13:52 +02:00
|
|
|
|
|
|
|
|
|
|
private static Task<List<ImageOverlay>> ReadGroundOverlaysFromArchiveAsync(string archiveFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
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 = 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())
|
|
|
|
|
|
{
|
|
|
|
|
|
zipStream.CopyTo(memoryStream);
|
|
|
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
imageOverlay.ImageSource = ImageLoader.LoadImage(memoryStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return imageOverlays;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2018-12-09 17:14:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|