/// <summary> /// Converts the feature to KML. /// </summary> /// <param name="item"></param> /// <param name="name"></param> /// <param name="geometryConversion"></param> /// <param name="z"></param> /// <param name="geometryElements"></param> /// <param name="placemarkElements"></param> /// <returns></returns> public static XElement ToKml(this MappableFeature item, string name, Func <IGeometry, IGeometry> geometryConversion = null, double z = 0, XElement[] geometryElements = null, params XElement[] placemarkElements) { if (geometryConversion == null) { geometryConversion = g => g; } return(new XElement(kml + "Placemark", new XElement(kml + "name", name), placemarkElements, new XElement(kml + "ExtendedData", from p in item.GetType().GetMappedProperties() select new XElement(kml + "Data", new XAttribute("name", p.MappedField.FieldName), new XElement(kml + "value", item[p.MappedField.FieldName]))), geometryConversion(item.Shape).ToKml(z, geometryElements))); }
/// <summary> /// Returns the JSON-serializable representation of this feature as a .NET dictionary. Use a weakly-typed JSON serializer to serialize this. /// </summary> /// <param name="feature"></param> /// <param name="includeGeometry"></param> /// <returns></returns> public static Dictionary <string, object> ToDictionary(this MappableFeature feature, bool includeGeometry = false) { var attributes = new Dictionary <string, object>(); if (feature.IsDataBound) { attributes.Add(feature.Table.OIDFieldName, feature.OID); } foreach (var o in feature.ToKeyValuePairs(p => p.MappedField.IncludeInJson)) { var value = o.Value; if (value != null) { if (value is DateTime) { value = Convert.ToInt64(((DateTime)value).Subtract(BaseTime).TotalMilliseconds); } else if (value is Guid) { value = ((Guid)value).ToString("B").ToUpper(); } } attributes.Add(o.Key, value); } var dictionary = new Dictionary <string, object> { { "attributes", attributes } }; if (includeGeometry && feature.Shape != null) { dictionary.Add("geometry", feature.Shape.ToJsonGeometry()); } return(dictionary); }
/// <summary> /// Return the JSON representation of this feature. /// </summary> /// <param name="feature"></param> /// <param name="includeGeometry"></param> /// <returns></returns> public static string Serialize(MappableFeature feature, bool includeGeometry) { return(SerializingFunction(feature.ToDictionary(includeGeometry))); }