TypeConverter for MapProjection

This commit is contained in:
ClemensFischer 2025-09-06 13:06:00 +02:00
parent de6bc52d10
commit 17a481c773
2 changed files with 45 additions and 4 deletions

View file

@ -19,6 +19,11 @@ namespace MapControl
/// <summary> /// <summary>
/// Defines a map projection between geographic coordinates and cartesian map coordinates. /// Defines a map projection between geographic coordinates and cartesian map coordinates.
/// </summary> /// </summary>
#if UWP || WINUI
[Windows.Foundation.Metadata.CreateFromString(MethodName = "Parse")]
#else
[System.ComponentModel.TypeConverter(typeof(MapProjectionConverter))]
#endif
public abstract class MapProjection public abstract class MapProjection
{ {
public const double Wgs84EquatorialRadius = 6378137d; public const double Wgs84EquatorialRadius = 6378137d;
@ -131,5 +136,18 @@ namespace MapControl
return rotatedRect; return rotatedRect;
} }
public override string ToString()
{
return CrsId;
}
/// <summary>
/// Creates a MapProjection instance from a CRS id string.
/// </summary>
public static MapProjection Parse(string crsId)
{
return MapProjectionFactory.Instance.GetProjection(crsId);
}
} }
} }

View file

@ -32,7 +32,7 @@ namespace MapControl
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture) public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{ {
return Location.Parse(value.ToString()); return ConvertFrom(value.ToString());
} }
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture) public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
@ -55,7 +55,7 @@ namespace MapControl
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture) public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{ {
return LocationCollection.Parse(value.ToString()); return ConvertFrom(value.ToString());
} }
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture) public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
@ -78,7 +78,7 @@ namespace MapControl
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture) public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{ {
return BoundingBox.Parse(value.ToString()); return ConvertFrom(value.ToString());
} }
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture) public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
@ -101,7 +101,30 @@ namespace MapControl
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture) public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{ {
return TileSource.Parse(value.ToString()); return ConvertFrom(value.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
}
}
public class MapProjectionConverter : TypeConverter, IValueConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return MapProjection.Parse(value.ToString());
}
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
} }
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture) public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)