From 7c5eb04c9e034844ba11397a916e113284abf4f3 Mon Sep 17 00:00:00 2001 From: Clemens Date: Sun, 24 Apr 2022 19:34:02 +0200 Subject: [PATCH] Update MapTileLayer.cs --- MapControl/Shared/MapTileLayer.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 6daa411e..8f1a9edd 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -26,9 +26,9 @@ namespace MapControl /// public class MapTileLayer : MapTileLayerBase { - public const int TileSize = 256; + private const int TileSize = 256; - public static readonly Point MapTopLeft = new Point( + private static readonly Point MapTopLeft = new Point( -180d * MapProjection.Wgs84MeterPerDegree, 180d * MapProjection.Wgs84MeterPerDegree); /// @@ -53,6 +53,9 @@ namespace MapControl public static readonly DependencyProperty MaxZoomLevelProperty = DependencyProperty.Register( nameof(MaxZoomLevel), typeof(int), typeof(MapTileLayer), new PropertyMetadata(19)); + public static readonly DependencyProperty ZoomLevelOffsetProperty = DependencyProperty.Register( + nameof(ZoomLevelOffset), typeof(double), typeof(MapTileLayer), new PropertyMetadata(0d)); + public MapTileLayer() : this(new TileImageLoader()) { @@ -85,6 +88,16 @@ namespace MapControl set { SetValue(MaxZoomLevelProperty, value); } } + /// + /// Optional offset between the map zoom level and the topmost tile zoom level. + /// Default value is 0. + /// + public double ZoomLevelOffset + { + get { return (double)GetValue(ZoomLevelOffsetProperty); } + set { SetValue(ZoomLevelOffsetProperty, value); } + } + protected override Size MeasureOverride(Size availableSize) { availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity); @@ -167,7 +180,7 @@ namespace MapControl private bool SetTileMatrix() { - var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel + 0.001); // avoid rounding issues + var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001); // avoid rounding issues var tileMatrixScale = ViewTransform.ZoomLevelToScale(tileMatrixZoomLevel);