diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index f2bc1342..073343ea 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -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 diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index 5a63a1a9..d3f667bf 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -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 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(); diff --git a/MapControl/Shared/TileSource.cs b/MapControl/Shared/TileSource.cs index fabda3e3..339b87d1 100644 --- a/MapControl/Shared/TileSource.cs +++ b/MapControl/Shared/TileSource.cs @@ -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. /// - public virtual Task LoadImageAsync(byte[] buffer) => ImageLoader.LoadImageAsync(buffer); + public virtual Task LoadImageAsync(byte[] buffer) + { + return ImageLoader.LoadImageAsync(buffer); + } /// /// Creates a TileSource instance from an Uri template string. diff --git a/MapControl/Shared/Timer.cs b/MapControl/Shared/Timer.cs index 105bbc8e..a9fdaff1 100644 --- a/MapControl/Shared/Timer.cs +++ b/MapControl/Shared/Timer.cs @@ -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(); } diff --git a/MapControl/WinUI/MapControl.WinUI.csproj b/MapControl/WinUI/MapControl.WinUI.csproj index e2e7674a..3bb4a40c 100644 --- a/MapControl/WinUI/MapControl.WinUI.csproj +++ b/MapControl/WinUI/MapControl.WinUI.csproj @@ -17,7 +17,6 @@ - diff --git a/MapControl/WinUI/Rect.WinUI.cs b/MapControl/WinUI/Rect.WinUI.cs index 93ec561f..9273cfa4 100644 --- a/MapControl/WinUI/Rect.WinUI.cs +++ b/MapControl/WinUI/Rect.WinUI.cs @@ -32,7 +32,10 @@ namespace MapControl public double Width { 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) { diff --git a/MapControl/WinUI/Timer.WinUI.cs b/MapControl/WinUI/Timer.WinUI.cs deleted file mode 100644 index 23b12cda..00000000 --- a/MapControl/WinUI/Timer.WinUI.cs +++ /dev/null @@ -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(); - } - } - } -}