Fixed TileSource (14.2.0)

This commit is contained in:
ClemensFischer 2025-11-14 15:02:48 +01:00
parent ef7849948e
commit 36883a8d9d
6 changed files with 49 additions and 20 deletions

View file

@ -3,7 +3,7 @@
<Product>XAML Map Control</Product> <Product>XAML Map Control</Product>
<Authors>Clemens Fischer</Authors> <Authors>Clemens Fischer</Authors>
<Copyright>Copyright © 2025 Clemens Fischer</Copyright> <Copyright>Copyright © 2025 Clemens Fischer</Copyright>
<Version>14.1.0</Version> <Version>14.2.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion> <AssemblyVersion>$(Version)</AssemblyVersion>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>

View file

@ -24,6 +24,11 @@ namespace MapControl
/// </summary> /// </summary>
public partial class MapTileLayer : TilePyramidLayer public partial class MapTileLayer : TilePyramidLayer
{ {
private const int TileSize = 256;
private static readonly Point MapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree,
180d * MapProjection.Wgs84MeterPerDegree);
public static readonly DependencyProperty MinZoomLevelProperty = public static readonly DependencyProperty MinZoomLevelProperty =
DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0); DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0);
@ -33,11 +38,6 @@ namespace MapControl
public static readonly DependencyProperty ZoomLevelOffsetProperty = public static readonly DependencyProperty ZoomLevelOffsetProperty =
DependencyPropertyHelper.Register<MapTileLayer, double>(nameof(ZoomLevelOffset), 0d); DependencyPropertyHelper.Register<MapTileLayer, double>(nameof(ZoomLevelOffset), 0d);
private const int TileSize = 256;
private static readonly Point MapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree,
180d * MapProjection.Wgs84MeterPerDegree);
/// <summary> /// <summary>
/// A default MapTileLayer using OpenStreetMap data. /// A default MapTileLayer using OpenStreetMap data.
/// </summary> /// </summary>
@ -48,6 +48,11 @@ namespace MapControl
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)" Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
}; };
public MapTileLayer()
{
MapPanel.SetRenderTransform(this, new MatrixTransform());
}
public override IReadOnlyCollection<string> SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId]; public override IReadOnlyCollection<string> SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId];
public TileMatrix TileMatrix { get; private set; } public TileMatrix TileMatrix { get; private set; }

View file

@ -165,7 +165,7 @@ namespace MapControl
} }
else if (uri.Scheme != "http" && uri.Scheme != "https" || string.IsNullOrEmpty(cacheName)) else if (uri.Scheme != "http" && uri.Scheme != "https" || string.IsNullOrEmpty(cacheName))
{ {
await tile.LoadImageAsync(() => ImageLoader.LoadImageAsync(uri)).ConfigureAwait(false); await tile.LoadImageAsync(() => tileSource.LoadImageAsync(uri)).ConfigureAwait(false);
} }
else else
{ {
@ -173,7 +173,7 @@ namespace MapControl
if (buffer != null) if (buffer != null)
{ {
await tile.LoadImageAsync(() => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); await tile.LoadImageAsync(() => tileSource.LoadImageAsync(buffer)).ConfigureAwait(false);
} }
} }
} }

View file

@ -69,8 +69,6 @@ namespace MapControl
updateTimer = new UpdateTimer { Interval = UpdateInterval }; updateTimer = new UpdateTimer { Interval = UpdateInterval };
updateTimer.Tick += (s, e) => UpdateTiles(); updateTimer.Tick += (s, e) => UpdateTiles();
MapPanel.SetRenderTransform(this, new MatrixTransform());
#if WPF #if WPF
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
#elif UWP || WINUI #elif UWP || WINUI

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Security.Policy;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
#if WPF #if WPF
@ -14,7 +15,7 @@ using ImageSource = Avalonia.Media.IImage;
namespace MapControl namespace MapControl
{ {
/// <summary> /// <summary>
/// Provides the download Uri or ImageSource of map tiles. /// Provides the download Uri or ImageSource of map tiles. Used by TileImageLoader.
/// </summary> /// </summary>
#if UWP || WINUI #if UWP || WINUI
[Windows.Foundation.Metadata.CreateFromString(MethodName = "Parse")] [Windows.Foundation.Metadata.CreateFromString(MethodName = "Parse")]
@ -24,15 +25,38 @@ namespace MapControl
public class TileSource public class TileSource
{ {
/// <summary> /// <summary>
/// Gets the image request Uri for the specified zoom level and tile indices. /// Gets an image request Uri for the specified zoom level and tile indices.
/// May return null when the image shall be loaded by the LoadImageAsync method. /// May return null when the image shall be loaded by
/// the LoadImageAsync(zoomLevel, column, row) method.
/// </summary> /// </summary>
public virtual Uri GetUri(int zoomLevel, int column, int row) => null; public virtual Uri GetUri(int zoomLevel, int column, int row)
{
return null;
}
/// <summary> /// <summary>
/// Loads a tile image without an Uri. /// Loads a tile image without an Uri.
/// </summary> /// </summary>
public virtual Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row) => null; public virtual Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row)
{
return null;
}
/// <summary>
/// Loads a tile image from an Uri.
/// </summary>
public virtual Task<ImageSource> LoadImageAsync(Uri uri)
{
return ImageLoader.LoadImageAsync(uri);
}
/// <summary>
/// Loads a tile image from an encoded frame buffer.
/// </summary>
public virtual Task<ImageSource> LoadImageAsync(byte[] buffer)
{
return ImageLoader.LoadImageAsync(buffer);
}
/// <summary> /// <summary>
/// Creates a TileSource instance from an Uri template string. /// Creates a TileSource instance from an Uri template string.

View file

@ -117,12 +117,14 @@ namespace MapControl
{ {
// Arrange tiles relative to XMin/YMin. // Arrange tiles relative to XMin/YMin.
// //
var x = WmtsTileMatrix.TileWidth * (tile.X - TileMatrix.XMin); var tileWidth = WmtsTileMatrix.TileWidth;
var y = WmtsTileMatrix.TileHeight * (tile.Y - TileMatrix.YMin); var tileHeight = WmtsTileMatrix.TileHeight;
var x = tileWidth * (tile.X - TileMatrix.XMin);
var y = tileHeight * (tile.Y - TileMatrix.YMin);
tile.Image.Width = WmtsTileMatrix.TileWidth; tile.Image.Width = tileWidth;
tile.Image.Height = WmtsTileMatrix.TileHeight; tile.Image.Height = tileHeight;
tile.Image.Arrange(new Rect(x, y, WmtsTileMatrix.TileWidth, WmtsTileMatrix.TileHeight)); tile.Image.Arrange(new Rect(x, y, tileWidth, tileHeight));
} }
return finalSize; return finalSize;