diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs index 8857938b..9b2045dc 100644 --- a/MapControl/Shared/GeoImage.cs +++ b/MapControl/Shared/GeoImage.cs @@ -94,7 +94,8 @@ namespace MapControl image.RenderTransform = new RotateTransform { Angle = -rotation }; - // effective unrotated transform + // Calculate effective unrotated transform. + // transform.M11 = Math.Sqrt(transform.M11 * transform.M11 + transform.M12 * transform.M12); transform.M22 = -Math.Sqrt(transform.M22 * transform.M22 + transform.M21 * transform.M21); transform.M12 = 0; diff --git a/MapControl/Shared/GroundOverlay.cs b/MapControl/Shared/GroundOverlay.cs index 04918680..a96a90f7 100644 --- a/MapControl/Shared/GroundOverlay.cs +++ b/MapControl/Shared/GroundOverlay.cs @@ -114,7 +114,8 @@ namespace MapControl overlay.RenderTransform = new RotateTransform { Angle = -imageOverlay.LatLonBox.Rotation }; overlay.RenderTransformOrigin = new Point(0.5, 0.5); - // additional Panel for map rotation, see MapPanel.ArrangeElementWithBoundingBox + // Additional Panel for map rotation, see MapPanel.ArrangeElementWithBoundingBox. + // var panel = new Grid { UseLayoutRounding = false }; panel.Children.Add(overlay); overlay = panel; diff --git a/MapControl/Shared/ImageLoader.cs b/MapControl/Shared/ImageLoader.cs index 3b31b557..e5fda0d0 100644 --- a/MapControl/Shared/ImageLoader.cs +++ b/MapControl/Shared/ImageLoader.cs @@ -89,7 +89,7 @@ namespace MapControl { byte[] buffer = null; - // check for possibly unavailable Bing Maps tile + // Check for possibly unavailable Bing Maps tile. // if (!responseMessage.Headers.TryGetValues("X-VE-Tile-Info", out IEnumerable tileInfo) || !tileInfo.Contains("no-tile")) diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index cb13962e..70066b06 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -343,7 +343,9 @@ namespace MapControl } else { - TranslateMap(translation); // more precise + // More accurate than SetTransformCenter. + // + TranslateMap(translation); } } @@ -764,7 +766,8 @@ namespace MapControl if (resetTransformCenter) { - // check if transform center moved across the dateline + // Check if transform center moved across the dateline. + // transformCenterChanged = Math.Abs(center.Longitude - transformCenter.Longitude) > 180d; ResetTransformCenter(); @@ -783,7 +786,8 @@ namespace MapControl SetViewScale(ViewTransform.Scale); - // check if view center moved across the dateline + // Check if view center moved across the dateline. + // transformCenterChanged = transformCenterChanged || Math.Abs(Center.Longitude - centerLongitude) > 180d; centerLongitude = Center.Longitude; diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index 51178ed3..410a725a 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -114,7 +114,7 @@ namespace MapControl { if (!rotation.HasValue) { - // get rotation from second location with same latitude + // Get rotation from second location with same latitude. // var pos = ParentMap.LocationToView( new Location(location.Latitude, location.Longitude + 10d / PixelPerLongitudeDegree(location))); diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 2412cee9..a5408b63 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -180,7 +180,7 @@ namespace MapControl { if (updateInProgress) { - // update image on next tick, start timer if not running + // Update image on next tick, start timer if not running. // updateTimer.Run(); } diff --git a/MapControl/Shared/MapItemsControl.cs b/MapControl/Shared/MapItemsControl.cs index a23333db..8ab37270 100644 --- a/MapControl/Shared/MapItemsControl.cs +++ b/MapControl/Shared/MapItemsControl.cs @@ -61,7 +61,9 @@ namespace MapControl protected override Size ArrangeOverride(Size bounds) { - if (mapTransform != null) // property in use, e.g. as source of a Binding + // If MapTransform is used, update its Matrix property. + // + if (mapTransform != null) { var parentMap = (VisualTreeHelper.GetParent(this) as MapPanel)?.ParentMap; @@ -184,7 +186,7 @@ namespace MapControl if (SelectionMode == SelectionMode.Single) { - // Single -> set only SelectedItem + // Single -> set only SelectedItem. if (SelectedItem != item) { @@ -197,7 +199,7 @@ namespace MapControl } else if (SelectionMode == SelectionMode.Multiple || controlKey) { - // Multiple or Extended with Ctrl -> toggle item in SelectedItems + // Multiple or Extended with Ctrl -> toggle item in SelectedItems. if (SelectedItems.Contains(item)) { @@ -210,7 +212,7 @@ namespace MapControl } else if (shiftKey && SelectedItem != null) { - // Extended with Shift -> select items in view rectangle + // Extended with Shift -> select items in view rectangle. var p1 = MapPanel.GetViewPosition(ContainerFromItem(SelectedItem)); var p2 = MapPanel.GetViewPosition(mapItem); @@ -222,7 +224,7 @@ namespace MapControl } else if (SelectedItem != item) { - // Extended without Control or Shift -> set selected item + // Extended without Control or Shift -> set selected item. SelectedItem = item; } diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index cbe9c613..b8145c26 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -108,7 +108,7 @@ namespace MapControl { foreach (var tile in Tiles) { - // arrange tiles relative to XMin/YMin + // Arrange tiles relative to XMin/YMin. // var tileSize = TileSize << (TileMatrix.ZoomLevel - tile.ZoomLevel); var x = tileSize * tile.X - TileSize * TileMatrix.XMin; @@ -162,7 +162,7 @@ namespace MapControl { if (TileMatrix != null) { - // tile matrix origin in pixels + // Tile matrix origin in pixels. // var tileMatrixOrigin = new Point(TileSize * TileMatrix.XMin, TileSize * TileMatrix.YMin); @@ -175,15 +175,17 @@ namespace MapControl private bool SetTileMatrix() { - var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001); // avoid rounding issues + // Add 0.001 to avoid rounding issues. + // + var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001); var tileMatrixScale = ViewTransform.ZoomLevelToScale(tileMatrixZoomLevel); - // bounds in tile pixels from view size + // Bounds in tile pixels from view size. // var bounds = ParentMap.ViewTransform.GetTileMatrixBounds(tileMatrixScale, MapTopLeft, ParentMap.RenderSize); - // tile X and Y bounds + // Tile X and Y bounds. // var xMin = (int)Math.Floor(bounds.X / TileSize); var yMin = (int)Math.Floor(bounds.Y / TileSize); diff --git a/MapControl/Shared/ViewTransform.cs b/MapControl/Shared/ViewTransform.cs index 33be71e3..9f8a2570 100644 --- a/MapControl/Shared/ViewTransform.cs +++ b/MapControl/Shared/ViewTransform.cs @@ -93,13 +93,13 @@ namespace MapControl transform.Rotate(Rotation); - // tile matrix origin in map coordinates + // Tile matrix origin in map coordinates. // var mapOrigin = new Point( tileMatrixTopLeft.X + tileMatrixOrigin.X / tileMatrixScale, tileMatrixTopLeft.Y - tileMatrixOrigin.Y / tileMatrixScale); - // tile matrix origin in view coordinates + // Tile matrix origin in view coordinates. // var viewOrigin = MapToView(mapOrigin); @@ -115,17 +115,17 @@ namespace MapControl transform.Rotate(-Rotation); - // view origin in map coordinates + // View origin in map coordinates. // var origin = ViewToMap(new Point()); - // translate origin to tile matrix origin in pixels + // Translate origin to tile matrix origin in pixels. // transform.Translate( tileMatrixScale * (origin.X - tileMatrixTopLeft.X), tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y)); - // transform view bounds to tile pixel bounds + // Transform view bounds to tile pixel bounds. // return new MatrixTransform { Matrix = transform } .TransformBounds(new Rect(0d, 0d, viewSize.Width, viewSize.Height)); diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index 4774a3e4..5398a6da 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -37,7 +37,9 @@ namespace MapControl new PropertyMetadata(null, async (o, e) => { - if (e.OldValue != null) // ignore property change from GetImageAsync + // Ignore property change from GetImageAsync, when Layers was null. + // + if (e.OldValue != null) { await ((WmsImageLayer)o).UpdateImageAsync(); } @@ -176,7 +178,9 @@ namespace MapControl if (Layers == null && ServiceUri.ToString().IndexOf("LAYERS=", StringComparison.OrdinalIgnoreCase) < 0) { - Layers = (await GetLayerNamesAsync())?.FirstOrDefault() ?? ""; // get first Layer from Capabilities + // Get first Layer from a GetCapabilities response. + // + Layers = (await GetLayerNamesAsync())?.FirstOrDefault() ?? ""; } if (boundingBox.West >= -180d && boundingBox.East <= 180d || diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 0a04de9c..8cd63965 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -112,20 +112,26 @@ namespace MapControl private bool UpdateChildLayers(WmtsTileMatrixSet tileMatrixSet) { - var maxScale = 1.001 * ParentMap.ViewTransform.Scale; // avoid rounding issues + // Multiply scale by 1.001 to avoid rounding issues. + // + var maxScale = 1.001 * ParentMap.ViewTransform.Scale; - // show all WmtsTileMatrix layers with Scale <= maxScale, at least the first layer + // Show all WmtsTileMatrix layers with Scale <= maxScale, at least the first layer. // var currentMatrixes = tileMatrixSet.TileMatrixes .Where((matrix, i) => i == 0 || matrix.Scale <= maxScale) .ToList(); - if (!IsBaseMapLayer) // show only the last layer + if (!IsBaseMapLayer) { + // Show only the last layer. + // currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - 1).ToList(); } else if (currentMatrixes.Count > MaxBackgroundLevels + 1) { + // Show not more than MaxBackgroundLevels + 1 layers. + // currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - MaxBackgroundLevels - 1).ToList(); } diff --git a/MapControl/Shared/WmtsTileMatrixLayer.cs b/MapControl/Shared/WmtsTileMatrixLayer.cs index 4cf5b870..bafc5ee7 100644 --- a/MapControl/Shared/WmtsTileMatrixLayer.cs +++ b/MapControl/Shared/WmtsTileMatrixLayer.cs @@ -21,8 +21,8 @@ namespace MapControl { public class WmtsTileMatrixLayer : Panel { - // zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list - // + // zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list. + // public WmtsTileMatrixLayer(WmtsTileMatrix tileMatrix, int zoomLevel) { RenderTransform = new MatrixTransform(); @@ -38,7 +38,7 @@ namespace MapControl public void SetRenderTransform(ViewTransform viewTransform) { - // tile matrix origin in pixels + // Tile matrix origin in pixels. // var tileMatrixOrigin = new Point(WmtsTileMatrix.TileWidth * TileMatrix.XMin, WmtsTileMatrix.TileHeight * TileMatrix.YMin); @@ -48,24 +48,24 @@ namespace MapControl public bool UpdateTiles(ViewTransform viewTransform, Size viewSize) { - // bounds in tile pixels from view size + // Bounds in tile pixels from view size. // var bounds = viewTransform.GetTileMatrixBounds(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, viewSize); - // tile X and Y bounds + // Tile X and Y bounds. // var xMin = (int)Math.Floor(bounds.X / WmtsTileMatrix.TileWidth); var yMin = (int)Math.Floor(bounds.Y / WmtsTileMatrix.TileHeight); var xMax = (int)Math.Floor((bounds.X + bounds.Width) / WmtsTileMatrix.TileWidth); var yMax = (int)Math.Floor((bounds.Y + bounds.Height) / WmtsTileMatrix.TileHeight); - // total tile matrix width in meters + // Total tile matrix width in meters. // var totalWidth = WmtsTileMatrix.MatrixWidth * WmtsTileMatrix.TileWidth / WmtsTileMatrix.Scale; if (Math.Abs(totalWidth - 360d * MapProjection.Wgs84MeterPerDegree) > 1d) { - // no full longitudinal coverage, restrict x index + // No full longitudinal coverage, restrict x index. // xMin = Math.Max(xMin, 0); xMax = Math.Min(Math.Max(xMax, 0), WmtsTileMatrix.MatrixWidth - 1); @@ -77,7 +77,7 @@ namespace MapControl if (TileMatrix.XMin == xMin && TileMatrix.YMin == yMin && TileMatrix.XMax == xMax && TileMatrix.YMax == yMax) { - // no change of the TileMatrix and the Tiles collection + // No change of the TileMatrix and the Tiles collection. // return false; } @@ -122,7 +122,7 @@ namespace MapControl { foreach (var tile in Tiles) { - // arrange tiles relative to XMin/YMin + // Arrange tiles relative to XMin/YMin. // var x = WmtsTileMatrix.TileWidth * (tile.X - TileMatrix.XMin); var y = WmtsTileMatrix.TileHeight * (tile.Y - TileMatrix.YMin); diff --git a/MapControl/WPF/Map.WPF.cs b/MapControl/WPF/Map.WPF.cs index 4736b79f..d8c2717f 100644 --- a/MapControl/WPF/Map.WPF.cs +++ b/MapControl/WPF/Map.WPF.cs @@ -101,7 +101,9 @@ namespace MapControl private void OnMouseWheel(object sender, MouseWheelEventArgs e) { - mouseWheelDelta += e.Delta / 120d; // standard mouse wheel delta + // Standard mouse wheel delta value is 120. + // + mouseWheelDelta += e.Delta / 120d; if (Math.Abs(mouseWheelDelta) >= 1d) { diff --git a/MapControl/WPF/MapOverlay.WPF.cs b/MapControl/WPF/MapOverlay.WPF.cs index 2299e4dc..69a71b95 100644 --- a/MapControl/WPF/MapOverlay.WPF.cs +++ b/MapControl/WPF/MapOverlay.WPF.cs @@ -61,7 +61,8 @@ namespace MapControl { base.OnInitialized(e); - // If this.Stroke is not explicitly set, bind it to this.Foreground + // If this.Stroke is not explicitly set, bind it to this.Foreground. + // this.SetBindingOnUnsetProperty(StrokeProperty, this, ForegroundProperty, nameof(Foreground)); } diff --git a/MapControl/WPF/MapPath.WPF.cs b/MapControl/WPF/MapPath.WPF.cs index ac4bf432..d5bd4558 100644 --- a/MapControl/WPF/MapPath.WPF.cs +++ b/MapControl/WPF/MapPath.WPF.cs @@ -27,7 +27,9 @@ namespace MapControl private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { - if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue)) // Data is actually a new Geometry + // Check if Data is actually a new Geometry. + // + if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue)) { var path = (MapPath)obj; var data = (Geometry)e.NewValue; diff --git a/MapControl/WinUI/ImageLoader.WinUI.cs b/MapControl/WinUI/ImageLoader.WinUI.cs index 97acb97f..f242783a 100644 --- a/MapControl/WinUI/ImageLoader.WinUI.cs +++ b/MapControl/WinUI/ImageLoader.WinUI.cs @@ -40,7 +40,9 @@ namespace MapControl { using (var stream = new MemoryStream(buffer)) { - return await LoadImageAsync(stream); // await before closing stream + // Must await method before closing the stream. + // + return await LoadImageAsync(stream); } } diff --git a/MapControl/WinUI/Map.WinUI.cs b/MapControl/WinUI/Map.WinUI.cs index 420f9404..ace1789b 100644 --- a/MapControl/WinUI/Map.WinUI.cs +++ b/MapControl/WinUI/Map.WinUI.cs @@ -58,7 +58,9 @@ namespace MapControl { var point = e.GetCurrentPoint(this); - mouseWheelDelta += point.Properties.MouseWheelDelta / 120d; // standard mouse wheel delta + // Standard mouse wheel delta value is 120. + // + mouseWheelDelta += point.Properties.MouseWheelDelta / 120d; if (Math.Abs(mouseWheelDelta) >= 1d) { diff --git a/MapControl/WinUI/MapBase.WinUI.cs b/MapControl/WinUI/MapBase.WinUI.cs index 1e2348da..0e3bd5ad 100644 --- a/MapControl/WinUI/MapBase.WinUI.cs +++ b/MapControl/WinUI/MapBase.WinUI.cs @@ -56,7 +56,8 @@ namespace MapControl public MapBase() { - // set Background by Style to enable resetting by ClearValue in MapLayerPropertyChanged + // Set Background by Style to enable resetting by ClearValue in MapLayerPropertyChanged. + // var style = new Style(typeof(MapBase)); style.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.White))); Style = style; diff --git a/MapControl/WinUI/MapContentControl.WinUI.cs b/MapControl/WinUI/MapContentControl.WinUI.cs index 63d15726..3446c066 100644 --- a/MapControl/WinUI/MapContentControl.WinUI.cs +++ b/MapControl/WinUI/MapContentControl.WinUI.cs @@ -57,13 +57,16 @@ namespace MapControl if (parentMap != null) { - // If this.Background is not explicitly set, bind it to parentMap.Background + // If this.Background is not explicitly set, bind it to parentMap.Background. + // this.SetBindingOnUnsetProperty(BackgroundProperty, parentMap, Panel.BackgroundProperty, nameof(Background)); - // If this.Foreground is not explicitly set, bind it to parentMap.Foreground + // If this.Foreground is not explicitly set, bind it to parentMap.Foreground. + // this.SetBindingOnUnsetProperty(ForegroundProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground)); - // If this.BorderBrush is not explicitly set, bind it to parentMap.Foreground + // If this.BorderBrush is not explicitly set, bind it to parentMap.Foreground. + // this.SetBindingOnUnsetProperty(BorderBrushProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground)); } } diff --git a/MapControl/WinUI/MapOverlay.WinUI.cs b/MapControl/WinUI/MapOverlay.WinUI.cs index eb77648b..8a8b6e5e 100644 --- a/MapControl/WinUI/MapOverlay.WinUI.cs +++ b/MapControl/WinUI/MapOverlay.WinUI.cs @@ -66,10 +66,12 @@ namespace MapControl { if (map != null) { - // If this.Forground is not explicitly set, bind it to map.Foreground + // If this.Forground is not explicitly set, bind it to map.Foreground. + // this.SetBindingOnUnsetProperty(ForegroundProperty, map, MapBase.ForegroundProperty, nameof(Foreground)); - // If this.Stroke is not explicitly set, bind it to this.Foreground + // If this.Stroke is not explicitly set, bind it to this.Foreground. + // this.SetBindingOnUnsetProperty(StrokeProperty, this, ForegroundProperty, nameof(Foreground)); }