mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
GeoImage and DependencyPropertyHelper implementation
This commit is contained in:
parent
0344db4b9b
commit
1b0e73dc35
12 changed files with 190 additions and 154 deletions
|
|
@ -15,21 +15,9 @@ namespace MapControl
|
|||
{
|
||||
public static class DependencyPropertyHelper
|
||||
{
|
||||
public static DependencyProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
Action<TOwner, TValue, TValue> changed = null)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
var metadata = changed != null
|
||||
? new PropertyMetadata(defaultValue, (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue))
|
||||
: new PropertyMetadata(defaultValue);
|
||||
|
||||
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty RegisterAttached<TOwner, TValue>(
|
||||
public static DependencyProperty RegisterAttached<TValue>(
|
||||
string name,
|
||||
Type ownerType,
|
||||
TValue defaultValue = default,
|
||||
Action<FrameworkElement, TValue, TValue> changed = null,
|
||||
bool inherits = false) // unused in WinUI/UWP
|
||||
|
|
@ -44,7 +32,20 @@ namespace MapControl
|
|||
}
|
||||
});
|
||||
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), ownerType, metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
Action<TOwner, TValue, TValue> changed = null)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
var metadata = changed != null
|
||||
? new PropertyMetadata(defaultValue, (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue))
|
||||
: new PropertyMetadata(defaultValue);
|
||||
|
||||
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,20 +8,29 @@ 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
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class GeoImage
|
||||
public static partial class GeoImage
|
||||
{
|
||||
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
||||
|
||||
private ImageBrush ImageBrush => new ImageBrush { ImageSource = bitmapSource };
|
||||
|
||||
private async Task LoadGeoTiffAsync(string sourcePath)
|
||||
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;
|
||||
Matrix transformMatrix;
|
||||
MapProjection mapProjection = null;
|
||||
|
||||
var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));
|
||||
|
||||
using (var stream = await file.OpenReadAsync())
|
||||
|
|
@ -68,9 +77,11 @@ namespace MapControl
|
|||
if (metadata.TryGetValue(geoKeyDirectoryQuery, out BitmapTypedValue geoKeyDirValue) &&
|
||||
geoKeyDirValue.Value is short[] geoKeyDirectory)
|
||||
{
|
||||
SetProjection(geoKeyDirectory);
|
||||
mapProjection = GetProjection(geoKeyDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
return new GeoBitmap(bitmapSource, transformMatrix, mapProjection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ namespace MapControl
|
|||
public partial class MapPanel
|
||||
{
|
||||
public static readonly DependencyProperty AutoCollapseProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
|
||||
DependencyPropertyHelper.RegisterAttached<bool>("AutoCollapse", typeof(MapPanel));
|
||||
|
||||
public static readonly DependencyProperty LocationProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null,
|
||||
DependencyPropertyHelper.RegisterAttached<Location>("Location", typeof(MapPanel), null,
|
||||
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
|
||||
|
||||
public static readonly DependencyProperty BoundingBoxProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
|
||||
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
|
||||
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
|
||||
|
||||
protected IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue