//----------------------------------------------------------------------- // // Copyright (c) 2016 Mapbox. All rights reserved. // //----------------------------------------------------------------------- namespace Mapbox.Utils.JsonConverters { using System; using Mapbox.Json; using Mapbox.Json.Converters; using Mapbox.Json.Linq; /// /// Bbox to geo coordinate bounds converter. /// public class BboxToVector2dBoundsConverter : CustomCreationConverter { /// /// Gets a value indicating whether this can write. /// /// true if can write; otherwise, false. public override bool CanWrite { get { return true; } } /// /// Create the specified objectType. /// /// Object type. /// A . public override Vector2dBounds Create(Type objectType) { throw new NotImplementedException(); } /// /// Create the specified objectType and jArray. /// /// Object type. /// J array. /// A . public Vector2dBounds Create(Type objectType, JArray val) { return new Vector2dBounds( new Vector2d((double)val[0], (double)val[1]), new Vector2d((double)val[2], (double)val[3])); } /// /// Reads the json. /// /// The serialized object. /// A reader. /// Object type. /// Existing value. /// A . public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JArray bbox = JArray.Load(reader); return Create(objectType, bbox); } /// /// Writes the JSON as an array. /// /// A . /// The value to serialize. /// A . public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var val = (Vector2dBounds)value; // TODO: This is not working correctly, and setting "bbox: [0,0,0,0]" to Vector2d properties for some reason. System.Diagnostics.Debug.WriteLine(val); serializer.Serialize(writer, val.ToArray()); } } }