mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Use C# 7
This commit is contained in:
parent
3ffb613f80
commit
310f0cca9a
|
|
@ -147,9 +147,7 @@ namespace MapControl.Caching
|
|||
throw new ArgumentNullException("The parameter key must not be null.");
|
||||
}
|
||||
|
||||
var imageCacheItem = value as ImageCacheItem;
|
||||
|
||||
if (imageCacheItem == null)
|
||||
if (!(value is ImageCacheItem imageCacheItem))
|
||||
{
|
||||
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,26 +57,23 @@ namespace MapControl.MBTiles
|
|||
if (file != null)
|
||||
{
|
||||
var tileData = await MBTileData.CreateAsync(file);
|
||||
int minZoom;
|
||||
int maxZoom;
|
||||
string s;
|
||||
|
||||
if (tileData.Metadata.TryGetValue("name", out s))
|
||||
if (tileData.Metadata.TryGetValue("name", out string sourceName))
|
||||
{
|
||||
SourceName = s;
|
||||
SourceName = sourceName;
|
||||
}
|
||||
|
||||
if (tileData.Metadata.TryGetValue("description", out s))
|
||||
if (tileData.Metadata.TryGetValue("description", out string description))
|
||||
{
|
||||
Description = s;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
if (tileData.Metadata.TryGetValue("minzoom", out s) && int.TryParse(s, out minZoom))
|
||||
if (tileData.Metadata.TryGetValue("minzoom", out sourceName) && int.TryParse(sourceName, out int minZoom))
|
||||
{
|
||||
MinZoomLevel = minZoom;
|
||||
}
|
||||
|
||||
if (tileData.Metadata.TryGetValue("maxzoom", out s) && int.TryParse(s, out maxZoom))
|
||||
if (tileData.Metadata.TryGetValue("maxzoom", out sourceName) && int.TryParse(sourceName, out int maxZoom))
|
||||
{
|
||||
MaxZoomLevel = maxZoom;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,9 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public abstract class AzimuthalProjection : MapProjection
|
||||
{
|
||||
public override bool IsNormalCylindrical
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override Rect BoundingBoxToRect(BoundingBox boundingBox)
|
||||
{
|
||||
var cbbox = boundingBox as CenteredBoundingBox;
|
||||
|
||||
if (cbbox != null)
|
||||
if (boundingBox is CenteredBoundingBox cbbox)
|
||||
{
|
||||
var center = LocationToMap(cbbox.Center);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ namespace MapControl
|
|||
CrsId = "EPSG:4326";
|
||||
}
|
||||
|
||||
public override bool IsNormalCylindrical
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
{
|
||||
return new Vector(
|
||||
|
|
|
|||
|
|
@ -388,8 +388,7 @@ namespace MapControl
|
|||
{
|
||||
Children.Remove(oldLayer);
|
||||
|
||||
var mapLayer = oldLayer as IMapLayer;
|
||||
if (mapLayer != null)
|
||||
if (oldLayer is IMapLayer mapLayer)
|
||||
{
|
||||
if (mapLayer.MapBackground != null)
|
||||
{
|
||||
|
|
@ -406,8 +405,7 @@ namespace MapControl
|
|||
{
|
||||
Children.Insert(0, newLayer);
|
||||
|
||||
var mapLayer = newLayer as IMapLayer;
|
||||
if (mapLayer != null)
|
||||
if (newLayer is IMapLayer mapLayer)
|
||||
{
|
||||
if (mapLayer.MapBackground != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -228,9 +228,7 @@ namespace MapControl
|
|||
element.Height = rect.Height;
|
||||
element.Arrange(rect);
|
||||
|
||||
var rotateTransform = element.RenderTransform as RotateTransform;
|
||||
|
||||
if (rotateTransform != null)
|
||||
if (element.RenderTransform is RotateTransform rotateTransform)
|
||||
{
|
||||
rotateTransform.Angle = parentMap.ViewTransform.Rotation;
|
||||
}
|
||||
|
|
@ -293,9 +291,7 @@ namespace MapControl
|
|||
|
||||
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var mapElement = obj as IMapElement;
|
||||
|
||||
if (mapElement != null)
|
||||
if (obj is IMapElement mapElement)
|
||||
{
|
||||
mapElement.ParentMap = e.NewValue as MapBase;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public virtual bool IsNormalCylindrical
|
||||
{
|
||||
get { return true; }
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ namespace MapControl
|
|||
|
||||
protected override void InsertItem(int index, IEnumerable<Location> polygon)
|
||||
{
|
||||
var observablePolygon = polygon as INotifyCollectionChanged;
|
||||
|
||||
if (observablePolygon != null)
|
||||
if (polygon is INotifyCollectionChanged observablePolygon)
|
||||
{
|
||||
CollectionChangedEventManager.AddListener(observablePolygon, this);
|
||||
}
|
||||
|
|
@ -38,9 +36,7 @@ namespace MapControl
|
|||
|
||||
protected override void SetItem(int index, IEnumerable<Location> polygon)
|
||||
{
|
||||
var observablePolygon = this[index] as INotifyCollectionChanged;
|
||||
|
||||
if (observablePolygon != null)
|
||||
if (this[index] is INotifyCollectionChanged observablePolygon)
|
||||
{
|
||||
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
|
||||
}
|
||||
|
|
@ -50,9 +46,7 @@ namespace MapControl
|
|||
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
var observablePolygon = this[index] as INotifyCollectionChanged;
|
||||
|
||||
if (observablePolygon != null)
|
||||
if (this[index] is INotifyCollectionChanged observablePolygon)
|
||||
{
|
||||
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ namespace MapControl
|
|||
CrsId = "EPSG:3857";
|
||||
}
|
||||
|
||||
public override bool IsNormalCylindrical
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsWebMercator
|
||||
{
|
||||
get { return true; }
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ namespace MapControl
|
|||
CrsId = "EPSG:3395";
|
||||
}
|
||||
|
||||
public override bool IsNormalCylindrical
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override double MaxLatitude
|
||||
{
|
||||
get { return maxLatitude; }
|
||||
|
|
|
|||
|
|
@ -17,12 +17,7 @@ namespace MapControl.Caching
|
|||
|
||||
public ImageFileCache(StorageFolder folder)
|
||||
{
|
||||
if (folder == null)
|
||||
{
|
||||
throw new ArgumentNullException("The parameter rootFolder must not be null.");
|
||||
}
|
||||
|
||||
this.folder = folder;
|
||||
this.folder = folder ?? throw new ArgumentNullException("The parameter rootFolder must not be null.");
|
||||
|
||||
Debug.WriteLine("Created ImageFileCache in " + folder.Path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,12 +53,9 @@ namespace MapControl
|
|||
|
||||
private static MapBase FindParentMap(FrameworkElement element)
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent(element) as FrameworkElement;
|
||||
|
||||
return parent == null ? null
|
||||
: ((parent as MapBase)
|
||||
?? (MapBase)element.GetValue(ParentMapProperty)
|
||||
?? FindParentMap(parent));
|
||||
return VisualTreeHelper.GetParent(element) is FrameworkElement parent
|
||||
? ((parent as MapBase) ?? (MapBase)element.GetValue(ParentMapProperty) ?? FindParentMap(parent))
|
||||
: null;
|
||||
}
|
||||
|
||||
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
|
||||
|
|
|
|||
|
|
@ -21,16 +21,14 @@ namespace MapControl
|
|||
|
||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
INotifyCollectionChanged collection;
|
||||
|
||||
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
|
||||
if (e.OldValue is INotifyCollectionChanged oldCollection)
|
||||
{
|
||||
collection.CollectionChanged -= DataCollectionChanged;
|
||||
oldCollection.CollectionChanged -= DataCollectionChanged;
|
||||
}
|
||||
|
||||
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
|
||||
if (e.NewValue is INotifyCollectionChanged newCollection)
|
||||
{
|
||||
collection.CollectionChanged += DataCollectionChanged;
|
||||
newCollection.CollectionChanged += DataCollectionChanged;
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ namespace MapControl
|
|||
|
||||
if (fadeIn && FadeDuration > TimeSpan.Zero)
|
||||
{
|
||||
var bitmap = image as BitmapImage;
|
||||
|
||||
if (bitmap?.UriSource != null)
|
||||
if (image is BitmapImage bitmap && bitmap.UriSource != null)
|
||||
{
|
||||
bitmap.ImageOpened += BitmapImageOpened;
|
||||
bitmap.ImageFailed += BitmapImageFailed;
|
||||
|
|
|
|||
|
|
@ -160,9 +160,8 @@ namespace MapControl.Caching
|
|||
throw new ArgumentNullException("The parameter key must not be null.");
|
||||
}
|
||||
|
||||
var imageCacheItem = value as ImageCacheItem;
|
||||
|
||||
if (imageCacheItem == null)
|
||||
if (!(value is ImageCacheItem imageCacheItem))
|
||||
{
|
||||
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,16 +35,14 @@ namespace MapControl
|
|||
|
||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
INotifyCollectionChanged collection;
|
||||
|
||||
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
|
||||
if (e.OldValue is INotifyCollectionChanged oldCollection)
|
||||
{
|
||||
CollectionChangedEventManager.RemoveListener(collection, this);
|
||||
CollectionChangedEventManager.RemoveListener(oldCollection, this);
|
||||
}
|
||||
|
||||
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
|
||||
if (e.NewValue is INotifyCollectionChanged newCollection)
|
||||
{
|
||||
CollectionChangedEventManager.AddListener(collection, this);
|
||||
CollectionChangedEventManager.AddListener(newCollection, this);
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ namespace MapControl
|
|||
|
||||
if (fadeIn && FadeDuration > TimeSpan.Zero)
|
||||
{
|
||||
var bitmap = image as BitmapSource;
|
||||
|
||||
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
|
||||
if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
|
||||
{
|
||||
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
||||
bitmap.DownloadFailed += BitmapDownloadFailed;
|
||||
|
|
|
|||
|
|
@ -115,12 +115,11 @@ namespace MapControl.Images
|
|||
.Take(6)
|
||||
.Select((line, i) =>
|
||||
{
|
||||
double p;
|
||||
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
|
||||
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out double parameter))
|
||||
{
|
||||
throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\".");
|
||||
}
|
||||
return p;
|
||||
return parameter;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,7 @@ namespace MapControl.Projections
|
|||
get { return coordinateSystem; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("The property value must not be null.");
|
||||
}
|
||||
|
||||
coordinateSystem = value;
|
||||
coordinateSystem = value ?? throw new ArgumentNullException("The property value must not be null.");
|
||||
|
||||
var transformFactory = new CoordinateTransformationFactory();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,9 @@ namespace MapControl.Projections
|
|||
}
|
||||
|
||||
var hemisphere = value[value.Length - 1];
|
||||
int zoneNumber;
|
||||
|
||||
if ((hemisphere != 'N' && hemisphere != 'S') ||
|
||||
!int.TryParse(value.Substring(0, value.Length - 1), out zoneNumber))
|
||||
!int.TryParse(value.Substring(0, value.Length - 1), out int zoneNumber))
|
||||
{
|
||||
throw new ArgumentException("Invalid UTM zone.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,9 +169,7 @@ namespace MapControl.Caching
|
|||
throw new ArgumentNullException("The parameter key must not be null.");
|
||||
}
|
||||
|
||||
var imageCacheItem = value as ImageCacheItem;
|
||||
|
||||
if (imageCacheItem == null)
|
||||
if (!(value is ImageCacheItem imageCacheItem))
|
||||
{
|
||||
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue