From e7aaa2ba22dc70eb9ca41bf1cb366d752d25cceb Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 30 Oct 2025 19:49:06 +0100 Subject: [PATCH] MapTileLayer/WmtsTileLayer --- MapControl/Shared/MapTileLayer.cs | 26 ++++++++++-------------- MapControl/Shared/MapTilePyramidLayer.cs | 16 +++++++-------- MapControl/Shared/WmtsTileLayer.cs | 11 +++++----- MapControl/Shared/WmtsTileMatrixLayer.cs | 2 +- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 7f39eec7..705fd4f2 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -115,37 +115,29 @@ namespace MapControl return finalSize; } - protected override void UpdateTiles(bool resetTiles) + protected override void UpdateTileCollection(bool reset) { if (ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId)) { TileMatrix = null; Children.Clear(); - CancelLoadTiles(); } - else if (SetTileMatrix() || resetTiles) + else if (SetTileMatrix() || reset) { - SetRenderTransform(); - - if (resetTiles) - { - Tiles.Clear(); - } - - UpdateTiles(); + UpdateRenderTransform(); + UpdateTiles(reset); BeginLoadTiles(Tiles, SourceName); } } - protected override void SetRenderTransform() + protected override void UpdateRenderTransform() { if (TileMatrix != null) { // Tile matrix origin in pixels. // var tileMatrixOrigin = new Point(TileSize * TileMatrix.XMin, TileSize * TileMatrix.YMin); - var tileMatrixScale = MapBase.ZoomLevelToScale(TileMatrix.ZoomLevel); ((MatrixTransform)RenderTransform).Matrix = @@ -158,7 +150,6 @@ namespace MapControl // Add 0.001 to avoid rounding issues. // var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001); - var tileMatrixScale = MapBase.ZoomLevelToScale(tileMatrixZoomLevel); // Bounds in tile pixels from view size. @@ -185,12 +176,17 @@ namespace MapControl return true; } - private void UpdateTiles() + private void UpdateTiles(bool reset) { var tiles = new TileCollection(); if (TileSource != null && TileMatrix != null) { + if (reset) + { + Tiles.Clear(); + } + var maxZoomLevel = Math.Min(TileMatrix.ZoomLevel, MaxZoomLevel); if (maxZoomLevel >= MinZoomLevel) diff --git a/MapControl/Shared/MapTilePyramidLayer.cs b/MapControl/Shared/MapTilePyramidLayer.cs index 23dd8bdb..a63a37f1 100644 --- a/MapControl/Shared/MapTilePyramidLayer.cs +++ b/MapControl/Shared/MapTilePyramidLayer.cs @@ -28,7 +28,7 @@ namespace MapControl { public static readonly DependencyProperty TileSourceProperty = DependencyPropertyHelper.Register(nameof(TileSource), null, - (layer, oldValue, newValue) => layer.Update(true)); + (layer, oldValue, newValue) => layer.UpdateTiles(true)); public static readonly DependencyProperty SourceNameProperty = DependencyPropertyHelper.Register(nameof(SourceName)); @@ -67,7 +67,7 @@ namespace MapControl loadingProgress = new Progress(p => SetValue(LoadingProgressProperty, p)); updateTimer = new UpdateTimer { Interval = UpdateInterval }; - updateTimer.Tick += (s, e) => Update(false); + updateTimer.Tick += (s, e) => UpdateTiles(); MapPanel.SetRenderTransform(this, new MatrixTransform()); #if WPF @@ -205,25 +205,25 @@ namespace MapControl ClearValue(LoadingProgressProperty); } - protected abstract void SetRenderTransform(); + protected abstract void UpdateRenderTransform(); - protected abstract void UpdateTiles(bool resetTiles); + protected abstract void UpdateTileCollection(bool reset); - private void Update(bool resetTiles) + private void UpdateTiles(bool reset = false) { updateTimer.Stop(); - UpdateTiles(resetTiles); + UpdateTileCollection(reset); } private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { if (e.TransformCenterChanged || e.ProjectionChanged || Children.Count == 0) { - Update(false); // update immediately + UpdateTiles(); // update immediately } else { - SetRenderTransform(); + UpdateRenderTransform(); updateTimer.Run(!UpdateWhileViewportChanging); } } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 13267154..1550a701 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -100,15 +100,14 @@ namespace MapControl return finalSize; } - protected override void UpdateTiles(bool resetTiles) + protected override void UpdateTileCollection(bool reset) { - // resetTiles is ignored here because it is always false. + // reset parameter is ignored here because it is always false. if (ParentMap == null || !TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet)) { Children.Clear(); - CancelLoadTiles(); } else if (UpdateChildLayers(tileMatrixSet)) @@ -134,11 +133,11 @@ namespace MapControl } } - protected override void SetRenderTransform() + protected override void UpdateRenderTransform() { foreach (var layer in ChildLayers) { - layer.SetRenderTransform(ParentMap.ViewTransform); + layer.UpdateRenderTransform(ParentMap.ViewTransform); } } @@ -182,7 +181,7 @@ namespace MapControl tilesChanged = true; } - layer.SetRenderTransform(ParentMap.ViewTransform); + layer.UpdateRenderTransform(ParentMap.ViewTransform); Children.Add(layer); } diff --git a/MapControl/Shared/WmtsTileMatrixLayer.cs b/MapControl/Shared/WmtsTileMatrixLayer.cs index 621da874..bb5d569f 100644 --- a/MapControl/Shared/WmtsTileMatrixLayer.cs +++ b/MapControl/Shared/WmtsTileMatrixLayer.cs @@ -37,7 +37,7 @@ namespace MapControl public TileCollection Tiles { get; private set; } = []; - public void SetRenderTransform(ViewTransform viewTransform) + public void UpdateRenderTransform(ViewTransform viewTransform) { // Tile matrix origin in pixels. //