Avalonia WmsImageLayer

This commit is contained in:
ClemensFischer 2024-05-21 23:18:00 +02:00
parent 5c3ebbc083
commit 838f77738b
7 changed files with 52 additions and 30 deletions

View file

@ -41,5 +41,10 @@ namespace MapControl
return LoadImage(stream); return LoadImage(stream);
}); });
} }
internal static Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
return Task.FromResult<IImage>(null);
}
} }
} }

View file

@ -7,6 +7,7 @@ using Avalonia.Animation;
using Avalonia.Animation.Easings; using Avalonia.Animation.Easings;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Styling; using Avalonia.Styling;
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -121,8 +122,8 @@ namespace MapControl
{ {
var scale = GetScale(location); var scale = GetScale(location);
return new Matrix(scale.X, 0d, 0d, scale.Y, 0d, 0d) return Matrix.CreateScale(scale.X, scale.Y)
.Append(Matrix.CreateRotation(ViewTransform.Rotation)); * Matrix.CreateRotation(ViewTransform.Rotation * Math.PI / 180d);
} }
private void CenterPropertyChanged(Location center) private void CenterPropertyChanged(Location center)

View file

@ -36,6 +36,7 @@
<Compile Include="..\Shared\ViewportChangedEventArgs.cs" Link="ViewportChangedEventArgs.cs" /> <Compile Include="..\Shared\ViewportChangedEventArgs.cs" Link="ViewportChangedEventArgs.cs" />
<Compile Include="..\Shared\ViewRect.cs" Link="ViewRect.cs" /> <Compile Include="..\Shared\ViewRect.cs" Link="ViewRect.cs" />
<Compile Include="..\Shared\WebMercatorProjection.cs" Link="WebMercatorProjection.cs" /> <Compile Include="..\Shared\WebMercatorProjection.cs" Link="WebMercatorProjection.cs" />
<Compile Include="..\Shared\WmsImageLayer.cs" Link="WmsImageLayer.cs" />
<Compile Include="..\WPF\Timer.WPF.cs" Link="Timer.WPF.cs" /> <Compile Include="..\WPF\Timer.WPF.cs" Link="Timer.WPF.cs" />
<Compile Include="..\WPF\TypeConverters.WPF.cs" Link="TypeConverters.WPF.cs" /> <Compile Include="..\WPF\TypeConverters.WPF.cs" Link="TypeConverters.WPF.cs" />
</ItemGroup> </ItemGroup>

View file

@ -40,6 +40,7 @@ namespace MapControl
{ {
var animation = new Animation var animation = new Animation
{ {
FillMode = FillMode.Forward,
Duration = MapBase.ImageFadeDuration, Duration = MapBase.ImageFadeDuration,
Children = Children =
{ {

View file

@ -64,9 +64,11 @@ namespace MapControl
Scale = scale; Scale = scale;
Rotation = ((rotation % 360d) + 360d) % 360d; Rotation = ((rotation % 360d) + 360d) % 360d;
MapToViewMatrix = new Matrix(Scale, 0d, 0d, -Scale, -Scale * mapCenter.X, Scale * mapCenter.Y) MapToViewMatrix
.Append(Matrix.CreateRotation(Rotation * Math.PI / 180d)) = Matrix.CreateTranslation(-mapCenter.X, -mapCenter.Y)
.Append(Matrix.CreateTranslation(viewCenter.X, viewCenter.Y)); * Matrix.CreateScale(scale, -scale)
* Matrix.CreateRotation(Rotation * Math.PI / 180d)
* Matrix.CreateTranslation(viewCenter.X, viewCenter.Y);
ViewToMapMatrix = MapToViewMatrix.Invert(); ViewToMapMatrix = MapToViewMatrix.Invert();
} }
@ -85,9 +87,9 @@ namespace MapControl
var transformScale = Scale / tileMatrixScale; var transformScale = Scale / tileMatrixScale;
return new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d) return Matrix.CreateScale(transformScale, transformScale)
.Append(Matrix.CreateRotation(Rotation * Math.PI / 180d)) * Matrix.CreateRotation(Rotation * Math.PI / 180d)
.Append(Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y)); * Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y);
} }
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize) public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize)
@ -98,14 +100,15 @@ namespace MapControl
var transformScale = tileMatrixScale / Scale; var transformScale = tileMatrixScale / Scale;
var transform = new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d) var transform
.Append(Matrix.CreateRotation(-Rotation * Math.PI / 180d)); = Matrix.CreateScale(transformScale, transformScale)
* Matrix.CreateRotation(-Rotation * Math.PI / 180d);
// Translate origin to tile matrix origin in pixels. // Translate origin to tile matrix origin in pixels.
// //
transform = transform.Append(Matrix.CreateTranslation( transform *= Matrix.CreateTranslation(
tileMatrixScale * (origin.X - tileMatrixTopLeft.X), tileMatrixScale * (origin.X - tileMatrixTopLeft.X),
tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y))); tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y));
// Transform view bounds to tile pixel bounds. // Transform view bounds to tile pixel bounds.
// //

View file

@ -74,7 +74,7 @@ namespace MapControl
Scale = scale; Scale = scale;
Rotation = ((rotation % 360d) + 360d) % 360d; Rotation = ((rotation % 360d) + 360d) % 360d;
var transform = new Matrix(Scale, 0d, 0d, -Scale, -Scale * mapCenter.X, Scale * mapCenter.Y); var transform = new Matrix(scale, 0d, 0d, -scale, -scale * mapCenter.X, scale * mapCenter.Y);
transform.Rotate(Rotation); transform.Rotate(Rotation);
transform.Translate(viewCenter.X, viewCenter.Y); transform.Translate(viewCenter.X, viewCenter.Y);

View file

@ -8,7 +8,14 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
#if WINUI #if AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Threading;
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
using ImageSource = Avalonia.Media.IImage;
#elif WINUI
using Windows.Foundation; using Windows.Foundation;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media;
@ -28,26 +35,25 @@ namespace MapControl
/// </summary> /// </summary>
public partial class WmsImageLayer : MapImageLayer public partial class WmsImageLayer : MapImageLayer
{ {
public static readonly DependencyProperty ServiceUriProperty = DependencyProperty.Register( public static readonly DependencyProperty ServiceUriProperty =
nameof(ServiceUri), typeof(Uri), typeof(WmsImageLayer), DependencyPropertyHelper.Register<WmsImageLayer, Uri>(nameof(ServiceUri), null, false,
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync())); async (layer, oldValue, newValue) => await layer.UpdateImageAsync());
public static readonly DependencyProperty LayersProperty = DependencyProperty.Register( public static readonly DependencyProperty LayersProperty =
nameof(Layers), typeof(string), typeof(WmsImageLayer), DependencyPropertyHelper.Register<WmsImageLayer, string>(nameof(Layers), null, false,
new PropertyMetadata(null, async (layer, oldValue, newValue) =>
async (o, e) =>
{ {
// Ignore property change from GetImageAsync, when Layers was null. // Ignore property change from GetImageAsync, when Layers was null.
// //
if (e.OldValue != null) if (oldValue != null)
{ {
await ((WmsImageLayer)o).UpdateImageAsync(); await layer.UpdateImageAsync();
} }
})); });
public static readonly DependencyProperty StylesProperty = DependencyProperty.Register( public static readonly DependencyProperty StylesProperty =
nameof(Styles), typeof(string), typeof(WmsImageLayer), DependencyPropertyHelper.Register<WmsImageLayer, string>(nameof(Styles), string.Empty, false,
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync())); async (layer, oldValue, newValue) => await layer.UpdateImageAsync());
public WmsImageLayer() public WmsImageLayer()
{ {
@ -78,7 +84,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Comma-separated sequence of requested styles. Default is an empty string. /// Comma-separated sequence of requested styles. Default is an empty string.
/// </summary> /// </summary>
public string Styles public new string Styles
{ {
get => (string)GetValue(StylesProperty); get => (string)GetValue(StylesProperty);
set => SetValue(StylesProperty, value); set => SetValue(StylesProperty, value);
@ -278,11 +284,16 @@ namespace MapControl
} }
var viewRect = GetViewRect(rect.Value); var viewRect = GetViewRect(rect.Value);
#if AVALONIA
var transform
= Matrix.CreateTranslation(-viewSize.Width / 2d, -viewSize.Height / 2d)
* Matrix.CreateRotation(-viewRect.Rotation * Math.PI / 180d)
* Matrix.CreateTranslation(viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d);
#else
var transform = new Matrix(1d, 0d, 0d, 1d, -viewSize.Width / 2d, -viewSize.Height / 2d); var transform = new Matrix(1d, 0d, 0d, 1d, -viewSize.Width / 2d, -viewSize.Height / 2d);
transform.Rotate(-viewRect.Rotation); transform.Rotate(-viewRect.Rotation);
transform.Translate(viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d); transform.Translate(viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d);
#endif
var imagePos = transform.Transform(position); var imagePos = transform.Transform(position);
var queryParameters = new Dictionary<string, string> var queryParameters = new Dictionary<string, string>