mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-03-26 23:26:16 +01:00
Added UpdateTimer class
This commit is contained in:
parent
579631dd9d
commit
3fcb91f2d9
|
|
@ -3,7 +3,7 @@
|
||||||
<Product>XAML Map Control</Product>
|
<Product>XAML Map Control</Product>
|
||||||
<Authors>Clemens Fischer</Authors>
|
<Authors>Clemens Fischer</Authors>
|
||||||
<Copyright>Copyright © 2025 Clemens Fischer</Copyright>
|
<Copyright>Copyright © 2025 Clemens Fischer</Copyright>
|
||||||
<Version>14.0.0</Version>
|
<Version>14.1.0</Version>
|
||||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||||
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace MapControl
|
||||||
DependencyPropertyHelper.Register<MapImageLayer, double>(nameof(LoadingProgress), 1d);
|
DependencyPropertyHelper.Register<MapImageLayer, double>(nameof(LoadingProgress), 1d);
|
||||||
|
|
||||||
private readonly Progress<double> loadingProgress;
|
private readonly Progress<double> loadingProgress;
|
||||||
private readonly DispatcherTimer updateTimer;
|
private readonly UpdateTimer updateTimer;
|
||||||
private bool updateInProgress;
|
private bool updateInProgress;
|
||||||
|
|
||||||
public MapImageLayer()
|
public MapImageLayer()
|
||||||
|
|
@ -62,7 +62,7 @@ namespace MapControl
|
||||||
|
|
||||||
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
||||||
|
|
||||||
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
updateTimer = new UpdateTimer { Interval = UpdateInterval };
|
||||||
updateTimer.Tick += async (s, e) => await UpdateImageAsync();
|
updateTimer.Tick += async (s, e) => await UpdateImageAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,15 +164,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!UpdateWhileViewportChanging)
|
updateTimer.Run(!UpdateWhileViewportChanging);
|
||||||
{
|
|
||||||
updateTimer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!updateTimer.IsEnabled)
|
|
||||||
{
|
|
||||||
updateTimer.Start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,9 +199,9 @@ namespace MapControl
|
||||||
|
|
||||||
updateInProgress = false;
|
updateInProgress = false;
|
||||||
}
|
}
|
||||||
else if (!updateTimer.IsEnabled) // update on next timer tick
|
else // update on next timer tick
|
||||||
{
|
{
|
||||||
updateTimer.Start();
|
updateTimer.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace MapControl
|
||||||
DependencyPropertyHelper.Register<MapTilePyramidLayer, double>(nameof(LoadingProgress), 1d);
|
DependencyPropertyHelper.Register<MapTilePyramidLayer, double>(nameof(LoadingProgress), 1d);
|
||||||
|
|
||||||
private readonly Progress<double> loadingProgress;
|
private readonly Progress<double> loadingProgress;
|
||||||
private readonly DispatcherTimer updateTimer;
|
private readonly UpdateTimer updateTimer;
|
||||||
private ITileImageLoader tileImageLoader;
|
private ITileImageLoader tileImageLoader;
|
||||||
private MapBase parentMap;
|
private MapBase parentMap;
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace MapControl
|
||||||
|
|
||||||
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
||||||
|
|
||||||
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
updateTimer = new UpdateTimer { Interval = UpdateInterval };
|
||||||
updateTimer.Tick += (s, e) => Update(false);
|
updateTimer.Tick += (s, e) => Update(false);
|
||||||
|
|
||||||
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
||||||
|
|
@ -185,10 +185,7 @@ namespace MapControl
|
||||||
parentMap.ViewportChanged += OnViewportChanged;
|
parentMap.ViewportChanged += OnViewportChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!updateTimer.IsEnabled)
|
updateTimer.Run();
|
||||||
{
|
|
||||||
updateTimer.Start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +204,6 @@ namespace MapControl
|
||||||
protected void CancelLoadTiles()
|
protected void CancelLoadTiles()
|
||||||
{
|
{
|
||||||
TileImageLoader.CancelLoadTiles();
|
TileImageLoader.CancelLoadTiles();
|
||||||
|
|
||||||
ClearValue(LoadingProgressProperty);
|
ClearValue(LoadingProgressProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +214,6 @@ namespace MapControl
|
||||||
private void Update(bool resetTiles)
|
private void Update(bool resetTiles)
|
||||||
{
|
{
|
||||||
updateTimer.Stop();
|
updateTimer.Stop();
|
||||||
|
|
||||||
UpdateTiles(resetTiles);
|
UpdateTiles(resetTiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,16 +226,7 @@ namespace MapControl
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetRenderTransform();
|
SetRenderTransform();
|
||||||
|
updateTimer.Run(!UpdateWhileViewportChanging);
|
||||||
if (!UpdateWhileViewportChanging)
|
|
||||||
{
|
|
||||||
updateTimer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!updateTimer.IsEnabled)
|
|
||||||
{
|
|
||||||
updateTimer.Start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
MapControl/Shared/UpdateTimer.cs
Normal file
28
MapControl/Shared/UpdateTimer.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#if WPF
|
||||||
|
using System.Windows.Threading;
|
||||||
|
#elif UWP
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
#elif WINUI
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
#elif AVALONIA
|
||||||
|
using Avalonia.Threading;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace MapControl
|
||||||
|
{
|
||||||
|
internal class UpdateTimer : DispatcherTimer
|
||||||
|
{
|
||||||
|
public void Run(bool restart = false)
|
||||||
|
{
|
||||||
|
if (restart)
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsEnabled)
|
||||||
|
{
|
||||||
|
Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue