mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
GeoImage and GroundOverlay implementation
This commit is contained in:
parent
febb6d6b00
commit
b22ee9a60f
|
|
@ -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<GeoBitmap> LoadGeoTiffAsync(string sourcePath)
|
||||
{
|
||||
throw new InvalidOperationException("GeoTIFF is not supported.");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<GeoBitmap> LoadGeoTiffAsync(string sourcePath)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
|
|
|
|||
|
|
@ -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<GeoBitmap> LoadGeoTiffAsync(string sourcePath)
|
||||
{
|
||||
BitmapSource bitmapSource;
|
||||
|
|
|
|||
Loading…
Reference in a new issue