mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Simplified DispatcherTimer wrapper
This commit is contained in:
parent
4ec73292c3
commit
d83493a498
|
|
@ -19,7 +19,6 @@ using Windows.UI.Xaml.Media;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Hosting;
|
using Microsoft.UI.Xaml.Hosting;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
@ -192,15 +191,15 @@ namespace MapControl
|
||||||
|
|
||||||
protected bool IsBaseMapLayer => parentMap != null && parentMap.Children.Count > 0 && parentMap.Children[0] == this;
|
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)
|
protected Task LoadTilesAsync(IEnumerable<Tile> tiles, string cacheName)
|
||||||
{
|
{
|
||||||
return TileImageLoader.LoadTilesAsync(tiles, TileSource, cacheName, loadingProgress);
|
return TileImageLoader.LoadTilesAsync(tiles, TileSource, cacheName, loadingProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void SetRenderTransform();
|
||||||
|
|
||||||
|
protected abstract Task UpdateTileLayerAsync(bool tileSourceChanged);
|
||||||
|
|
||||||
private Task UpdateTileLayer(bool tileSourceChanged)
|
private Task UpdateTileLayer(bool tileSourceChanged)
|
||||||
{
|
{
|
||||||
updateTimer.Stop();
|
updateTimer.Stop();
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,10 @@ namespace MapControl
|
||||||
/// Loads a tile ImageSource asynchronously from an encoded frame buffer in a byte array.
|
/// Loads a tile ImageSource asynchronously from an encoded frame buffer in a byte array.
|
||||||
/// This method is called by TileImageLoader when caching is enabled.
|
/// This method is called by TileImageLoader when caching is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Task<ImageSource> LoadImageAsync(byte[] buffer) => ImageLoader.LoadImageAsync(buffer);
|
public virtual Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||||
|
{
|
||||||
|
return ImageLoader.LoadImageAsync(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a TileSource instance from an Uri template string.
|
/// Creates a TileSource instance from an Uri template string.
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,30 @@
|
||||||
// Copyright © Clemens Fischer
|
// Copyright © Clemens Fischer
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System;
|
|
||||||
#if WPF
|
#if WPF
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
#elif UWP
|
#elif UWP
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
|
#elif WINUI
|
||||||
|
global using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
#endif
|
#endif
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
internal static class Timer
|
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)
|
public static void Run(this DispatcherTimer timer, bool restart = false)
|
||||||
|
|
@ -25,8 +34,11 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
}
|
}
|
||||||
|
#if WINUI
|
||||||
|
if (!timer.IsRunning)
|
||||||
|
#else
|
||||||
if (!timer.IsEnabled)
|
if (!timer.IsEnabled)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
timer.Start();
|
timer.Start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="..\Shared\Timer.cs" />
|
|
||||||
<Compile Remove="..\Shared\TypeConverters.cs" />
|
<Compile Remove="..\Shared\TypeConverters.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,10 @@ namespace MapControl
|
||||||
public double Width { get; }
|
public double Width { get; }
|
||||||
public double Height { get; }
|
public double Height { get; }
|
||||||
|
|
||||||
public bool Contains(Point p) => p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height;
|
public bool Contains(Point p)
|
||||||
|
{
|
||||||
|
return p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height;
|
||||||
|
}
|
||||||
|
|
||||||
public static implicit operator Windows.Foundation.Rect(Rect r)
|
public static implicit operator Windows.Foundation.Rect(Rect r)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
||||||
// Copyright © Clemens Fischer
|
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
|
||||||
|
|
||||||
using Microsoft.UI.Dispatching;
|
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
internal static class Timer
|
|
||||||
{
|
|
||||||
public static DispatcherQueueTimer CreateTimer(this DependencyObject obj, TimeSpan interval)
|
|
||||||
{
|
|
||||||
var timer = obj.DispatcherQueue.CreateTimer();
|
|
||||||
timer.Interval = interval;
|
|
||||||
return timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Run(this DispatcherQueueTimer timer, bool restart = false)
|
|
||||||
{
|
|
||||||
if (restart)
|
|
||||||
{
|
|
||||||
timer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timer.IsRunning)
|
|
||||||
{
|
|
||||||
timer.Start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue