From d859a9c4f95b17564586fc1b91f68fed3f12e76a Mon Sep 17 00:00:00 2001 From: ClemensF Date: Tue, 14 Aug 2018 23:13:58 +0200 Subject: [PATCH] Version 4.10.0: Updated target framework versions. Cleanup of TypeConverters, ImageLoader, MBTileSource. --- MapControl/Shared/ImageLoader.cs | 2 +- MapControl/Shared/MapTileLayer.cs | 4 +- MapControl/UWP/Tile.UWP.cs | 6 +- MapControl/WPF/Tile.WPF.cs | 6 +- SampleApps/Shared/MapLayers.cs | 83 ++++++++++++++++++-- SampleApps/UniversalApp/MainPage.xaml.cs | 33 +++++++- SampleApps/WpfApplication/MainWindow.xaml.cs | 3 +- 7 files changed, 123 insertions(+), 14 deletions(-) diff --git a/MapControl/Shared/ImageLoader.cs b/MapControl/Shared/ImageLoader.cs index fc2320dc..5b0f401e 100644 --- a/MapControl/Shared/ImageLoader.cs +++ b/MapControl/Shared/ImageLoader.cs @@ -34,7 +34,7 @@ namespace MapControl { imageSource = await LoadLocalImageAsync(uri); } - else if (uri.Scheme == "http") + else if (uri.Scheme == "http" || uri.Scheme == "https") { imageSource = await LoadHttpImageAsync(uri); } diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index d9ca85a2..676cb21b 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -41,7 +41,7 @@ namespace MapControl { SourceName = "OpenStreetMap", Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)", - TileSource = new TileSource { UriFormat = "http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png" }, + TileSource = new TileSource { UriFormat = "https://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png" }, MaxZoomLevel = 19 }; } @@ -374,7 +374,7 @@ namespace MapControl if (equivalentTile != null) { - tile.SetImage(equivalentTile.Image.Source, false); // do not animate to avoid flicker when crossing 180° longitude + tile.SetImage(equivalentTile.Image.Source, false); // no fade-in animation } } diff --git a/MapControl/UWP/Tile.UWP.cs b/MapControl/UWP/Tile.UWP.cs index e0b2aeb4..a8366a53 100644 --- a/MapControl/UWP/Tile.UWP.cs +++ b/MapControl/UWP/Tile.UWP.cs @@ -28,7 +28,8 @@ namespace MapControl } else { - Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { To = 1d, Duration = FadeDuration }); + Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { From = 0d, To = 1d, Duration = FadeDuration, FillBehavior = FillBehavior.Stop }); + Image.Opacity = 1d; } } else @@ -46,7 +47,8 @@ namespace MapControl bitmapImage.ImageOpened -= BitmapImageOpened; bitmapImage.ImageFailed -= BitmapImageFailed; - Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { To = 1d, Duration = FadeDuration }); + Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { From = 0d, To = 1d, Duration = FadeDuration, FillBehavior = FillBehavior.Stop }); + Image.Opacity = 1d; } private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e) diff --git a/MapControl/WPF/Tile.WPF.cs b/MapControl/WPF/Tile.WPF.cs index 27b1663b..09ddd05c 100644 --- a/MapControl/WPF/Tile.WPF.cs +++ b/MapControl/WPF/Tile.WPF.cs @@ -28,7 +28,8 @@ namespace MapControl } else { - Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1d, FadeDuration)); + Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0d, 1d, FadeDuration, FillBehavior.Stop)); + Image.Opacity = 1d; } } else @@ -46,7 +47,8 @@ namespace MapControl bitmapSource.DownloadCompleted -= BitmapDownloadCompleted; bitmapSource.DownloadFailed -= BitmapDownloadFailed; - Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1d, FadeDuration)); + Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0d, 1d, FadeDuration, FillBehavior.Stop)); + Image.Opacity = 1d; } private void BitmapDownloadFailed(object sender, ExceptionEventArgs e) diff --git a/SampleApps/Shared/MapLayers.cs b/SampleApps/Shared/MapLayers.cs index 870e4a63..6b4518ef 100644 --- a/SampleApps/Shared/MapLayers.cs +++ b/SampleApps/Shared/MapLayers.cs @@ -23,6 +23,20 @@ namespace ViewModel "OpenStreetMap", MapTileLayer.OpenStreetMapTileLayer }, + { + "OpenStreetMap Files", + new MapTileLayer + { + SourceName = "OpenStreetMap Files", + Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)", +#if WINDOWS_UWP + TileSource = new TileSource { UriFormat = @"C:\Users\Clemens\AppData\Local\Packages\XamlMapControl.UniversalApp_2kan67jdewwkc\TempState\OpenStreetMap\{z}\{x}\{y}.png" }, +#else + TileSource = new TileSource { UriFormat = @"C:\ProgramData\MapControl\TileCache\OpenStreetMap\{z}\{x}\{y}.png" }, +#endif + MaxZoomLevel = 19 + } + }, { "OpenStreetMap German", new MapTileLayer @@ -118,10 +132,54 @@ namespace ViewModel { Description = "© [SevenCs GmbH](http://www.sevencs.com)", ServiceUri = new Uri("http://chartserver4.sevencs.com:8080"), - Layers = "ENC", - MaxBoundingBoxWidth = 360 + Layers = "ENC" } - } + }, + { + "ECDIS DAY_BRIGHT", + new WmsImageLayer + { + Description = "ECDIS WMS DAY_BRIGHT", + ServiceUri = new Uri("http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=0&DETAILS=2") + } + }, + { + "ECDIS DAY_WHITEBACK", + new WmsImageLayer + { + Description = "ECDIS WMS DAY_WHITEBACK", + ServiceUri = new Uri("http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=1&DETAILS=2") + } + }, + { + "ECDIS DAY_BLACKBACK", + new WmsImageLayer + { + Description = "ECDIS WMS DAY_BLACKBACK", + ServiceUri = new Uri("http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=2&DETAILS=2"), + MapForeground = new SolidColorBrush(Colors.White) + } + }, + { + "ECDIS DUSK", + new WmsImageLayer + { + Description = "ECDIS WMS DUSK", + ServiceUri = new Uri("http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=3&DETAILS=2"), + MapForeground = new SolidColorBrush(Colors.Gray), + MapBackground = new SolidColorBrush(Colors.Black) + } + }, + { + "ECDIS NIGHT", + new WmsImageLayer + { + Description = "ECDIS WMS NIGHT", + ServiceUri = new Uri("http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=4&DETAILS=2"), + MapForeground = new SolidColorBrush(Colors.Gray), + MapBackground = new SolidColorBrush(Colors.Black) + } + }, }; private string currentMapLayerName = "OpenStreetMap"; @@ -150,17 +208,23 @@ namespace ViewModel public List MapLayerNames { get; } = new List { "OpenStreetMap", + "OpenStreetMap Files", "OpenStreetMap German", "Stamen Terrain", "Stamen Toner Light", "OpenStreetMap WMS", "OpenStreetMap TOPO WMS", - "SevenCs ChartServer" + "SevenCs ChartServer", + "ECDIS DAY_BRIGHT", + "ECDIS DAY_WHITEBACK", + "ECDIS DAY_BLACKBACK", + "ECDIS DUSK", + "ECDIS NIGHT", }; public MapLayers() { - //BingMapsTileLayer.ApiKey = "..."; + BingMapsTileLayer.ApiKey = ""; // Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service // (see http://msdn.microsoft.com/en-us/library/ff701716.aspx). @@ -173,6 +237,15 @@ namespace ViewModel MapLayerNames.Add("Bing Maps Aerial"); MapLayerNames.Add("Bing Maps Aerial with Labels"); } + + //var t = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; + //t.Tick += async (s, e) => + //{ + // var layers = await ((WmsImageLayer)mapLayers["OpenStreetMap WMS"]).GetLayerNamesAsync(); + // System.Diagnostics.Debug.WriteLine(string.Join(", ", layers)); + // t.Stop(); + //}; + //t.Start(); } } } diff --git a/SampleApps/UniversalApp/MainPage.xaml.cs b/SampleApps/UniversalApp/MainPage.xaml.cs index c44aafe2..6b104b39 100644 --- a/SampleApps/UniversalApp/MainPage.xaml.cs +++ b/SampleApps/UniversalApp/MainPage.xaml.cs @@ -1,9 +1,11 @@ using MapControl; using MapControl.Caching; using ViewModel; +using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Media; namespace UniversalApp { @@ -13,11 +15,40 @@ namespace UniversalApp public MainPage() { - //TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder); + TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder); InitializeComponent(); DataContext = ViewModel; + + for (var x = -180d; x < 180d; x += 15d) + { + var location = new Location(0d, x); + + var locations = new LocationCollection + { + new Location(0, x - 5), + new Location(5, x), + new Location(0, x + 5), + new Location(-5, x) + }; + + map.Children.Add(new MapPolygon + { + Fill = new SolidColorBrush(Colors.Red) { Opacity = 0.25 }, + Stroke = new SolidColorBrush(Colors.Red), + StrokeThickness = 2, + StrokeLineJoin = PenLineJoin.Round, + Locations = locations, + Location = location, + }); + + map.Children.Add(new Pushpin + { + Content = x, + Location = location, + }); + } } private void ImageOpacitySliderValueChanged(object sender, RangeBaseValueChangedEventArgs e) diff --git a/SampleApps/WpfApplication/MainWindow.xaml.cs b/SampleApps/WpfApplication/MainWindow.xaml.cs index 6301684a..645d6974 100644 --- a/SampleApps/WpfApplication/MainWindow.xaml.cs +++ b/SampleApps/WpfApplication/MainWindow.xaml.cs @@ -11,8 +11,9 @@ namespace WpfApplication { public MainWindow() { - //TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder); + TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder); + //TileImageLoader.Cache = null; InitializeComponent(); }