mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added UpdateTimer class
This commit is contained in:
parent
579631dd9d
commit
3fcb91f2d9
|
|
@ -3,7 +3,7 @@
|
|||
<Product>XAML Map Control</Product>
|
||||
<Authors>Clemens Fischer</Authors>
|
||||
<Copyright>Copyright © 2025 Clemens Fischer</Copyright>
|
||||
<Version>14.0.0</Version>
|
||||
<Version>14.1.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace MapControl
|
|||
DependencyPropertyHelper.Register<MapImageLayer, double>(nameof(LoadingProgress), 1d);
|
||||
|
||||
private readonly Progress<double> loadingProgress;
|
||||
private readonly DispatcherTimer updateTimer;
|
||||
private readonly UpdateTimer updateTimer;
|
||||
private bool updateInProgress;
|
||||
|
||||
public MapImageLayer()
|
||||
|
|
@ -62,7 +62,7 @@ namespace MapControl
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -164,15 +164,7 @@ namespace MapControl
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!UpdateWhileViewportChanging)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
}
|
||||
|
||||
if (!updateTimer.IsEnabled)
|
||||
{
|
||||
updateTimer.Start();
|
||||
}
|
||||
updateTimer.Run(!UpdateWhileViewportChanging);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,9 +199,9 @@ namespace MapControl
|
|||
|
||||
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);
|
||||
|
||||
private readonly Progress<double> loadingProgress;
|
||||
private readonly DispatcherTimer updateTimer;
|
||||
private readonly UpdateTimer updateTimer;
|
||||
private ITileImageLoader tileImageLoader;
|
||||
private MapBase parentMap;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ namespace MapControl
|
|||
|
||||
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
||||
|
||||
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
||||
updateTimer = new UpdateTimer { Interval = UpdateInterval };
|
||||
updateTimer.Tick += (s, e) => Update(false);
|
||||
|
||||
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
||||
|
|
@ -185,10 +185,7 @@ namespace MapControl
|
|||
parentMap.ViewportChanged += OnViewportChanged;
|
||||
}
|
||||
|
||||
if (!updateTimer.IsEnabled)
|
||||
{
|
||||
updateTimer.Start();
|
||||
}
|
||||
updateTimer.Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +204,6 @@ namespace MapControl
|
|||
protected void CancelLoadTiles()
|
||||
{
|
||||
TileImageLoader.CancelLoadTiles();
|
||||
|
||||
ClearValue(LoadingProgressProperty);
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +214,6 @@ namespace MapControl
|
|||
private void Update(bool resetTiles)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
|
||||
UpdateTiles(resetTiles);
|
||||
}
|
||||
|
||||
|
|
@ -231,16 +226,7 @@ namespace MapControl
|
|||
else
|
||||
{
|
||||
SetRenderTransform();
|
||||
|
||||
if (!UpdateWhileViewportChanging)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
}
|
||||
|
||||
if (!updateTimer.IsEnabled)
|
||||
{
|
||||
updateTimer.Start();
|
||||
}
|
||||
updateTimer.Run(!UpdateWhileViewportChanging);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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