mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Update GeoImage.cs
This commit is contained in:
parent
4c48f823bd
commit
84cd6e2f9a
|
|
@ -72,68 +72,68 @@ namespace MapControl
|
||||||
|
|
||||||
private async Task ReadGeoImageAsync(string sourcePath)
|
private async Task ReadGeoImageAsync(string sourcePath)
|
||||||
{
|
{
|
||||||
GeoBitmap geoBitmap = null;
|
GeoBitmap geoBitmap = null;
|
||||||
var ext = Path.GetExtension(sourcePath);
|
var ext = Path.GetExtension(sourcePath);
|
||||||
|
|
||||||
if (ext.Length >= 4)
|
if (ext.Length >= 4)
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(sourcePath);
|
||||||
|
var file = Path.GetFileNameWithoutExtension(sourcePath);
|
||||||
|
var worldFilePath = Path.Combine(dir, file + ext.Remove(2, 1) + "w");
|
||||||
|
|
||||||
|
if (File.Exists(worldFilePath))
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(sourcePath);
|
geoBitmap = await ReadWorldFileImageAsync(sourcePath, worldFilePath);
|
||||||
var file = Path.GetFileNameWithoutExtension(sourcePath);
|
|
||||||
var worldFilePath = Path.Combine(dir, file + ext.Remove(2, 1) + "w");
|
|
||||||
|
|
||||||
if (File.Exists(worldFilePath))
|
|
||||||
{
|
|
||||||
geoBitmap = await ReadWorldFileImageAsync(sourcePath, worldFilePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (geoBitmap == null)
|
if (geoBitmap == null)
|
||||||
{
|
{
|
||||||
#if AVALONIA
|
#if AVALONIA
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
geoBitmap = await ReadGeoTiffAsync(sourcePath);
|
geoBitmap = await ReadGeoTiffAsync(sourcePath);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
var image = new Image
|
var image = new Image
|
||||||
{
|
{
|
||||||
Source = geoBitmap.Bitmap,
|
Source = geoBitmap.Bitmap,
|
||||||
Stretch = Stretch.Fill,
|
Stretch = Stretch.Fill,
|
||||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||||
VerticalAlignment = VerticalAlignment.Stretch
|
VerticalAlignment = VerticalAlignment.Stretch
|
||||||
};
|
};
|
||||||
|
|
||||||
var transform = geoBitmap.Transform;
|
var transform = geoBitmap.Transform;
|
||||||
|
|
||||||
if (transform.M12 != 0 && transform.M21 != 0)
|
if (transform.M12 != 0 && transform.M21 != 0)
|
||||||
{
|
{
|
||||||
var rotation = (Math.Atan2(transform.M12, transform.M11) + Math.Atan2(transform.M21, -transform.M22)) * 90d / Math.PI;
|
var rotation = (Math.Atan2(transform.M12, transform.M11) + Math.Atan2(transform.M21, -transform.M22)) * 90d / Math.PI;
|
||||||
|
|
||||||
image.RenderTransform = new RotateTransform { Angle = -rotation };
|
image.RenderTransform = new RotateTransform { Angle = -rotation };
|
||||||
|
|
||||||
// Calculate effective unrotated transform.
|
// Calculate effective unrotated transform.
|
||||||
//
|
//
|
||||||
geoBitmap.Transform = new Matrix(
|
geoBitmap.Transform = new Matrix(
|
||||||
Math.Sqrt(transform.M11 * transform.M11 + transform.M12 * transform.M12), 0d, 0d,
|
Math.Sqrt(transform.M11 * transform.M11 + transform.M12 * transform.M12), 0d, 0d,
|
||||||
-Math.Sqrt(transform.M22 * transform.M22 + transform.M21 * transform.M21), 0d, 0d);
|
-Math.Sqrt(transform.M22 * transform.M22 + transform.M21 * transform.M21), 0d, 0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if AVALONIA
|
#if AVALONIA
|
||||||
var size = new Point(geoBitmap.Bitmap.PixelSize.Width, geoBitmap.Bitmap.PixelSize.Height);
|
var size = new Point(geoBitmap.Bitmap.PixelSize.Width, geoBitmap.Bitmap.PixelSize.Height);
|
||||||
#else
|
#else
|
||||||
var size = new Point(geoBitmap.Bitmap.PixelWidth, geoBitmap.Bitmap.PixelHeight);
|
var size = new Point(geoBitmap.Bitmap.PixelWidth, geoBitmap.Bitmap.PixelHeight);
|
||||||
#endif
|
#endif
|
||||||
var rect = new Rect(transform.Transform(new Point()), transform.Transform(size));
|
var rect = new Rect(transform.Transform(new Point()), transform.Transform(size));
|
||||||
|
|
||||||
var boundingBox = geoBitmap.Projection != null
|
var boundingBox = geoBitmap.Projection != null
|
||||||
? geoBitmap.Projection.MapToBoundingBox(rect)
|
? geoBitmap.Projection.MapToBoundingBox(rect)
|
||||||
: new BoundingBox(rect.Y, rect.X, rect.Y + rect.Height, rect.X + rect.Width);
|
: new BoundingBox(rect.Y, rect.X, rect.Y + rect.Height, rect.X + rect.Width);
|
||||||
|
|
||||||
MapPanel.SetBoundingBox(this, boundingBox);
|
MapPanel.SetBoundingBox(this, boundingBox);
|
||||||
|
|
||||||
Children.Clear();
|
Children.Clear();
|
||||||
Children.Add(image);
|
Children.Add(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<GeoBitmap> ReadWorldFileImageAsync(string sourcePath, string worldFilePath)
|
private static async Task<GeoBitmap> ReadWorldFileImageAsync(string sourcePath, string worldFilePath)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue