mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Simplified DispatcherTimer wrapper
This commit is contained in:
parent
4ec73292c3
commit
d83493a498
7 changed files with 28 additions and 46 deletions
|
|
@ -19,7 +19,6 @@ using Windows.UI.Xaml.Media;
|
|||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ using Microsoft.UI.Xaml;
|
|||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Hosting;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -192,15 +191,15 @@ namespace MapControl
|
|||
|
||||
protected bool IsBaseMapLayer => parentMap != null && parentMap.Children.Count > 0 && parentMap.Children[0] == this;
|
||||
|
||||
protected abstract void SetRenderTransform();
|
||||
|
||||
protected abstract Task UpdateTileLayerAsync(bool tileSourceChanged);
|
||||
|
||||
protected Task LoadTilesAsync(IEnumerable<Tile> tiles, string cacheName)
|
||||
{
|
||||
return TileImageLoader.LoadTilesAsync(tiles, TileSource, cacheName, loadingProgress);
|
||||
}
|
||||
|
||||
protected abstract void SetRenderTransform();
|
||||
|
||||
protected abstract Task UpdateTileLayerAsync(bool tileSourceChanged);
|
||||
|
||||
private Task UpdateTileLayer(bool tileSourceChanged)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
|
|
|
|||
|
|
@ -88,7 +88,10 @@ namespace MapControl
|
|||
/// Loads a tile ImageSource asynchronously from an encoded frame buffer in a byte array.
|
||||
/// This method is called by TileImageLoader when caching is enabled.
|
||||
/// </summary>
|
||||
public virtual Task<ImageSource> LoadImageAsync(byte[] buffer) => ImageLoader.LoadImageAsync(buffer);
|
||||
public virtual Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return ImageLoader.LoadImageAsync(buffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a TileSource instance from an Uri template string.
|
||||
|
|
|
|||
|
|
@ -2,21 +2,30 @@
|
|||
// Copyright © Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
#elif WINUI
|
||||
global using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||
using Microsoft.UI.Xaml;
|
||||
#endif
|
||||
using System;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
internal static class Timer
|
||||
{
|
||||
public static DispatcherTimer CreateTimer(this DependencyObject _, TimeSpan interval)
|
||||
public static DispatcherTimer CreateTimer(this DependencyObject obj, TimeSpan interval)
|
||||
{
|
||||
return new DispatcherTimer { Interval = interval };
|
||||
#if WINUI
|
||||
var timer = obj.DispatcherQueue.CreateTimer();
|
||||
#else
|
||||
var timer = new DispatcherTimer();
|
||||
#endif
|
||||
timer.Interval = interval;
|
||||
return timer;
|
||||
}
|
||||
|
||||
public static void Run(this DispatcherTimer timer, bool restart = false)
|
||||
|
|
@ -25,8 +34,11 @@ namespace MapControl
|
|||
{
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
#if WINUI
|
||||
if (!timer.IsRunning)
|
||||
#else
|
||||
if (!timer.IsEnabled)
|
||||
#endif
|
||||
{
|
||||
timer.Start();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue