mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Avalonia WmsImageLayer
This commit is contained in:
parent
5c3ebbc083
commit
838f77738b
|
|
@ -41,5 +41,10 @@ namespace MapControl
|
|||
return LoadImage(stream);
|
||||
});
|
||||
}
|
||||
|
||||
internal static Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
|
||||
{
|
||||
return Task.FromResult<IImage>(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using Avalonia.Animation;
|
|||
using Avalonia.Animation.Easings;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Styling;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -121,8 +122,8 @@ namespace MapControl
|
|||
{
|
||||
var scale = GetScale(location);
|
||||
|
||||
return new Matrix(scale.X, 0d, 0d, scale.Y, 0d, 0d)
|
||||
.Append(Matrix.CreateRotation(ViewTransform.Rotation));
|
||||
return Matrix.CreateScale(scale.X, scale.Y)
|
||||
* Matrix.CreateRotation(ViewTransform.Rotation * Math.PI / 180d);
|
||||
}
|
||||
|
||||
private void CenterPropertyChanged(Location center)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<Compile Include="..\Shared\ViewportChangedEventArgs.cs" Link="ViewportChangedEventArgs.cs" />
|
||||
<Compile Include="..\Shared\ViewRect.cs" Link="ViewRect.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\TypeConverters.WPF.cs" Link="TypeConverters.WPF.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ namespace MapControl
|
|||
{
|
||||
var animation = new Animation
|
||||
{
|
||||
FillMode = FillMode.Forward,
|
||||
Duration = MapBase.ImageFadeDuration,
|
||||
Children =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,9 +64,11 @@ namespace MapControl
|
|||
Scale = scale;
|
||||
Rotation = ((rotation % 360d) + 360d) % 360d;
|
||||
|
||||
MapToViewMatrix = new Matrix(Scale, 0d, 0d, -Scale, -Scale * mapCenter.X, Scale * mapCenter.Y)
|
||||
.Append(Matrix.CreateRotation(Rotation * Math.PI / 180d))
|
||||
.Append(Matrix.CreateTranslation(viewCenter.X, viewCenter.Y));
|
||||
MapToViewMatrix
|
||||
= Matrix.CreateTranslation(-mapCenter.X, -mapCenter.Y)
|
||||
* Matrix.CreateScale(scale, -scale)
|
||||
* Matrix.CreateRotation(Rotation * Math.PI / 180d)
|
||||
* Matrix.CreateTranslation(viewCenter.X, viewCenter.Y);
|
||||
|
||||
ViewToMapMatrix = MapToViewMatrix.Invert();
|
||||
}
|
||||
|
|
@ -85,9 +87,9 @@ namespace MapControl
|
|||
|
||||
var transformScale = Scale / tileMatrixScale;
|
||||
|
||||
return new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d)
|
||||
.Append(Matrix.CreateRotation(Rotation * Math.PI / 180d))
|
||||
.Append(Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y));
|
||||
return Matrix.CreateScale(transformScale, transformScale)
|
||||
* Matrix.CreateRotation(Rotation * Math.PI / 180d)
|
||||
* Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y);
|
||||
}
|
||||
|
||||
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize)
|
||||
|
|
@ -98,14 +100,15 @@ namespace MapControl
|
|||
|
||||
var transformScale = tileMatrixScale / Scale;
|
||||
|
||||
var transform = new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d)
|
||||
.Append(Matrix.CreateRotation(-Rotation * Math.PI / 180d));
|
||||
var transform
|
||||
= Matrix.CreateScale(transformScale, transformScale)
|
||||
* Matrix.CreateRotation(-Rotation * Math.PI / 180d);
|
||||
|
||||
// Translate origin to tile matrix origin in pixels.
|
||||
//
|
||||
transform = transform.Append(Matrix.CreateTranslation(
|
||||
transform *= Matrix.CreateTranslation(
|
||||
tileMatrixScale * (origin.X - tileMatrixTopLeft.X),
|
||||
tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y)));
|
||||
tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y));
|
||||
|
||||
// Transform view bounds to tile pixel bounds.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace MapControl
|
|||
Scale = scale;
|
||||
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.Translate(viewCenter.X, viewCenter.Y);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,14 @@ using System.Diagnostics;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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 Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
|
|
@ -28,26 +35,25 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public partial class WmsImageLayer : MapImageLayer
|
||||
{
|
||||
public static readonly DependencyProperty ServiceUriProperty = DependencyProperty.Register(
|
||||
nameof(ServiceUri), typeof(Uri), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
|
||||
public static readonly DependencyProperty ServiceUriProperty =
|
||||
DependencyPropertyHelper.Register<WmsImageLayer, Uri>(nameof(ServiceUri), null, false,
|
||||
async (layer, oldValue, newValue) => await layer.UpdateImageAsync());
|
||||
|
||||
public static readonly DependencyProperty LayersProperty = DependencyProperty.Register(
|
||||
nameof(Layers), typeof(string), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(null,
|
||||
async (o, e) =>
|
||||
public static readonly DependencyProperty LayersProperty =
|
||||
DependencyPropertyHelper.Register<WmsImageLayer, string>(nameof(Layers), null, false,
|
||||
async (layer, oldValue, newValue) =>
|
||||
{
|
||||
// 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(
|
||||
nameof(Styles), typeof(string), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
|
||||
public static readonly DependencyProperty StylesProperty =
|
||||
DependencyPropertyHelper.Register<WmsImageLayer, string>(nameof(Styles), string.Empty, false,
|
||||
async (layer, oldValue, newValue) => await layer.UpdateImageAsync());
|
||||
|
||||
public WmsImageLayer()
|
||||
{
|
||||
|
|
@ -78,7 +84,7 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Comma-separated sequence of requested styles. Default is an empty string.
|
||||
/// </summary>
|
||||
public string Styles
|
||||
public new string Styles
|
||||
{
|
||||
get => (string)GetValue(StylesProperty);
|
||||
set => SetValue(StylesProperty, value);
|
||||
|
|
@ -278,11 +284,16 @@ namespace MapControl
|
|||
}
|
||||
|
||||
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);
|
||||
transform.Rotate(-viewRect.Rotation);
|
||||
transform.Translate(viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d);
|
||||
|
||||
#endif
|
||||
var imagePos = transform.Transform(position);
|
||||
|
||||
var queryParameters = new Dictionary<string, string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue