mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.12.2 Fixed local file handling for UWP. All relative paths relative to ms-appx:
This commit is contained in:
parent
26bf0b5005
commit
c28387f87c
14 changed files with 172 additions and 192 deletions
|
|
@ -2,6 +2,7 @@
|
|||
// © 2019 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using MapControl.Projections;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
|
@ -19,7 +20,6 @@ using System.Windows.Controls;
|
|||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
using MapControl.Projections;
|
||||
|
||||
namespace MapControl.Images
|
||||
{
|
||||
|
|
@ -79,24 +79,11 @@ namespace MapControl.Images
|
|||
|
||||
public static async Task<WorldFileImage> ReadWorldFileImage(string imagePath, string worldFilePath, string projFilePath = null)
|
||||
{
|
||||
BitmapSource bitmap;
|
||||
|
||||
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 bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(imagePath);
|
||||
var transform = ReadWorldFile(worldFilePath);
|
||||
MapProjection projection = null;
|
||||
|
||||
if (projFilePath != null && File.Exists(projFilePath))
|
||||
{
|
||||
projection = new GeoApiProjection { WKT = File.ReadAllText(projFilePath) };
|
||||
}
|
||||
var projection = (projFilePath != null && File.Exists(projFilePath))
|
||||
? new GeoApiProjection { WKT = File.ReadAllText(projFilePath) }
|
||||
: null;
|
||||
|
||||
return new WorldFileImage(bitmap, transform, projection);
|
||||
}
|
||||
|
|
@ -124,16 +111,18 @@ namespace MapControl.Images
|
|||
throw new ArgumentException("World file \"" + path + "\"not found.");
|
||||
}
|
||||
|
||||
var parameters = File.ReadLines(path).Take(6).Select((line, i) =>
|
||||
{
|
||||
double p;
|
||||
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
|
||||
var parameters = File.ReadLines(path)
|
||||
.Take(6)
|
||||
.Select((line, i) =>
|
||||
{
|
||||
throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\".");
|
||||
}
|
||||
return p;
|
||||
})
|
||||
.ToList();
|
||||
double p;
|
||||
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
|
||||
{
|
||||
throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\".");
|
||||
}
|
||||
return p;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (parameters.Count != 6)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
|
|
@ -21,28 +20,21 @@ namespace MapControl.Images
|
|||
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 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)
|
||||
{
|
||||
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath));
|
||||
|
|
@ -51,7 +43,7 @@ namespace MapControl.Images
|
|||
return imageOverlays;
|
||||
}
|
||||
|
||||
private async Task<List<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile)
|
||||
private async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromArchive(string archiveFile)
|
||||
{
|
||||
using (var archive = ZipFile.OpenRead(archiveFile))
|
||||
{
|
||||
|
|
@ -63,17 +55,14 @@ namespace MapControl.Images
|
|||
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())
|
||||
{
|
||||
kmlDocument.Load(docStream);
|
||||
}
|
||||
|
||||
return ReadGroundOverlays(kmlDocument).ToList();
|
||||
});
|
||||
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
|
||||
|
||||
foreach (var imageOverlay in imageOverlays)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,23 +14,16 @@ namespace MapControl.Images
|
|||
{
|
||||
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.Combine(Directory.GetCurrentDirectory(), docFile);
|
||||
}
|
||||
docFile = Path.GetFullPath(docFile);
|
||||
|
||||
var kmlDocument = new XmlDocument();
|
||||
kmlDocument.Load(docFile);
|
||||
|
||||
var imageOverlays = ReadGroundOverlays(kmlDocument).ToList();
|
||||
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)
|
||||
{
|
||||
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(new Uri(docUri, imageOverlay.ImagePath));
|
||||
|
|
@ -39,48 +32,45 @@ namespace MapControl.Images
|
|||
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")
|
||||
?? archive.Entries.FirstOrDefault(e => e.Name.EndsWith(".kml"));
|
||||
throw new ArgumentException("No KML entry found in " + archiveFile);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
using (var zipStream = imageEntry.Open())
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
zipStream.CopyTo(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
imageOverlay.ImageSource = ImageLoader.LoadImage(memoryStream);
|
||||
}
|
||||
await zipStream.CopyToAsync(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
imageOverlay.ImageSource = await ImageLoader.LoadImageAsync(memoryStream);
|
||||
}
|
||||
}
|
||||
|
||||
return imageOverlays;
|
||||
}
|
||||
});
|
||||
|
||||
return imageOverlays;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue