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>
<Authors>Clemens Fischer</Authors>
<Copyright>Copyright © 2025 Clemens Fischer</Copyright>
<Version>14.1.0</Version>
<Version>14.2.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>

View file

@ -24,6 +24,11 @@ namespace MapControl
/// </summary>
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 =
DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0);
@ -33,11 +38,6 @@ namespace MapControl
public static readonly DependencyProperty ZoomLevelOffsetProperty =
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>
/// A default MapTileLayer using OpenStreetMap data.
/// </summary>
@ -48,6 +48,11 @@ namespace MapControl
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
};
public MapTileLayer()
{
MapPanel.SetRenderTransform(this, new MatrixTransform());
}
public override IReadOnlyCollection<string> SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId];
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))
{
await tile.LoadImageAsync(() => ImageLoader.LoadImageAsync(uri)).ConfigureAwait(false);
await tile.LoadImageAsync(() => tileSource.LoadImageAsync(uri)).ConfigureAwait(false);
}
else
{
@ -173,7 +173,7 @@ namespace MapControl
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.Tick += (s, e) => UpdateTiles();
MapPanel.SetRenderTransform(this, new MatrixTransform());
#if WPF
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
#elif UWP || WINUI

View file

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

View file

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