mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
GroundOverlay without Task.Run
This commit is contained in:
parent
7846f4f685
commit
a3e7ab0404
|
|
@ -21,8 +21,11 @@ dotnet_diagnostic.IDE0090.severity = silent
|
||||||
# IDE0290: Use primary constructor
|
# IDE0290: Use primary constructor
|
||||||
dotnet_diagnostic.IDE0290.severity = silent
|
dotnet_diagnostic.IDE0290.severity = silent
|
||||||
|
|
||||||
# IDE0300: Use collection expression for array
|
# IDE030X: Use collection expression
|
||||||
dotnet_diagnostic.IDE0300.severity = silent
|
dotnet_diagnostic.IDE0300.severity = silent
|
||||||
|
|
||||||
# IDE0301: Use collection expression for empty
|
|
||||||
dotnet_diagnostic.IDE0301.severity = silent
|
dotnet_diagnostic.IDE0301.severity = silent
|
||||||
|
dotnet_diagnostic.IDE0302.severity = silent
|
||||||
|
dotnet_diagnostic.IDE0303.severity = silent
|
||||||
|
dotnet_diagnostic.IDE0304.severity = silent
|
||||||
|
dotnet_diagnostic.IDE0305.severity = silent
|
||||||
|
dotnet_diagnostic.IDE0306.severity = silent
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using System.Threading;
|
|
||||||
#if WPF
|
#if WPF
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
@ -115,22 +114,15 @@ namespace MapControl
|
||||||
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")) ??
|
||||||
|
|
||||||
if (docEntry == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"No KML entry found in {archiveFilePath}.");
|
throw new ArgumentException($"No KML entry found in {archiveFilePath}.");
|
||||||
}
|
|
||||||
|
|
||||||
var imageOverlays = await Task.Run(() =>
|
List<ImageOverlay> imageOverlays;
|
||||||
{
|
|
||||||
using (var docStream = docEntry.Open())
|
using (var docStream = docEntry.Open())
|
||||||
{
|
{
|
||||||
var kmlDocument = XDocument.Load(docStream);
|
imageOverlays = await ReadGroundOverlays(docStream);
|
||||||
|
|
||||||
return ReadGroundOverlays(kmlDocument.Root).ToList();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var imageOverlay in imageOverlays)
|
foreach (var imageOverlay in imageOverlays)
|
||||||
{
|
{
|
||||||
|
|
@ -157,14 +149,14 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
docFilePath = FilePath.GetFullPath(docFilePath);
|
docFilePath = FilePath.GetFullPath(docFilePath);
|
||||||
|
|
||||||
var docUri = new Uri(docFilePath);
|
List<ImageOverlay> imageOverlays;
|
||||||
|
|
||||||
var imageOverlays = await Task.Run(() =>
|
using (var docStream = File.OpenRead(docFilePath))
|
||||||
{
|
{
|
||||||
var kmlDocument = XDocument.Load(docFilePath);
|
imageOverlays = await ReadGroundOverlays(docStream);
|
||||||
|
}
|
||||||
|
|
||||||
return ReadGroundOverlays(kmlDocument.Root).ToList();
|
var docUri = new Uri(docFilePath);
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var imageOverlay in imageOverlays)
|
foreach (var imageOverlay in imageOverlays)
|
||||||
{
|
{
|
||||||
|
|
@ -174,10 +166,17 @@ namespace MapControl
|
||||||
return imageOverlays;
|
return imageOverlays;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<ImageOverlay> ReadGroundOverlays(XElement kmlElement)
|
private static async Task<List<ImageOverlay>> ReadGroundOverlays(Stream docStream)
|
||||||
{
|
{
|
||||||
var ns = kmlElement.Name.Namespace;
|
#if NETFRAMEWORK
|
||||||
var docElement = kmlElement.Element(ns + "Document") ?? kmlElement;
|
var document = await Task.FromResult(XDocument.Load(docStream, LoadOptions.None));
|
||||||
|
#else
|
||||||
|
var document = await XDocument.LoadAsync(docStream, LoadOptions.None, System.Threading.CancellationToken.None);
|
||||||
|
#endif
|
||||||
|
var rootElement = document.Root;
|
||||||
|
var ns = rootElement.Name.Namespace;
|
||||||
|
var docElement = rootElement.Element(ns + "Document") ?? rootElement;
|
||||||
|
var imageOverlays = new List<ImageOverlay>();
|
||||||
|
|
||||||
foreach (var folderElement in docElement.Elements(ns + "Folder"))
|
foreach (var folderElement in docElement.Elements(ns + "Folder"))
|
||||||
{
|
{
|
||||||
|
|
@ -194,10 +193,12 @@ namespace MapControl
|
||||||
|
|
||||||
if (latLonBox != null && imagePath != null)
|
if (latLonBox != null && imagePath != null)
|
||||||
{
|
{
|
||||||
yield return new ImageOverlay(imagePath, latLonBox, zIndex);
|
imageOverlays.Add(new ImageOverlay(imagePath, latLonBox, zIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return imageOverlays;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LatLonBox ReadLatLonBox(XElement latLonBoxElement)
|
private static LatLonBox ReadLatLonBox(XElement latLonBoxElement)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue