diff --git a/MapControl/Avalonia/GeoImage.Avalonia.cs b/MapControl/Avalonia/GeoImage.Avalonia.cs index 1cfa2a9f..09f636c8 100644 --- a/MapControl/Avalonia/GeoImage.Avalonia.cs +++ b/MapControl/Avalonia/GeoImage.Avalonia.cs @@ -11,6 +11,8 @@ namespace MapControl { private Point BitmapSize => new(bitmapSource.PixelSize.Width, bitmapSource.PixelSize.Height); + private ImageBrush ImageBrush => new(bitmapSource); + private Task LoadGeoTiffAsync(string sourcePath) { throw new InvalidOperationException("GeoTIFF is not supported."); diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs index 9ef34b35..a5e329ad 100644 --- a/MapControl/Shared/GeoImage.cs +++ b/MapControl/Shared/GeoImage.cs @@ -13,16 +13,21 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; +using Shape = System.Windows.Shapes.Shape; #elif UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; +using Shape = Windows.UI.Xaml.Shapes.Shape; #elif WINUI using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; +using Shape = Microsoft.UI.Xaml.Shapes.Shape; +#elif AVALONIA +using Shape = Avalonia.Controls.Shapes.Shape; #endif namespace MapControl @@ -44,28 +49,28 @@ namespace MapControl public static readonly DependencyProperty SourcePathProperty = DependencyPropertyHelper.RegisterAttached("SourcePath", null, - async (image, oldValue, newValue) => await LoadGeoImageAsync((Image)image, newValue)); + async (image, oldValue, newValue) => await LoadGeoImageAsync(image, newValue)); - public static string GetSourcePath(Image image) + public static string GetSourcePath(FrameworkElement image) { return (string)image.GetValue(SourcePathProperty); } - public static void SetSourcePath(Image image, string value) + public static void SetSourcePath(FrameworkElement image, string value) { image.SetValue(SourcePathProperty, value); } - public static Image LoadGeoImage(string sourcePath) + public static FrameworkElement LoadGeoImage(string sourcePath) { - var image = new Image(); + var image = new Image { Stretch = Stretch.Fill }; SetSourcePath(image, sourcePath); return image; } - private static async Task LoadGeoImageAsync(Image image, string sourcePath) + private static async Task LoadGeoImageAsync(FrameworkElement element, string sourcePath) { if (!string.IsNullOrEmpty(sourcePath)) { @@ -82,10 +87,16 @@ namespace MapControl ? geoImage.mapProjection.MapToBoundingBox(new Rect(p1, p2)) : new BoundingBox(p1.Y, p1.X, p2.Y, p2.X); - image.Source = geoImage.bitmapSource; - image.Stretch = Stretch.Fill; + if (element is Image image) + { + image.Source = geoImage.bitmapSource; + } + else if (element is Shape shape) + { + shape.Fill = geoImage.ImageBrush; + } - MapPanel.SetBoundingBox(image, boundingBox); + MapPanel.SetBoundingBox(element, boundingBox); } catch (Exception ex) { diff --git a/MapControl/WPF/GeoImage.WPF.cs b/MapControl/WPF/GeoImage.WPF.cs index 0ef68336..daf30957 100644 --- a/MapControl/WPF/GeoImage.WPF.cs +++ b/MapControl/WPF/GeoImage.WPF.cs @@ -16,6 +16,8 @@ namespace MapControl { private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight); + private ImageBrush ImageBrush => new ImageBrush(bitmapSource); + private Task LoadGeoTiffAsync(string sourcePath) { return Task.Run(() => diff --git a/MapControl/WinUI/GeoImage.WinUI.cs b/MapControl/WinUI/GeoImage.WinUI.cs index 43d32c48..f3bedd78 100644 --- a/MapControl/WinUI/GeoImage.WinUI.cs +++ b/MapControl/WinUI/GeoImage.WinUI.cs @@ -6,6 +6,11 @@ using System; using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Storage; +#if UWP +using Windows.UI.Xaml.Media; +#else +using Microsoft.UI.Xaml.Media; +#endif namespace MapControl { @@ -13,6 +18,8 @@ namespace MapControl { private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight); + private ImageBrush ImageBrush => new ImageBrush { ImageSource = bitmapSource }; + private async Task LoadGeoTiffAsync(string sourcePath) { var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));