Created
July 24, 2014 15:22
-
-
Save jbreuer/cc8d3686d74adca4e1f4 to your computer and use it in GitHub Desktop.
GoogleMapsConverter for Umbraco 7.1.5 or higher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GoogleMapsConverter : PropertyValueConverterBase, IPropertyValueConverterMeta | |
{ | |
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) | |
{ | |
if(source != null && !string.IsNullOrWhiteSpace(source.ToString())) | |
{ | |
var coordinates = source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); | |
if (coordinates.Length == 3) | |
{ | |
return new GoogleMaps | |
{ | |
Lat = decimal.Parse(coordinates[0]), | |
Lng = decimal.Parse(coordinates[1]), | |
Zoom = int.Parse(coordinates[2]) | |
}; | |
} | |
} | |
return null; | |
} | |
public override bool IsConverter(PublishedPropertyType propertyType) | |
{ | |
return "AngularGoogleMaps".InvariantEquals(propertyType.PropertyEditorAlias); | |
} | |
public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, PropertyCacheValue cacheValue) | |
{ | |
return PropertyCacheLevel.Content; | |
} | |
public Type GetPropertyValueType(PublishedPropertyType propertyType) | |
{ | |
return typeof(GoogleMaps); | |
} | |
} | |
public class GoogleMaps | |
{ | |
public decimal Lat { get; set; } | |
public decimal Lng { get; set; } | |
public int Zoom { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment