diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 1a851743..1f97e7e5 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -60,7 +60,7 @@ namespace MapControl public TileMatrix TileMatrix { get; private set; } - public IReadOnlyCollection Tiles { get; private set; } = new List(); + public List Tiles { get; private set; } = new List(); /// /// Minimum zoom level supported by the MapTileLayer. Default value is 0. @@ -80,25 +80,32 @@ namespace MapControl set { SetValue(MaxZoomLevelProperty, value); } } - protected override void TileSourcePropertyChanged() + protected override void UpdateTileLayer(bool tileSourceChanged) { - if (TileMatrix != null) - { - Tiles = new List(); - UpdateTiles(); - } - } + var update = false; - protected override void UpdateTileLayer() - { if (ParentMap == null || !ParentMap.MapProjection.IsWebMercator) { TileMatrix = null; - UpdateTiles(); + update = true; } - else if (SetTileMatrix()) + else + { + if (tileSourceChanged) + { + Tiles.Clear(); + update = true; + } + + if (SetTileMatrix()) + { + SetRenderTransform(); + update = true; + } + } + + if (update) { - SetRenderTransform(); UpdateTiles(); } } diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index 8d6bfc05..dd5766ca 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -26,7 +26,7 @@ namespace MapControl { public static readonly DependencyProperty TileSourceProperty = DependencyProperty.Register( nameof(TileSource), typeof(TileSource), typeof(MapTileLayerBase), - new PropertyMetadata(null, (o, e) => ((MapTileLayerBase)o).TileSourcePropertyChanged())); + new PropertyMetadata(null, (o, e) => ((MapTileLayerBase)o).Update(true))); public static readonly DependencyProperty SourceNameProperty = DependencyProperty.Register( nameof(SourceName), typeof(string), typeof(MapTileLayerBase), new PropertyMetadata(null)); @@ -59,7 +59,7 @@ namespace MapControl TileImageLoader = tileImageLoader; updateTimer = new DispatcherTimer { Interval = UpdateInterval }; - updateTimer.Tick += (s, e) => Update(); + updateTimer.Tick += (s, e) => Update(false); MapPanel.InitMapElement(this); } @@ -156,7 +156,7 @@ namespace MapControl parentMap.ViewportChanged += OnViewportChanged; } - Update(); + Update(false); } } @@ -164,7 +164,7 @@ namespace MapControl { if (Children.Count == 0 || e.ProjectionChanged || Math.Abs(e.LongitudeOffset) > 180d) { - Update(); // update immediately when projection has changed or center has moved across 180° longitude + Update(false); // update immediately when projection has changed or center has moved across 180° longitude } else { @@ -182,17 +182,15 @@ namespace MapControl } } - private void Update() + private void Update(bool tileSourceChanged) { updateTimer.Stop(); - UpdateTileLayer(); + UpdateTileLayer(tileSourceChanged); } - protected abstract void UpdateTileLayer(); + protected abstract void UpdateTileLayer(bool tileSourceChanged); protected abstract void SetRenderTransform(); - - protected abstract void TileSourcePropertyChanged(); } } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index d7df2c6d..413616d1 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -83,12 +83,7 @@ namespace MapControl return finalSize; } - protected override void TileSourcePropertyChanged() - { - UpdateTileLayer(); - } - - protected override void UpdateTileLayer() + protected override void UpdateTileLayer(bool tileSourceChanged) { if (ParentMap == null || !TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet))