XAML-Map-Control/MapControl/Shared/ImageTileList.cs

48 lines
1.6 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System.Collections.Generic;
2022-11-22 19:15:34 +01:00
using System.Linq;
namespace MapControl
{
2025-11-14 23:59:24 +01:00
public class ImageTileList : List<ImageTile>
2022-11-22 19:15:34 +01:00
{
2025-11-20 00:14:52 +01:00
public ImageTileList()
{
}
public ImageTileList(ImageTileList source, TileMatrix tileMatrix, int columnCount)
{
FillMatrix(source, tileMatrix.ZoomLevel, tileMatrix.XMin, tileMatrix.YMin, tileMatrix.XMax, tileMatrix.YMax, columnCount);
}
2022-11-22 19:15:34 +01:00
/// <summary>
2025-11-13 15:32:01 +01:00
/// Adds existing ImageTile from the source collection or newly created ImageTile to fill the specified tile matrix.
2022-11-22 19:15:34 +01:00
/// </summary>
2025-11-13 15:32:01 +01:00
public void FillMatrix(ImageTileList source, int zoomLevel, int xMin, int yMin, int xMax, int yMax, int columnCount)
2022-11-22 19:15:34 +01:00
{
2025-08-22 16:10:03 +02:00
for (var y = yMin; y <= yMax; y++)
2022-11-22 19:15:34 +01:00
{
2025-08-22 16:10:03 +02:00
for (var x = xMin; x <= xMax; x++)
{
var tile = source.FirstOrDefault(t => t.ZoomLevel == zoomLevel && t.X == x && t.Y == y);
2022-11-22 19:15:34 +01:00
2025-08-22 16:10:03 +02:00
if (tile == null)
{
2025-11-13 15:32:01 +01:00
tile = new ImageTile(zoomLevel, x, y, columnCount);
2022-11-22 19:15:34 +01:00
2025-08-22 16:10:03 +02:00
var equivalentTile = source.FirstOrDefault(
t => t.Image.Source != null && t.ZoomLevel == tile.ZoomLevel && t.Column == tile.Column && t.Row == tile.Row);
if (equivalentTile != null)
{
tile.IsPending = false;
tile.Image.Source = equivalentTile.Image.Source; // no opacity animation
}
}
Add(tile);
2022-11-22 19:15:34 +01:00
}
}
}
}
}