mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-20 23:50:17 +01:00
Updated projection center update behavior
This commit is contained in:
parent
94e8edf18b
commit
c245a8f722
|
|
@ -8,6 +8,7 @@ namespace MapControl
|
|||
public abstract class AzimuthalProjection : MapProjection
|
||||
{
|
||||
protected AzimuthalProjection()
|
||||
: base(true)
|
||||
{
|
||||
Type = MapProjectionType.Azimuthal;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,9 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an optional center (reference point) for azimuthal projections.
|
||||
/// If ProjectionCenter is null, the Center property value will be used instead.
|
||||
/// Gets or sets a projection center e.g. for azimuthal projections.
|
||||
/// If ProjectionCenter is null, the value of the Center property is used as projection center.
|
||||
/// This behavior is overridden when the Center property of a MapProjection is set explicitly.
|
||||
/// </summary>
|
||||
public Location ProjectionCenter
|
||||
{
|
||||
|
|
@ -456,7 +457,7 @@ namespace MapControl
|
|||
var viewScale = ZoomLevelToScale(ZoomLevel);
|
||||
var projection = MapProjection;
|
||||
|
||||
projection.Center = ProjectionCenter ?? Center;
|
||||
projection.SetCenter(ProjectionCenter ?? Center);
|
||||
|
||||
var mapCenter = projection.LocationToMap(transformCenter ?? Center);
|
||||
|
||||
|
|
@ -496,7 +497,7 @@ namespace MapControl
|
|||
|
||||
ResetTransformCenter();
|
||||
|
||||
projection.Center = ProjectionCenter ?? Center;
|
||||
projection.SetCenter(ProjectionCenter ?? Center);
|
||||
|
||||
mapCenter = projection.LocationToMap(center);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace MapControl
|
|||
#else
|
||||
[System.ComponentModel.TypeConverter(typeof(MapProjectionConverter))]
|
||||
#endif
|
||||
public abstract class MapProjection
|
||||
public abstract class MapProjection(bool hasCenter = false)
|
||||
{
|
||||
public const double Wgs84EquatorialRadius = 6378137d;
|
||||
public const double Wgs84Flattening = 1d / 298.257223563;
|
||||
|
|
@ -60,19 +60,41 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public string CrsId { get; protected set; } = "";
|
||||
|
||||
private Location center;
|
||||
private bool updateCenter = hasCenter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an optional projection center.
|
||||
/// Gets or sets an optional projection center. If the property is set to a non-null value,
|
||||
/// it overrides the projection center set by MapBase.Center or MapBase.ProjectionCenter.
|
||||
/// </summary>
|
||||
public Location Center
|
||||
{
|
||||
get => field ??= new Location();
|
||||
protected internal set
|
||||
get => center ??= new Location();
|
||||
set
|
||||
{
|
||||
updateCenter = true;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
SetCenter(value);
|
||||
updateCenter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by MapBase.UpdateTransform().
|
||||
/// </summary>
|
||||
internal void SetCenter(Location value)
|
||||
{
|
||||
if (updateCenter)
|
||||
{
|
||||
var latitude = value.Latitude;
|
||||
var longitude = Location.NormalizeLongitude(value.Longitude);
|
||||
|
||||
if (field == null || !field.Equals(value.Latitude, longitude))
|
||||
if (center == null || !center.Equals(latitude, longitude))
|
||||
{
|
||||
field = new Location(value.Latitude, longitude);
|
||||
center = new Location(latitude, longitude);
|
||||
CenterChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ namespace MapControl.Projections
|
|||
/// </summary>
|
||||
public class ProjNetMapProjection : MapProjection
|
||||
{
|
||||
protected ProjNetMapProjection()
|
||||
protected ProjNetMapProjection(bool hasCenter = false)
|
||||
: base(hasCenter)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace MapControl.Projections
|
|||
public class Wgs84OrthographicProjection : ProjNetMapProjection
|
||||
{
|
||||
public Wgs84OrthographicProjection()
|
||||
: base(true)
|
||||
{
|
||||
CenterChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace MapControl.Projections
|
|||
public class Wgs84StereographicProjection : ProjNetMapProjection
|
||||
{
|
||||
public Wgs84StereographicProjection()
|
||||
: base(true)
|
||||
{
|
||||
CenterChanged();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue