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
|
|
@ -9,6 +9,44 @@ namespace MapControl
|
|||
{
|
||||
public static class DependencyPropertyHelper
|
||||
{
|
||||
public static DependencyProperty RegisterAttached<TValue>(
|
||||
string name,
|
||||
Type ownerType,
|
||||
TValue defaultValue = default,
|
||||
Action<FrameworkElement, TValue, TValue> changed = null,
|
||||
bool inherits = false)
|
||||
{
|
||||
var metadata = new FrameworkPropertyMetadata
|
||||
{
|
||||
DefaultValue = defaultValue,
|
||||
Inherits = inherits
|
||||
};
|
||||
|
||||
if (changed != null)
|
||||
{
|
||||
metadata.PropertyChangedCallback = (o, e) =>
|
||||
{
|
||||
if (o is FrameworkElement element)
|
||||
{
|
||||
changed(element, (TValue)e.OldValue, (TValue)e.NewValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), ownerType, metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty RegisterAttached<TValue>(
|
||||
string name,
|
||||
Type ownerType,
|
||||
TValue defaultValue,
|
||||
FrameworkPropertyMetadataOptions options)
|
||||
{
|
||||
var metadata = new FrameworkPropertyMetadata(defaultValue, options);
|
||||
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), ownerType, metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue,
|
||||
|
|
@ -47,42 +85,6 @@ namespace MapControl
|
|||
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty RegisterAttached<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue,
|
||||
FrameworkPropertyMetadataOptions options)
|
||||
{
|
||||
var metadata = new FrameworkPropertyMetadata(defaultValue, options);
|
||||
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty RegisterAttached<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
Action<FrameworkElement, TValue, TValue> changed = null,
|
||||
bool inherits = false)
|
||||
{
|
||||
var metadata = new FrameworkPropertyMetadata
|
||||
{
|
||||
DefaultValue = defaultValue,
|
||||
Inherits = inherits
|
||||
};
|
||||
|
||||
if (changed != null)
|
||||
{
|
||||
metadata.PropertyChangedCallback = (o, e) =>
|
||||
{
|
||||
if (o is FrameworkElement element)
|
||||
{
|
||||
changed(element, (TValue)e.OldValue, (TValue)e.NewValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
}
|
||||
|
||||
public static DependencyPropertyKey RegisterReadOnly<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default)
|
||||
|
|
|
|||
|
|
@ -12,16 +12,23 @@ using System.Windows.Media.Imaging;
|
|||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class GeoImage
|
||||
public static partial class GeoImage
|
||||
{
|
||||
private Point BitmapSize => new Point(bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
||||
private partial class GeoBitmap
|
||||
{
|
||||
public Point BitmapSize => new Point(BitmapSource.PixelWidth, BitmapSource.PixelHeight);
|
||||
|
||||
private ImageBrush ImageBrush => new ImageBrush(bitmapSource);
|
||||
public ImageBrush ImageBrush => new ImageBrush(BitmapSource);
|
||||
}
|
||||
|
||||
private Task LoadGeoTiffAsync(string sourcePath)
|
||||
private static Task<GeoBitmap> LoadGeoTiffAsync(string sourcePath)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
BitmapSource bitmapSource;
|
||||
Matrix transformMatrix;
|
||||
MapProjection mapProjection = null;
|
||||
|
||||
using (var stream = File.OpenRead(sourcePath))
|
||||
{
|
||||
bitmapSource = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
|
|
@ -50,7 +57,7 @@ namespace MapControl
|
|||
|
||||
if (metadata.GetQuery(QueryString(GeoKeyDirectoryTag)) is short[] geoKeyDirectory)
|
||||
{
|
||||
SetProjection(geoKeyDirectory);
|
||||
mapProjection = GetProjection(geoKeyDirectory);
|
||||
}
|
||||
|
||||
if (metadata.GetQuery(QueryString(NoDataTag)) is string noData &&
|
||||
|
|
@ -58,6 +65,8 @@ namespace MapControl
|
|||
{
|
||||
bitmapSource = ConvertTransparentPixel(bitmapSource, noDataValue);
|
||||
}
|
||||
|
||||
return new GeoBitmap(bitmapSource, transformMatrix, mapProjection);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,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,
|
||||
FrameworkPropertyMetadataOptions.AffectsParentArrange);
|
||||
|
||||
public static readonly DependencyProperty BoundingBoxProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
|
||||
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
|
||||
FrameworkPropertyMetadataOptions.AffectsParentArrange);
|
||||
|
||||
protected IEnumerable<FrameworkElement> ChildElements => InternalChildren.OfType<FrameworkElement>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue