mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-08 16:05:50 +00:00
Avoid unnecessary Location and Point allocations
This commit is contained in:
parent
f44d2207e5
commit
e268be2948
20 changed files with 205 additions and 172 deletions
|
|
@ -176,6 +176,15 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public ViewTransform ViewTransform { get; } = new ViewTransform();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map scale as horizontal and vertical scaling factors from meters to
|
||||
/// view coordinates at the specified geographic coordinates.
|
||||
/// </summary>
|
||||
public Point GetScale(double latitude, double longitude)
|
||||
{
|
||||
return ViewTransform.GetMapScale(MapProjection.GetRelativeScale(latitude, longitude));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map scale as horizontal and vertical scaling factors from meters to
|
||||
/// view coordinates at the specified location.
|
||||
|
|
@ -187,7 +196,7 @@ namespace MapControl
|
|||
|
||||
/// <summary>
|
||||
/// Gets a transform Matrix from meters to view coordinates for scaling and rotating
|
||||
/// objects that are anchored at a Location.
|
||||
/// objects that are anchored at the specified Location.
|
||||
/// </summary>
|
||||
public Matrix GetMapTransform(Location location)
|
||||
{
|
||||
|
|
@ -195,11 +204,11 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Location in geographic coordinates to a Point in view coordinates.
|
||||
/// Transforms geographic coordinates to a Point in view coordinates.
|
||||
/// </summary>
|
||||
public Point? LocationToView(Location location)
|
||||
public Point? LocationToView(double latitude, double longitude)
|
||||
{
|
||||
var point = MapProjection.LocationToMap(location);
|
||||
var point = MapProjection.LocationToMap(latitude, longitude);
|
||||
|
||||
if (point.HasValue)
|
||||
{
|
||||
|
|
@ -209,6 +218,14 @@ namespace MapControl
|
|||
return point;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Location in geographic coordinates to a Point in view coordinates.
|
||||
/// </summary>
|
||||
public Point? LocationToView(Location location)
|
||||
{
|
||||
return LocationToView(location.Latitude, location.Longitude);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Point in view coordinates to a Location in geographic coordinates.
|
||||
/// </summary>
|
||||
|
|
@ -343,8 +360,9 @@ namespace MapControl
|
|||
|
||||
if (mapRect.HasValue)
|
||||
{
|
||||
var rectCenter = new Point(mapRect.Value.X + mapRect.Value.Width / 2d, mapRect.Value.Y + mapRect.Value.Height / 2d);
|
||||
var targetCenter = MapProjection.MapToLocation(rectCenter);
|
||||
var targetCenter = MapProjection.MapToLocation(
|
||||
mapRect.Value.X + mapRect.Value.Width / 2d,
|
||||
mapRect.Value.Y + mapRect.Value.Height / 2d);
|
||||
|
||||
if (targetCenter != null)
|
||||
{
|
||||
|
|
@ -428,7 +446,7 @@ namespace MapControl
|
|||
|
||||
if (projection.Type <= MapProjectionType.NormalCylindrical)
|
||||
{
|
||||
var maxLocation = projection.MapToLocation(new Point(0d, 180d * MapProjection.Wgs84MeterPerDegree));
|
||||
var maxLocation = projection.MapToLocation(0d, 180d * MapProjection.Wgs84MeterPerDegree);
|
||||
|
||||
if (maxLocation != null && maxLocation.Latitude < 90d)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue