Skip to content

Instantly share code, notes, and snippets.

@jbreuer
Created July 24, 2014 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbreuer/cc8d3686d74adca4e1f4 to your computer and use it in GitHub Desktop.
Save jbreuer/cc8d3686d74adca4e1f4 to your computer and use it in GitHub Desktop.
GoogleMapsConverter for Umbraco 7.1.5 or higher
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