diff --git a/MapControl/Shared/BoundingBox.cs b/MapControl/Shared/BoundingBox.cs index 4c373bac..49ff5d4a 100644 --- a/MapControl/Shared/BoundingBox.cs +++ b/MapControl/Shared/BoundingBox.cs @@ -10,26 +10,21 @@ namespace MapControl /// /// A geographic bounding box with south and north latitude and west and east longitude values in degrees. /// -#if !UWP +#if WINUI || UWP + [Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.BoundingBox.Parse")] +#else [System.ComponentModel.TypeConverter(typeof(BoundingBoxConverter))] #endif public class BoundingBox { - private double south; - private double north; - public BoundingBox() { - south = double.NaN; - north = double.NaN; - West = double.NaN; - East = double.NaN; } public BoundingBox(double latitude1, double longitude1, double latitude2, double longitude2) { - South = Math.Min(latitude1, latitude2); - North = Math.Max(latitude1, latitude2); + South = Math.Min(Math.Max(Math.Min(latitude1, latitude2), -90d), 90d); + North = Math.Min(Math.Max(Math.Max(latitude1, latitude2), -90d), 90d); West = Math.Min(longitude1, longitude2); East = Math.Max(longitude1, longitude2); } @@ -39,28 +34,15 @@ namespace MapControl { } - public double South - { - get => south; - set => south = Math.Min(Math.Max(value, -90d), 90d); - } - - public double North - { - get => north; - set => north = Math.Min(Math.Max(value, -90d), 90d); - } - - public double West { get; set; } - public double East { get; set; } + public double South { get; } + public double North { get; } + public double West { get; } + public double East { get; } public virtual double Width => East - West; public virtual double Height => North - South; - public virtual Location Center => - HasValidBounds ? new Location((South + North) / 2d, (West + East) / 2d) : null; - - public virtual bool HasValidBounds => South < North && West < East; + public virtual Location Center => new Location((South + North) / 2d, (West + East) / 2d); public static BoundingBox Parse(string boundingBox) { diff --git a/MapControl/Shared/CenteredBoundingBox.cs b/MapControl/Shared/CenteredBoundingBox.cs index 5639901d..33799812 100644 --- a/MapControl/Shared/CenteredBoundingBox.cs +++ b/MapControl/Shared/CenteredBoundingBox.cs @@ -19,7 +19,6 @@ namespace MapControl height = Math.Max(h, 0d); } - public override bool HasValidBounds => false; public override Location Center => center; public override double Width => width; public override double Height => height; diff --git a/MapControl/Shared/LocationCollection.cs b/MapControl/Shared/LocationCollection.cs index d59f57a4..925274fa 100644 --- a/MapControl/Shared/LocationCollection.cs +++ b/MapControl/Shared/LocationCollection.cs @@ -12,7 +12,9 @@ namespace MapControl /// A collection of Locations with support for string parsing /// and calculation of great circle and rhumb line locations. /// -#if !UWP +#if WINUI || UWP + [Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.LocationCollection.Parse")] +#else [System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))] #endif public class LocationCollection : List diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index e69c8da3..07c24f3f 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -71,7 +71,7 @@ namespace MapControl { MapRect mapRect = null; - if (boundingBox.HasValidBounds) + if (boundingBox.South < boundingBox.North && boundingBox.West < boundingBox.East) { var p1 = LocationToMap(new Location(boundingBox.South, boundingBox.West)); var p2 = LocationToMap(new Location(boundingBox.North, boundingBox.East)); diff --git a/MapControl/Shared/TileSource.cs b/MapControl/Shared/TileSource.cs index 427c6828..cc60f285 100644 --- a/MapControl/Shared/TileSource.cs +++ b/MapControl/Shared/TileSource.cs @@ -17,7 +17,9 @@ namespace MapControl /// /// Provides the download Uri or ImageSource of map tiles. /// -#if !UWP +#if WINUI || UWP + [Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.TileSource.Parse")] +#else [System.ComponentModel.TypeConverter(typeof(TileSourceConverter))] #endif public class TileSource @@ -81,6 +83,11 @@ namespace MapControl return uri != null ? ImageLoader.LoadImageAsync(uri) : Task.FromResult((ImageSource)null); } + + public static TileSource Parse(string uriTemplate) + { + return new TileSource { UriTemplate = uriTemplate }; + } } public class TmsTileSource : TileSource diff --git a/MapControl/Shared/TypeConverters.cs b/MapControl/Shared/TypeConverters.cs index 56f8d9c4..21116754 100644 --- a/MapControl/Shared/TypeConverters.cs +++ b/MapControl/Shared/TypeConverters.cs @@ -56,7 +56,7 @@ namespace MapControl public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - return new TileSource { UriTemplate = (string)value }; + return TileSource.Parse((string)value); } } } diff --git a/SampleApps/UniversalApp/MainPage.xaml b/SampleApps/UniversalApp/MainPage.xaml index 36350d9c..a76b1066 100644 --- a/SampleApps/UniversalApp/MainPage.xaml +++ b/SampleApps/UniversalApp/MainPage.xaml @@ -160,55 +160,43 @@ Map="{Binding ElementName=map}"> - - - - + Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> + Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)"/> + ServiceUri="https://sgx.geodatenzentrum.de/wms_topplus_open" + Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)"/> + ServiceUri="http://ows.terrestris.de/osm/service" + Description="© [terrestris GmbH & Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> @@ -218,18 +206,13 @@ - - - - - + - - - - - + diff --git a/SampleApps/WinUiApp/MainWindow.xaml b/SampleApps/WinUiApp/MainWindow.xaml index 5bf1b2e2..519c76cb 100644 --- a/SampleApps/WinUiApp/MainWindow.xaml +++ b/SampleApps/WinUiApp/MainWindow.xaml @@ -175,55 +175,43 @@ Map="{Binding ElementName=map}"> - - - - + Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> - - - - + Description="© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> + Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)"/> + ServiceUri="https://sgx.geodatenzentrum.de/wms_topplus_open" + Description="© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)"/> + ServiceUri="http://ows.terrestris.de/osm/service" + Description="© [terrestris GmbH & Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"/> @@ -233,18 +221,13 @@ - - - - - + - - - - - +