From b22ee9a60f8fc49036b867b9d03c78961f1f9312 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Sat, 14 Sep 2024 13:26:57 +0200 Subject: [PATCH] GeoImage and GroundOverlay implementation --- MapControl/Avalonia/GeoImage.Avalonia.cs | 7 ------- MapControl/Shared/GeoImage.cs | 25 +++++++++++++++++------- MapControl/Shared/GroundOverlay.cs | 14 ++++++------- MapControl/WPF/GeoImage.WPF.cs | 8 -------- MapControl/WinUI/GeoImage.WinUI.cs | 9 --------- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/MapControl/Avalonia/GeoImage.Avalonia.cs b/MapControl/Avalonia/GeoImage.Avalonia.cs index d166ad8b..288a095b 100644 --- a/MapControl/Avalonia/GeoImage.Avalonia.cs +++ b/MapControl/Avalonia/GeoImage.Avalonia.cs @@ -9,13 +9,6 @@ namespace MapControl { public static partial class GeoImage { - private partial class GeoBitmap - { - public Point BitmapSize => new(BitmapSource.PixelSize.Width, BitmapSource.PixelSize.Height); - - public ImageBrush ImageBrush => new(BitmapSource); - } - private static Task LoadGeoTiffAsync(string sourcePath) { throw new InvalidOperationException("GeoTIFF is not supported."); diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs index 503d18b0..aadfe174 100644 --- a/MapControl/Shared/GeoImage.cs +++ b/MapControl/Shared/GeoImage.cs @@ -33,15 +33,18 @@ namespace MapControl { public static partial class GeoImage { - private partial class GeoBitmap + private class GeoBitmap { public GeoBitmap(BitmapSource bitmapSource, Matrix transform, MapProjection projection) { - BitmapSource = bitmapSource; - var p1 = transform.Transform(new Point()); - var p2 = transform.Transform(BitmapSize); - + var p2 = transform.Transform(new Point( +#if AVALONIA + bitmapSource.PixelSize.Width, bitmapSource.PixelSize.Height)); +#else + bitmapSource.PixelWidth, bitmapSource.PixelHeight)); +#endif + BitmapSource = bitmapSource; LatLonBox = projection != null ? new LatLonBox(projection.MapToBoundingBox(new Rect(p1, p2))) : new LatLonBox(p1.Y, p1.X, p2.Y, p2.X); @@ -93,13 +96,21 @@ namespace MapControl if (element is Image image) { - image.Source = geoBitmap.BitmapSource; image.Stretch = Stretch.Fill; + image.Source = geoBitmap.BitmapSource; } else if (element is Shape shape) { - shape.Fill = geoBitmap.ImageBrush; shape.Stretch = Stretch.Fill; + shape.Fill = new ImageBrush + { + Stretch = Stretch.Fill, +#if AVALONIA + Source = geoBitmap.BitmapSource +#else + ImageSource = geoBitmap.BitmapSource +#endif + }; } MapPanel.SetBoundingBox(element, geoBitmap.LatLonBox); diff --git a/MapControl/Shared/GroundOverlay.cs b/MapControl/Shared/GroundOverlay.cs index 8ca8930e..18288b5b 100644 --- a/MapControl/Shared/GroundOverlay.cs +++ b/MapControl/Shared/GroundOverlay.cs @@ -31,15 +31,15 @@ namespace MapControl { private class ImageOverlay { - public ImageOverlay(BoundingBox boundingBox, string imagePath, int zIndex) + public ImageOverlay(string imagePath, BoundingBox boundingBox, int zIndex) { - BoundingBox = boundingBox; ImagePath = imagePath; + BoundingBox = boundingBox; ZIndex = zIndex; } - public BoundingBox BoundingBox { get; } public string ImagePath { get; } + public BoundingBox BoundingBox { get; } public int ZIndex { get; } public ImageSource ImageSource { get; set; } } @@ -180,18 +180,18 @@ namespace MapControl { foreach (var groundOverlayElement in folderElement.Elements(ns + "GroundOverlay")) { - var latLonBoxElement = groundOverlayElement.Element(ns + "LatLonBox"); - var latLonBox = latLonBoxElement != null ? ReadLatLonBox(latLonBoxElement) : null; - var imagePathElement = groundOverlayElement.Element(ns + "Icon"); var imagePath = imagePathElement?.Element(ns + "href")?.Value; + var latLonBoxElement = groundOverlayElement.Element(ns + "LatLonBox"); + var latLonBox = latLonBoxElement != null ? ReadLatLonBox(latLonBoxElement) : null; + var drawOrder = groundOverlayElement.Element(ns + "drawOrder")?.Value; var zIndex = drawOrder != null ? int.Parse(drawOrder) : 0; if (latLonBox != null && imagePath != null) { - yield return new ImageOverlay(latLonBox, imagePath, zIndex); + yield return new ImageOverlay(imagePath, latLonBox, zIndex); } } } diff --git a/MapControl/WPF/GeoImage.WPF.cs b/MapControl/WPF/GeoImage.WPF.cs index 6447a1d4..4306c670 100644 --- a/MapControl/WPF/GeoImage.WPF.cs +++ b/MapControl/WPF/GeoImage.WPF.cs @@ -6,7 +6,6 @@ using System; using System.IO; using System.Linq; using System.Threading.Tasks; -using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -14,13 +13,6 @@ namespace MapControl { public static partial class GeoImage { - private partial class GeoBitmap - { - public Point BitmapSize => new Point(BitmapSource.PixelWidth, BitmapSource.PixelHeight); - - public ImageBrush ImageBrush => new ImageBrush(BitmapSource); - } - private static Task LoadGeoTiffAsync(string sourcePath) { return Task.Run(() => diff --git a/MapControl/WinUI/GeoImage.WinUI.cs b/MapControl/WinUI/GeoImage.WinUI.cs index 6d0781c9..a0b357cf 100644 --- a/MapControl/WinUI/GeoImage.WinUI.cs +++ b/MapControl/WinUI/GeoImage.WinUI.cs @@ -7,10 +7,8 @@ using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Storage; #if UWP -using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; #else -using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; #endif @@ -18,13 +16,6 @@ namespace MapControl { public static partial class GeoImage { - private partial class GeoBitmap - { - public Point BitmapSize => new Point(BitmapSource.PixelWidth, BitmapSource.PixelHeight); - - public ImageBrush ImageBrush => new ImageBrush { ImageSource = BitmapSource }; - } - private static async Task LoadGeoTiffAsync(string sourcePath) { BitmapSource bitmapSource;