Replaced RenderSize by ActualWidth/Height

This commit is contained in:
ClemensFischer 2024-07-15 20:10:28 +02:00
parent 4e6d0db24f
commit fa508f51e7
16 changed files with 67 additions and 51 deletions

View file

@ -105,7 +105,8 @@ namespace MapControl
Animation.RegisterCustomAnimator<Location, LocationAnimator>();
}
internal Size RenderSize => Bounds.Size;
public double ActualWidth => Bounds.Width;
public double ActualHeight => Bounds.Height;
protected override void OnSizeChanged(SizeChangedEventArgs e)
{

View file

@ -29,7 +29,8 @@ namespace MapControl
AffectsRender<PushpinBorder>(ArrowSizeProperty, BorderWidthProperty, CornerRadiusProperty, BackgroundProperty, BorderBrushProperty);
}
private Size RenderSize => Bounds.Size;
public double ActualWidth => Bounds.Width;
public double ActualHeight => Bounds.Height;
public CornerRadius CornerRadius
{

View file

@ -123,7 +123,7 @@ namespace MapControl
/// <summary>
/// Gets the index bounds of a tile matrix.
/// </summary>
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize)
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight)
{
// View origin in map coordinates.
//
@ -143,7 +143,7 @@ namespace MapControl
// Transform view bounds to tile pixel bounds.
//
return new Rect(0d, 0d, viewSize.Width, viewSize.Height).TransformToAABB(transform);
return new Rect(0d, 0d, viewWidth, viewHeight).TransformToAABB(transform);
}
internal static Matrix CreateTransformMatrix(

View file

@ -255,7 +255,7 @@ namespace MapControl
public void SetTransformCenter(Point center)
{
transformCenter = ViewToLocation(center);
viewCenter = transformCenter != null ? center : new Point(RenderSize.Width / 2d, RenderSize.Height / 2d);
viewCenter = transformCenter != null ? center : new Point(ActualWidth / 2d, ActualHeight / 2d);
}
/// <summary>
@ -264,7 +264,7 @@ namespace MapControl
public void ResetTransformCenter()
{
transformCenter = null;
viewCenter = new Point(RenderSize.Width / 2d, RenderSize.Height / 2d);
viewCenter = new Point(ActualWidth / 2d, ActualHeight / 2d);
}
/// <summary>
@ -359,7 +359,7 @@ namespace MapControl
if (targetCenter != null)
{
var scale = Math.Min(RenderSize.Width / rect.Value.Width, RenderSize.Height / rect.Value.Height);
var scale = Math.Min(ActualWidth / rect.Value.Width, ActualHeight / rect.Value.Height);
TargetZoomLevel = ViewTransform.ScaleToZoomLevel(scale);
TargetCenter = targetCenter;
@ -510,7 +510,7 @@ namespace MapControl
if (transformCenter != null)
{
var center = ViewToLocation(new Point(RenderSize.Width / 2d, RenderSize.Height / 2d));
var center = ViewToLocation(new Point(ActualWidth / 2d, ActualHeight / 2d));
if (center != null)
{

View file

@ -40,8 +40,8 @@ namespace MapControl
protected override void SetViewPosition(FrameworkElement element, ref Point? position)
{
var onBorder = false;
var w = ParentMap.RenderSize.Width;
var h = ParentMap.RenderSize.Height;
var w = ParentMap.ActualWidth;
var h = ParentMap.ActualHeight;
var minX = BorderWidth / 2d;
var minY = BorderWidth / 2d;
var maxX = w - BorderWidth / 2d;

View file

@ -104,8 +104,8 @@ namespace MapControl
private void AddLabel(ICollection<Label> labels, Location location, Point position, double? rotation = null)
{
if (position.X >= 0d && position.X <= ParentMap.RenderSize.Width &&
position.Y >= 0d && position.Y <= ParentMap.RenderSize.Height)
if (position.X >= 0d && position.X <= ParentMap.ActualWidth &&
position.Y >= 0d && position.Y <= ParentMap.ActualHeight)
{
if (!rotation.HasValue)
{
@ -152,7 +152,7 @@ namespace MapControl
private void DrawCylindricalGraticule(PathFigureCollection figures, ICollection<Label> labels)
{
var bounds = ParentMap.ViewRectToBoundingBox(new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height));
var bounds = ParentMap.ViewRectToBoundingBox(new Rect(0, 0, ParentMap.ActualWidth, ParentMap.ActualHeight));
var latLabelStart = Math.Ceiling(bounds.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(bounds.West / lineDistance) * lineDistance;
@ -288,8 +288,8 @@ namespace MapControl
if (p.HasValue)
{
visible = visible ||
p.Value.X >= 0d && p.Value.X <= ParentMap.RenderSize.Width &&
p.Value.Y >= 0d && p.Value.Y <= ParentMap.RenderSize.Height;
p.Value.X >= 0d && p.Value.X <= ParentMap.ActualWidth &&
p.Value.Y >= 0d && p.Value.Y <= ParentMap.ActualHeight;
points.Add(p.Value);
}
@ -305,8 +305,8 @@ namespace MapControl
private void GetLatitudeRange(double lineDistance, ref double minLatitude, ref double maxLatitude)
{
var width = ParentMap.RenderSize.Width;
var height = ParentMap.RenderSize.Height;
var width = ParentMap.ActualWidth;
var height = ParentMap.ActualHeight;
var northPole = ParentMap.LocationToView(new Location(90d, 0d));
var southPole = ParentMap.LocationToView(new Location(-90d, 0d));

View file

@ -209,12 +209,12 @@ namespace MapControl
{
BoundingBox boundingBox = null;
if (ParentMap != null && ParentMap.RenderSize.Width > 0d && ParentMap.RenderSize.Height > 0d)
if (ParentMap != null && ParentMap.ActualWidth > 0d && ParentMap.ActualHeight > 0d)
{
var width = ParentMap.RenderSize.Width * RelativeImageSize;
var height = ParentMap.RenderSize.Height * RelativeImageSize;
var x = (ParentMap.RenderSize.Width - width) / 2d;
var y = (ParentMap.RenderSize.Height - height) / 2d;
var width = ParentMap.ActualWidth * RelativeImageSize;
var height = ParentMap.ActualHeight * RelativeImageSize;
var x = (ParentMap.ActualWidth - width) / 2d;
var y = (ParentMap.ActualHeight - height) / 2d;
boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(x, y, width, height));
}

View file

@ -214,9 +214,9 @@ namespace MapControl
return GetViewRect(rect.Value);
}
protected ViewRect GetViewRect(Rect rect)
protected ViewRect GetViewRect(Rect mapRect)
{
var rectCenter = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var rectCenter = new Point(mapRect.X + mapRect.Width / 2d, mapRect.Y + mapRect.Height / 2d);
var position = parentMap.ViewTransform.MapToView(rectCenter);
var projection = parentMap.MapProjection;
@ -236,8 +236,8 @@ namespace MapControl
}
}
var width = rect.Width * parentMap.ViewTransform.Scale;
var height = rect.Height * parentMap.ViewTransform.Scale;
var width = mapRect.Width * parentMap.ViewTransform.Scale;
var height = mapRect.Height * parentMap.ViewTransform.Scale;
var x = position.X - width / 2d;
var y = position.Y - height / 2d;
@ -246,8 +246,8 @@ namespace MapControl
private bool IsOutsideViewport(Point point)
{
return point.X < 0d || point.X > parentMap.RenderSize.Width
|| point.Y < 0d || point.Y > parentMap.RenderSize.Height;
return point.X < 0d || point.X > parentMap.ActualWidth
|| point.Y < 0d || point.Y > parentMap.ActualHeight;
}
private void ArrangeChildElement(FrameworkElement element, Size panelSize)

View file

@ -124,8 +124,8 @@ namespace MapControl
var point = parentMap.LocationToView(location);
if (point.HasValue &&
(point.Value.X < 0d || point.Value.X > parentMap.RenderSize.Width ||
point.Value.Y < 0d || point.Value.Y > parentMap.RenderSize.Height))
(point.Value.X < 0d || point.Value.X > parentMap.ActualWidth ||
point.Value.Y < 0d || point.Value.Y > parentMap.ActualHeight))
{
longitudeOffset = parentMap.CoerceLongitude(location.Longitude) - location.Longitude;
}

View file

@ -173,7 +173,7 @@ namespace MapControl
// Bounds in tile pixels from view size.
//
var bounds = ParentMap.ViewTransform.GetTileMatrixBounds(tileMatrixScale, MapTopLeft, ParentMap.RenderSize);
var bounds = ParentMap.ViewTransform.GetTileMatrixBounds(tileMatrixScale, MapTopLeft, ParentMap.ActualWidth, ParentMap.ActualHeight);
// Tile X and Y bounds.
//

View file

@ -34,8 +34,8 @@ namespace MapControl
protected virtual Geometry BuildGeometry()
{
var width = Math.Floor(RenderSize.Width);
var height = Math.Floor(RenderSize.Height);
var width = Math.Floor(ActualWidth);
var height = Math.Floor(ActualHeight);
var x1 = BorderWidth / 2d;
var y1 = BorderWidth / 2d;
var x2 = width - x1;

View file

@ -7,10 +7,8 @@ using System;
using System.Windows;
using System.Windows.Media;
#elif UWP
using Windows.Foundation;
using Windows.UI.Xaml.Media;
#elif WINUI
using Windows.Foundation;
using Microsoft.UI.Xaml.Media;
#endif
@ -138,7 +136,7 @@ namespace MapControl
/// <summary>
/// Gets the index bounds of a tile matrix.
/// </summary>
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize)
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight)
{
// View origin in map coordinates.
//
@ -158,7 +156,7 @@ namespace MapControl
// Transform view bounds to tile pixel bounds.
//
return new MatrixTransform { Matrix = transform }
.TransformBounds(new Rect(0d, 0d, viewSize.Width, viewSize.Height));
.TransformBounds(new Rect(0d, 0d, viewWidth, viewHeight));
}
internal static Matrix CreateTransformMatrix(

View file

@ -134,8 +134,8 @@ namespace MapControl
if (ServiceUri != null &&
ParentMap?.MapProjection != null &&
ParentMap.RenderSize.Width > 0d &&
ParentMap.RenderSize.Height > 0d)
ParentMap.ActualWidth > 0d &&
ParentMap.ActualHeight > 0d)
{
var uri = GetFeatureInfoRequestUri(position, format);
@ -257,19 +257,19 @@ namespace MapControl
/// </summary>
protected virtual string GetFeatureInfoRequestUri(Point position, string format)
{
var viewSize = ParentMap.RenderSize;
var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(0d, 0d, viewSize.Width, viewSize.Height));
var rect = ParentMap.MapProjection.BoundingBoxToMap(boundingBox);
var viewport = new Rect(0d, 0d, ParentMap.ActualWidth, ParentMap.ActualHeight);
var boundingBox = ParentMap.ViewRectToBoundingBox(viewport);
var mapRect = ParentMap.MapProjection.BoundingBoxToMap(boundingBox);
if (!rect.HasValue)
if (!mapRect.HasValue)
{
return null;
}
var viewRect = GetViewRect(rect.Value);
var viewRect = GetViewRect(mapRect.Value);
var transform = ViewTransform.CreateTransformMatrix(
-viewSize.Width / 2d, -viewSize.Height / 2d,
-viewport.Width / 2d, -viewport.Height / 2d,
-viewRect.Rotation,
viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d);
@ -285,7 +285,7 @@ namespace MapControl
{ "FORMAT", "image/png" },
{ "INFO_FORMAT", format },
{ "CRS", GetCrsValue() },
{ "BBOX", GetBboxValue(rect.Value) },
{ "BBOX", GetBboxValue(mapRect.Value) },
{ "WIDTH", Math.Round(viewRect.Rect.Width).ToString("F0") },
{ "HEIGHT", Math.Round(viewRect.Rect.Height).ToString("F0") },
{ "I", Math.Round(imagePos.X).ToString("F0") },

View file

@ -154,7 +154,7 @@ namespace MapControl
var layer = currentLayers.FirstOrDefault(l => l.WmtsTileMatrix == tileMatrix) ??
new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix));
if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.RenderSize))
if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight))
{
tilesChanged = true;
}

View file

@ -47,11 +47,11 @@ namespace MapControl
viewTransform.GetTileLayerTransform(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, tileMatrixOrigin);
}
public bool UpdateTiles(ViewTransform viewTransform, Size viewSize)
public bool UpdateTiles(ViewTransform viewTransform, double viewWidth, double viewHeight)
{
// Bounds in tile pixels from view size.
//
var bounds = viewTransform.GetTileMatrixBounds(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, viewSize);
var bounds = viewTransform.GetTileMatrixBounds(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, viewWidth, viewHeight);
// Tile X and Y bounds.
//

View file

@ -2,6 +2,7 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
@ -78,9 +79,15 @@ namespace MapControl
if (points.Any())
{
var startPoint = points.First();
var minX = startPoint.X;
var maxX = startPoint.X;
var minY = startPoint.Y;
var maxY = startPoint.Y;
var figure = new PathFigure
{
StartPoint = points.First(),
StartPoint = startPoint,
IsClosed = closed,
IsFilled = true
};
@ -89,10 +96,19 @@ namespace MapControl
foreach (var point in points.Skip(1))
{
minX = Math.Min(minX, point.X);
maxX = Math.Max(maxX, point.X);
minY = Math.Min(minY, point.Y);
maxY = Math.Max(maxY, point.Y);
polyline.Points.Add(point);
}
figure.Segments.Add(polyline);
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
{
figure.Segments.Add(polyline);
}
pathFigures.Add(figure);
}
}