Version 4.4.1: MapPolygon for UWP in progress

This commit is contained in:
ClemensF 2018-02-11 19:46:31 +01:00
parent 66a97b3fa2
commit 54c924f9e7
15 changed files with 497 additions and 125 deletions

View file

@ -86,12 +86,18 @@
<Compile Include="..\Shared\HyperlinkText.cs">
<Link>HyperlinkText.cs</Link>
</Compile>
<Compile Include="..\Shared\Intersections.cs">
<Link>Intersections.cs</Link>
</Compile>
<Compile Include="..\Shared\Location.cs">
<Link>Location.cs</Link>
</Compile>
<Compile Include="..\Shared\LocationCollection.cs">
<Link>LocationCollection.cs</Link>
</Compile>
<Compile Include="..\Shared\LocationEx.cs">
<Link>LocationEx.cs</Link>
</Compile>
<Compile Include="..\Shared\MapBase.cs">
<Link>MapBase.cs</Link>
</Compile>

View file

@ -39,62 +39,75 @@ namespace MapControl
{
var projection = ParentMap?.MapProjection;
if (projection != null && !projection.IsAzimuthal)
if (projection != null)
{
var bounds = projection.ViewportRectToBoundingBox(new Rect(ParentMap.RenderSize));
var lineDistance = GetLineDistance();
var labelFormat = GetLabelFormat(lineDistance);
if (bounds.HasValidBounds)
if (projection.IsAzimuthal)
{
var lineDistance = GetLineDistance();
var labelFormat = GetLabelFormat(lineDistance);
var latLabelStart = Math.Ceiling(bounds.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(bounds.West / lineDistance) * lineDistance;
var latLabels = new List<Label>((int)((bounds.North - latLabelStart) / lineDistance) + 1);
var lonLabels = new List<Label>((int)((bounds.East - lonLabelStart) / lineDistance) + 1);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var pen = new Pen
}
else
{
DrawCylindricalGraticule(drawingContext, projection, lineDistance, labelFormat);
}
}
}
private void DrawCylindricalGraticule(DrawingContext drawingContext, MapProjection projection, double lineDistance, string labelFormat)
{
var boundingBox = projection.ViewportRectToBoundingBox(new Rect(ParentMap.RenderSize));
if (boundingBox.HasValidBounds)
{
var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance;
var latLabels = new List<Label>((int)((boundingBox.North - latLabelStart) / lineDistance) + 1);
var lonLabels = new List<Label>((int)((boundingBox.East - lonLabelStart) / lineDistance) + 1);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var pen = new Pen
{
Brush = Stroke,
Thickness = StrokeThickness,
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset),
DashCap = StrokeDashCap
};
for (var lat = latLabelStart; lat <= boundingBox.North; lat += lineDistance)
{
latLabels.Add(new Label(lat, new FormattedText(
GetLabelText(lat, labelFormat, "NS"),
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground)));
drawingContext.DrawLine(pen,
projection.LocationToViewportPoint(new Location(lat, boundingBox.West)),
projection.LocationToViewportPoint(new Location(lat, boundingBox.East)));
}
for (var lon = lonLabelStart; lon <= boundingBox.East; lon += lineDistance)
{
lonLabels.Add(new Label(lon, new FormattedText(
GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW"),
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground)));
drawingContext.DrawLine(pen,
projection.LocationToViewportPoint(new Location(boundingBox.South, lon)),
projection.LocationToViewportPoint(new Location(boundingBox.North, lon)));
}
foreach (var latLabel in latLabels)
{
foreach (var lonLabel in lonLabels)
{
Brush = Stroke,
Thickness = StrokeThickness,
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset),
DashCap = StrokeDashCap
};
var position = projection.LocationToViewportPoint(new Location(latLabel.Position, lonLabel.Position));
for (var lat = latLabelStart; lat <= bounds.North; lat += lineDistance)
{
latLabels.Add(new Label(lat, new FormattedText(
GetLabelText(lat, labelFormat, "NS"),
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground)));
drawingContext.DrawLine(pen,
projection.LocationToViewportPoint(new Location(lat, bounds.West)),
projection.LocationToViewportPoint(new Location(lat, bounds.East)));
}
for (var lon = lonLabelStart; lon <= bounds.East; lon += lineDistance)
{
lonLabels.Add(new Label(lon, new FormattedText(
GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW"),
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground)));
drawingContext.DrawLine(pen,
projection.LocationToViewportPoint(new Location(bounds.South, lon)),
projection.LocationToViewportPoint(new Location(bounds.North, lon)));
}
foreach (var latLabel in latLabels)
{
foreach (var lonLabel in lonLabels)
{
var position = projection.LocationToViewportPoint(new Location(latLabel.Position, lonLabel.Position));
drawingContext.PushTransform(new RotateTransform(ParentMap.Heading, position.X, position.Y));
drawingContext.DrawText(latLabel.Text,
new Point(position.X + StrokeThickness / 2d + 2d, position.Y - StrokeThickness / 2d - latLabel.Text.Height));
drawingContext.DrawText(lonLabel.Text,
new Point(position.X + StrokeThickness / 2d + 2d, position.Y + StrokeThickness / 2d));
drawingContext.Pop();
}
drawingContext.PushTransform(new RotateTransform(ParentMap.Heading, position.X, position.Y));
drawingContext.DrawText(latLabel.Text,
new Point(position.X + StrokeThickness / 2d + 2d, position.Y - StrokeThickness / 2d - latLabel.Text.Height));
drawingContext.DrawText(lonLabel.Text,
new Point(position.X + StrokeThickness / 2d + 2d, position.Y + StrokeThickness / 2d));
drawingContext.Pop();
}
}
}

View file

@ -8,8 +8,8 @@ using System.Windows;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.4.0")]
[assembly: AssemblyFileVersion("4.4.0")]
[assembly: AssemblyVersion("4.4.1")]
[assembly: AssemblyFileVersion("4.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]