Updated MapTileLayerBase

This commit is contained in:
ClemensF 2020-10-26 21:59:51 +01:00
parent 555fbc698f
commit 6435ee462a
3 changed files with 28 additions and 28 deletions

View file

@ -60,7 +60,7 @@ namespace MapControl
public TileMatrix TileMatrix { get; private set; }
public IReadOnlyCollection<Tile> Tiles { get; private set; } = new List<Tile>();
public List<Tile> Tiles { get; private set; } = new List<Tile>();
/// <summary>
/// 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<Tile>();
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();
}
}

View file

@ -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();
}
}

View file

@ -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))