mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.17.0: Added support for WMTS
This commit is contained in:
parent
b5fe760c83
commit
31a58c3510
|
|
@ -198,7 +198,7 @@ namespace MapControl
|
||||||
InverseViewportTransform = matrix;
|
InverseViewportTransform = matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Matrix CreateViewportTransform(Point mapCenter, Point viewportCenter)
|
private Matrix CreateViewportTransform(Point mapCenter, Point viewportCenter)
|
||||||
{
|
{
|
||||||
var matrix = new Matrix(ViewportScale, 0d, 0d, -ViewportScale, -ViewportScale * mapCenter.X, ViewportScale * mapCenter.Y);
|
var matrix = new Matrix(ViewportScale, 0d, 0d, -ViewportScale, -ViewportScale * mapCenter.X, ViewportScale * mapCenter.Y);
|
||||||
|
|
||||||
|
|
@ -215,13 +215,13 @@ namespace MapControl
|
||||||
|
|
||||||
matrix.Rotate(ViewportRotation);
|
matrix.Rotate(ViewportRotation);
|
||||||
|
|
||||||
// tile grid origin in map cordinates
|
// tile grid origin in map coordinates
|
||||||
//
|
//
|
||||||
var mapOrigin = new Point(
|
var mapOrigin = new Point(
|
||||||
tileGridTopLeft.X + tileGridOrigin.X / tileGridScale,
|
tileGridTopLeft.X + tileGridOrigin.X / tileGridScale,
|
||||||
tileGridTopLeft.Y - tileGridOrigin.Y / tileGridScale);
|
tileGridTopLeft.Y - tileGridOrigin.Y / tileGridScale);
|
||||||
|
|
||||||
// tile grid origin in viewport cordinates
|
// tile grid origin in viewport coordinates
|
||||||
//
|
//
|
||||||
var viewOrigin = ViewportTransform.Transform(mapOrigin);
|
var viewOrigin = ViewportTransform.Transform(mapOrigin);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,10 +63,10 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyCollection<Tile> Tiles { get; private set; } = new List<Tile>();
|
|
||||||
|
|
||||||
public TileGrid TileGrid { get; private set; }
|
public TileGrid TileGrid { get; private set; }
|
||||||
|
|
||||||
|
public IReadOnlyCollection<Tile> Tiles { get; private set; } = new List<Tile>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum zoom level supported by the MapTileLayer. Default value is 0.
|
/// Minimum zoom level supported by the MapTileLayer. Default value is 0.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -85,37 +85,6 @@ namespace MapControl
|
||||||
set { SetValue(MaxZoomLevelProperty, value); }
|
set { SetValue(MaxZoomLevelProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Size MeasureOverride(Size availableSize)
|
|
||||||
{
|
|
||||||
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
|
||||||
|
|
||||||
foreach (var tile in Tiles)
|
|
||||||
{
|
|
||||||
tile.Image.Measure(availableSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Size();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Size ArrangeOverride(Size finalSize)
|
|
||||||
{
|
|
||||||
if (TileGrid != null)
|
|
||||||
{
|
|
||||||
foreach (var tile in Tiles)
|
|
||||||
{
|
|
||||||
var tileSize = TileSize << (TileGrid.ZoomLevel - tile.ZoomLevel);
|
|
||||||
var x = tileSize * tile.X - TileSize * TileGrid.XMin;
|
|
||||||
var y = tileSize * tile.Y - TileSize * TileGrid.YMin;
|
|
||||||
|
|
||||||
tile.Image.Width = tileSize;
|
|
||||||
tile.Image.Height = tileSize;
|
|
||||||
tile.Image.Arrange(new Rect(x, y, tileSize, tileSize));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return finalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void TileSourcePropertyChanged()
|
protected override void TileSourcePropertyChanged()
|
||||||
{
|
{
|
||||||
if (TileGrid != null)
|
if (TileGrid != null)
|
||||||
|
|
@ -242,5 +211,36 @@ namespace MapControl
|
||||||
|
|
||||||
TileImageLoader.LoadTilesAsync(Tiles, TileSource, SourceName);
|
TileImageLoader.LoadTilesAsync(Tiles, TileSource, SourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override Size MeasureOverride(Size availableSize)
|
||||||
|
{
|
||||||
|
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
||||||
|
|
||||||
|
foreach (var tile in Tiles)
|
||||||
|
{
|
||||||
|
tile.Image.Measure(availableSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Size();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Size ArrangeOverride(Size finalSize)
|
||||||
|
{
|
||||||
|
if (TileGrid != null)
|
||||||
|
{
|
||||||
|
foreach (var tile in Tiles)
|
||||||
|
{
|
||||||
|
var tileSize = TileSize << (TileGrid.ZoomLevel - tile.ZoomLevel);
|
||||||
|
var x = tileSize * tile.X - TileSize * TileGrid.XMin;
|
||||||
|
var y = tileSize * tile.Y - TileSize * TileGrid.YMin;
|
||||||
|
|
||||||
|
tile.Image.Width = tileSize;
|
||||||
|
tile.Image.Height = tileSize;
|
||||||
|
tile.Image.Arrange(new Rect(x, y, tileSize, tileSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ namespace MapControl
|
||||||
public WmtsTileLayer(ITileImageLoader tileImageLoader)
|
public WmtsTileLayer(ITileImageLoader tileImageLoader)
|
||||||
: base(tileImageLoader)
|
: base(tileImageLoader)
|
||||||
{
|
{
|
||||||
|
IsHitTestVisible = false;
|
||||||
|
|
||||||
Loaded += OnLoaded;
|
Loaded += OnLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,11 +50,16 @@ namespace MapControl
|
||||||
set { SetValue(LayerIdentifierProperty, value); }
|
set { SetValue(LayerIdentifierProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<WmtsTileMatrixLayer> ChildLayers
|
||||||
|
{
|
||||||
|
get { return Children.Cast<WmtsTileMatrixLayer>(); }
|
||||||
|
}
|
||||||
|
|
||||||
public Dictionary<string, WmtsTileMatrixSet> TileMatrixSets { get; } = new Dictionary<string, WmtsTileMatrixSet>();
|
public Dictionary<string, WmtsTileMatrixSet> TileMatrixSets { get; } = new Dictionary<string, WmtsTileMatrixSet>();
|
||||||
|
|
||||||
protected override Size MeasureOverride(Size availableSize)
|
protected override Size MeasureOverride(Size availableSize)
|
||||||
{
|
{
|
||||||
foreach (var layer in Children.Cast<WmtsTileMatrixLayer>())
|
foreach (var layer in ChildLayers)
|
||||||
{
|
{
|
||||||
layer.Measure(availableSize);
|
layer.Measure(availableSize);
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +69,7 @@ namespace MapControl
|
||||||
|
|
||||||
protected override Size ArrangeOverride(Size finalSize)
|
protected override Size ArrangeOverride(Size finalSize)
|
||||||
{
|
{
|
||||||
foreach (var layer in Children.Cast<WmtsTileMatrixLayer>())
|
foreach (var layer in ChildLayers)
|
||||||
{
|
{
|
||||||
layer.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
|
layer.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +102,7 @@ namespace MapControl
|
||||||
|
|
||||||
protected override void SetRenderTransform()
|
protected override void SetRenderTransform()
|
||||||
{
|
{
|
||||||
foreach (var layer in Children.Cast<WmtsTileMatrixLayer>())
|
foreach (var layer in ChildLayers)
|
||||||
{
|
{
|
||||||
layer.SetRenderTransform(ParentMap.MapProjection);
|
layer.SetRenderTransform(ParentMap.MapProjection);
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +113,7 @@ namespace MapControl
|
||||||
var layersChanged = false;
|
var layersChanged = false;
|
||||||
var maxScale = 1.001 * ParentMap.MapProjection.ViewportScale; // avoid rounding issues
|
var maxScale = 1.001 * ParentMap.MapProjection.ViewportScale; // avoid rounding issues
|
||||||
|
|
||||||
// show all TileMatrix layers with Scale <= maxScale, or at least the first layer
|
// show all TileMatrix layers with Scale <= maxScale, at least the first layer
|
||||||
//
|
//
|
||||||
var currentMatrixes = tileMatrixSet.TileMatrixes
|
var currentMatrixes = tileMatrixSet.TileMatrixes
|
||||||
.Where((matrix, i) => i == 0 || matrix.Scale <= maxScale)
|
.Where((matrix, i) => i == 0 || matrix.Scale <= maxScale)
|
||||||
|
|
@ -121,9 +128,7 @@ namespace MapControl
|
||||||
currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - MaxBackgroundLevels - 1).ToList();
|
currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - MaxBackgroundLevels - 1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentLayers = Children.Cast<WmtsTileMatrixLayer>()
|
var currentLayers = ChildLayers.Where(layer => currentMatrixes.Contains(layer.TileMatrix)).ToList();
|
||||||
.Where(layer => currentMatrixes.Contains(layer.TileMatrix))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
Children.Clear();
|
Children.Clear();
|
||||||
|
|
||||||
|
|
@ -152,7 +157,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var tiles = new List<Tile>();
|
var tiles = new List<Tile>();
|
||||||
|
|
||||||
foreach (var layer in Children.Cast<WmtsTileMatrixLayer>())
|
foreach (var layer in ChildLayers)
|
||||||
{
|
{
|
||||||
layer.UpdateTiles();
|
layer.UpdateTiles();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
public WmtsTileMatrix TileMatrix { get; }
|
public WmtsTileMatrix TileMatrix { get; }
|
||||||
public int ZoomLevel { get; }
|
public int ZoomLevel { get; } // index of TileMatrix in WmtsTileMatrixSet.TileMatrixes
|
||||||
|
|
||||||
public int XMin { get; private set; }
|
public int XMin { get; private set; }
|
||||||
public int YMin { get; private set; }
|
public int YMin { get; private set; }
|
||||||
public int XMax { get; private set; }
|
public int XMax { get; private set; }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue