mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
GeoImage implementation
This commit is contained in:
parent
f948f07f7e
commit
0d95dd2adb
|
|
@ -11,6 +11,8 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
private Point BitmapSize => new(bitmapSource.PixelSize.Width, bitmapSource.PixelSize.Height);
|
private Point BitmapSize => new(bitmapSource.PixelSize.Width, bitmapSource.PixelSize.Height);
|
||||||
|
|
||||||
|
private ImageBrush ImageBrush => new(bitmapSource);
|
||||||
|
|
||||||
private Task LoadGeoTiffAsync(string sourcePath)
|
private Task LoadGeoTiffAsync(string sourcePath)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("GeoTIFF is not supported.");
|
throw new InvalidOperationException("GeoTIFF is not supported.");
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,21 @@ using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using Shape = System.Windows.Shapes.Shape;
|
||||||
#elif UWP
|
#elif UWP
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Media.Imaging;
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
using Shape = Windows.UI.Xaml.Shapes.Shape;
|
||||||
#elif WINUI
|
#elif WINUI
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
using Microsoft.UI.Xaml.Media.Imaging;
|
using Microsoft.UI.Xaml.Media.Imaging;
|
||||||
|
using Shape = Microsoft.UI.Xaml.Shapes.Shape;
|
||||||
|
#elif AVALONIA
|
||||||
|
using Shape = Avalonia.Controls.Shapes.Shape;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
@ -44,28 +49,28 @@ namespace MapControl
|
||||||
|
|
||||||
public static readonly DependencyProperty SourcePathProperty =
|
public static readonly DependencyProperty SourcePathProperty =
|
||||||
DependencyPropertyHelper.RegisterAttached<GeoImage, string>("SourcePath", null,
|
DependencyPropertyHelper.RegisterAttached<GeoImage, string>("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);
|
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);
|
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);
|
SetSourcePath(image, sourcePath);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task LoadGeoImageAsync(Image image, string sourcePath)
|
private static async Task LoadGeoImageAsync(FrameworkElement element, string sourcePath)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(sourcePath))
|
if (!string.IsNullOrEmpty(sourcePath))
|
||||||
{
|
{
|
||||||
|
|
@ -82,10 +87,16 @@ namespace MapControl
|
||||||
? geoImage.mapProjection.MapToBoundingBox(new Rect(p1, p2))
|
? geoImage.mapProjection.MapToBoundingBox(new Rect(p1, p2))
|
||||||
: new BoundingBox(p1.Y, p1.X, p2.Y, p2.X);
|
: new BoundingBox(p1.Y, p1.X, p2.Y, p2.X);
|
||||||
|
|
||||||
image.Source = geoImage.bitmapSource;
|
if (element is Image image)
|
||||||
image.Stretch = Stretch.Fill;
|
{
|
||||||
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
||||||
|
|
||||||
|
private ImageBrush ImageBrush => new ImageBrush(bitmapSource);
|
||||||
|
|
||||||
private Task LoadGeoTiffAsync(string sourcePath)
|
private Task LoadGeoTiffAsync(string sourcePath)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.Graphics.Imaging;
|
using Windows.Graphics.Imaging;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
|
#if UWP
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
#else
|
||||||
|
using Microsoft.UI.Xaml.Media;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
|
|
@ -13,6 +18,8 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
||||||
|
|
||||||
|
private ImageBrush ImageBrush => new ImageBrush { ImageSource = bitmapSource };
|
||||||
|
|
||||||
private async Task LoadGeoTiffAsync(string sourcePath)
|
private async Task LoadGeoTiffAsync(string sourcePath)
|
||||||
{
|
{
|
||||||
var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));
|
var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue