This commit is contained in:
ClemensF 2020-04-16 23:15:03 +02:00
parent 3ffb613f80
commit 310f0cca9a
21 changed files with 51 additions and 86 deletions

View file

@ -147,9 +147,7 @@ namespace MapControl.Caching
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException("The parameter key must not be null.");
} }
var imageCacheItem = value as ImageCacheItem; if (!(value is ImageCacheItem imageCacheItem))
if (imageCacheItem == null)
{ {
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
} }

View file

@ -57,26 +57,23 @@ namespace MapControl.MBTiles
if (file != null) if (file != null)
{ {
var tileData = await MBTileData.CreateAsync(file); 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; 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; MaxZoomLevel = maxZoom;
} }

View file

@ -16,16 +16,9 @@ namespace MapControl
/// </summary> /// </summary>
public abstract class AzimuthalProjection : MapProjection public abstract class AzimuthalProjection : MapProjection
{ {
public override bool IsNormalCylindrical
{
get { return false; }
}
public override Rect BoundingBoxToRect(BoundingBox boundingBox) public override Rect BoundingBoxToRect(BoundingBox boundingBox)
{ {
var cbbox = boundingBox as CenteredBoundingBox; if (boundingBox is CenteredBoundingBox cbbox)
if (cbbox != null)
{ {
var center = LocationToMap(cbbox.Center); var center = LocationToMap(cbbox.Center);

View file

@ -23,6 +23,11 @@ namespace MapControl
CrsId = "EPSG:4326"; CrsId = "EPSG:4326";
} }
public override bool IsNormalCylindrical
{
get { return true; }
}
public override Vector GetRelativeScale(Location location) public override Vector GetRelativeScale(Location location)
{ {
return new Vector( return new Vector(

View file

@ -388,8 +388,7 @@ namespace MapControl
{ {
Children.Remove(oldLayer); Children.Remove(oldLayer);
var mapLayer = oldLayer as IMapLayer; if (oldLayer is IMapLayer mapLayer)
if (mapLayer != null)
{ {
if (mapLayer.MapBackground != null) if (mapLayer.MapBackground != null)
{ {
@ -406,8 +405,7 @@ namespace MapControl
{ {
Children.Insert(0, newLayer); Children.Insert(0, newLayer);
var mapLayer = newLayer as IMapLayer; if (newLayer is IMapLayer mapLayer)
if (mapLayer != null)
{ {
if (mapLayer.MapBackground != null) if (mapLayer.MapBackground != null)
{ {

View file

@ -228,9 +228,7 @@ namespace MapControl
element.Height = rect.Height; element.Height = rect.Height;
element.Arrange(rect); element.Arrange(rect);
var rotateTransform = element.RenderTransform as RotateTransform; if (element.RenderTransform is RotateTransform rotateTransform)
if (rotateTransform != null)
{ {
rotateTransform.Angle = parentMap.ViewTransform.Rotation; rotateTransform.Angle = parentMap.ViewTransform.Rotation;
} }
@ -293,9 +291,7 @@ namespace MapControl
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{ {
var mapElement = obj as IMapElement; if (obj is IMapElement mapElement)
if (mapElement != null)
{ {
mapElement.ParentMap = e.NewValue as MapBase; mapElement.ParentMap = e.NewValue as MapBase;
} }

View file

@ -37,7 +37,7 @@ namespace MapControl
/// </summary> /// </summary>
public virtual bool IsNormalCylindrical public virtual bool IsNormalCylindrical
{ {
get { return true; } get { return false; }
} }
/// <summary> /// <summary>

View file

@ -26,9 +26,7 @@ namespace MapControl
protected override void InsertItem(int index, IEnumerable<Location> polygon) protected override void InsertItem(int index, IEnumerable<Location> polygon)
{ {
var observablePolygon = polygon as INotifyCollectionChanged; if (polygon is INotifyCollectionChanged observablePolygon)
if (observablePolygon != null)
{ {
CollectionChangedEventManager.AddListener(observablePolygon, this); CollectionChangedEventManager.AddListener(observablePolygon, this);
} }
@ -38,9 +36,7 @@ namespace MapControl
protected override void SetItem(int index, IEnumerable<Location> polygon) protected override void SetItem(int index, IEnumerable<Location> polygon)
{ {
var observablePolygon = this[index] as INotifyCollectionChanged; if (this[index] is INotifyCollectionChanged observablePolygon)
if (observablePolygon != null)
{ {
CollectionChangedEventManager.RemoveListener(observablePolygon, this); CollectionChangedEventManager.RemoveListener(observablePolygon, this);
} }
@ -50,9 +46,7 @@ namespace MapControl
protected override void RemoveItem(int index) protected override void RemoveItem(int index)
{ {
var observablePolygon = this[index] as INotifyCollectionChanged; if (this[index] is INotifyCollectionChanged observablePolygon)
if (observablePolygon != null)
{ {
CollectionChangedEventManager.RemoveListener(observablePolygon, this); CollectionChangedEventManager.RemoveListener(observablePolygon, this);
} }

View file

@ -22,6 +22,11 @@ namespace MapControl
CrsId = "EPSG:3857"; CrsId = "EPSG:3857";
} }
public override bool IsNormalCylindrical
{
get { return true; }
}
public override bool IsWebMercator public override bool IsWebMercator
{ {
get { return true; } get { return true; }

View file

@ -25,6 +25,11 @@ namespace MapControl
CrsId = "EPSG:3395"; CrsId = "EPSG:3395";
} }
public override bool IsNormalCylindrical
{
get { return true; }
}
public override double MaxLatitude public override double MaxLatitude
{ {
get { return maxLatitude; } get { return maxLatitude; }

View file

@ -17,12 +17,7 @@ namespace MapControl.Caching
public ImageFileCache(StorageFolder folder) public ImageFileCache(StorageFolder folder)
{ {
if (folder == null) this.folder = folder ?? throw new ArgumentNullException("The parameter rootFolder must not be null.");
{
throw new ArgumentNullException("The parameter rootFolder must not be null.");
}
this.folder = folder;
Debug.WriteLine("Created ImageFileCache in " + folder.Path); Debug.WriteLine("Created ImageFileCache in " + folder.Path);
} }

View file

@ -53,12 +53,9 @@ namespace MapControl
private static MapBase FindParentMap(FrameworkElement element) private static MapBase FindParentMap(FrameworkElement element)
{ {
var parent = VisualTreeHelper.GetParent(element) as FrameworkElement; return VisualTreeHelper.GetParent(element) is FrameworkElement parent
? ((parent as MapBase) ?? (MapBase)element.GetValue(ParentMapProperty) ?? FindParentMap(parent))
return parent == null ? null : null;
: ((parent as MapBase)
?? (MapBase)element.GetValue(ParentMapProperty)
?? FindParentMap(parent));
} }
private static void SetViewPosition(FrameworkElement element, Point? viewPosition) private static void SetViewPosition(FrameworkElement element, Point? viewPosition)

View file

@ -21,16 +21,14 @@ namespace MapControl
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
{ {
INotifyCollectionChanged collection; if (e.OldValue is INotifyCollectionChanged oldCollection)
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
{ {
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(); UpdateData();

View file

@ -18,9 +18,7 @@ namespace MapControl
if (fadeIn && FadeDuration > TimeSpan.Zero) if (fadeIn && FadeDuration > TimeSpan.Zero)
{ {
var bitmap = image as BitmapImage; if (image is BitmapImage bitmap && bitmap.UriSource != null)
if (bitmap?.UriSource != null)
{ {
bitmap.ImageOpened += BitmapImageOpened; bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed; bitmap.ImageFailed += BitmapImageFailed;

View file

@ -160,9 +160,8 @@ namespace MapControl.Caching
throw new ArgumentNullException("The parameter key must not be null."); 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."); throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
} }

View file

@ -35,16 +35,14 @@ namespace MapControl
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
{ {
INotifyCollectionChanged collection; if (e.OldValue is INotifyCollectionChanged oldCollection)
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
{ {
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(); UpdateData();

View file

@ -17,9 +17,7 @@ namespace MapControl
if (fadeIn && FadeDuration > TimeSpan.Zero) if (fadeIn && FadeDuration > TimeSpan.Zero)
{ {
var bitmap = image as BitmapSource; if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
{ {
bitmap.DownloadCompleted += BitmapDownloadCompleted; bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed; bitmap.DownloadFailed += BitmapDownloadFailed;

View file

@ -115,12 +115,11 @@ namespace MapControl.Images
.Take(6) .Take(6)
.Select((line, i) => .Select((line, i) =>
{ {
double p; if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out double parameter))
if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p))
{ {
throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\"."); throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\".");
} }
return p; return parameter;
}) })
.ToList(); .ToList();

View file

@ -38,12 +38,7 @@ namespace MapControl.Projections
get { return coordinateSystem; } get { return coordinateSystem; }
set set
{ {
if (value == null) coordinateSystem = value ?? throw new ArgumentNullException("The property value must not be null.");
{
throw new ArgumentNullException("The property value must not be null.");
}
coordinateSystem = value;
var transformFactory = new CoordinateTransformationFactory(); var transformFactory = new CoordinateTransformationFactory();

View file

@ -24,10 +24,9 @@ namespace MapControl.Projections
} }
var hemisphere = value[value.Length - 1]; var hemisphere = value[value.Length - 1];
int zoneNumber;
if ((hemisphere != 'N' && hemisphere != 'S') || 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."); throw new ArgumentException("Invalid UTM zone.");
} }

View file

@ -169,9 +169,7 @@ namespace MapControl.Caching
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException("The parameter key must not be null.");
} }
var imageCacheItem = value as ImageCacheItem; if (!(value is ImageCacheItem imageCacheItem))
if (imageCacheItem == null)
{ {
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
} }