This commit is contained in:
runette committed 2024-04-22 15:52:51 +01:00
commit e0afef912e
1285 files changed
+83219

No files matched your search

@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
// <copyright file="BboxToVector2dBoundsConverter.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Utils.JsonConverters
{
using System;
using Mapbox.Json;
using Mapbox.Json.Converters;
using Mapbox.Json.Linq;
/// <summary>
/// Bbox to geo coordinate bounds converter.
/// </summary>
public class BboxToVector2dBoundsConverter : CustomCreationConverter<Vector2dBounds>
{
/// <summary>
/// Gets a value indicating whether this <see cref="T:Mapbox.BboxToVector2dBoundsConverter"/> can write.
/// </summary>
/// <value><c>true</c> if can write; otherwise, <c>false</c>.</value>
public override bool CanWrite {
get { return true; }
}
/// <summary>
/// Create the specified objectType.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <returns>A <see cref="Vector2dBounds"/>.</returns>
public override Vector2dBounds Create(Type objectType)
{
throw new NotImplementedException();
}
/// <summary>
/// Create the specified objectType and jArray.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <param name="val">J array.</param>
/// <returns>A <see cref="Vector2dBounds"/>.</returns>
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]));
}
/// <summary>
/// Reads the json.
/// </summary>
/// <returns>The serialized object.</returns>
/// <param name="reader">A reader.</param>
/// <param name="objectType">Object type.</param>
/// <param name="existingValue">Existing value.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JArray bbox = JArray.Load(reader);
return Create(objectType, bbox);
}
/// <summary>
/// Writes the JSON as an array.
/// </summary>
/// <param name="writer">A <see cref="JsonWriter"/>.</param>
/// <param name="value">The value to serialize.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
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());
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 382bc19f5f34f4f14985294dbd8d4f73
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
//-----------------------------------------------------------------------
// <copyright file="JsonConverters.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Utils.JsonConverters
{
using Mapbox.Json;
/// <summary>
/// Custom json converters.
/// </summary>
public static class JsonConverters
{
/// <summary>
/// Array of converters.
/// </summary>
private static JsonConverter[] converters =
{
new LonLatToVector2dConverter(),
new BboxToVector2dBoundsConverter(),
new PolylineToVector2dListConverter()
};
/// <summary>
/// Gets the converters.
/// </summary>
/// <value>The converters.</value>
public static JsonConverter[] Converters {
get {
return converters;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f95c54018d5ac404bbe0b84d5dc3ab9a
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
// <copyright file="LonLatToVector2dConverter.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Utils.JsonConverters
{
using System;
using Mapbox.Json;
using Mapbox.Json.Converters;
using Mapbox.Json.Linq;
/// <summary>
/// Bbox to geo coordinate bounds converter.
/// </summary>
public class LonLatToVector2dConverter : CustomCreationConverter<Vector2d>
{
/// <summary>
/// Gets a value indicating whether this <see cref="T:Mapbox.LonLatToVector2dConverter"/> can write.
/// </summary>
/// <value><c>true</c> if can write; otherwise, <c>false</c>.</value>
public override bool CanWrite {
get { return true; }
}
/// <summary>
/// Create the specified objectType.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <returns>A <see cref="Vector2d"/>.</returns>
public override Vector2d Create(Type objectType)
{
throw new NotImplementedException();
}
/// <summary>
/// Create the specified objectType and jArray.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <param name="val">Jarray representing a two length array of coordinates.</param>
/// <returns>A <see cref="Vector2d"/>.</returns>
public Vector2d Create(Type objectType, JArray val)
{
// Assumes long,lat order (like in geojson)
return new Vector2d(y: (double)val[0], x: (double)val[1]);
}
/// <summary>
/// Writes the json.
/// </summary>
/// <param name="writer">A <see cref="JsonWriter"/>.</param>
/// <param name="value">The value to serialize.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var val = (Vector2d)value;
Array valAsArray = val.ToArray();
// By default, Vector2d outputs an array with [lat, lon] order, but we want the reverse.
Array.Reverse(valAsArray);
serializer.Serialize(writer, valAsArray);
}
/// <summary>
/// Reads the json.
/// </summary>
/// <returns>The serialized object.</returns>
/// <param name="reader">A reader.</param>
/// <param name="objectType">Object type.</param>
/// <param name="existingValue">Existing value.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
/// <returns>An object.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JArray coordinates = JArray.Load(reader);
return Create(objectType, coordinates);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4974791f7db3740088cca9acd2104670
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
// <copyright file="PolylineToVector2dListConverter.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Utils.JsonConverters
{
using System;
using System.Collections.Generic;
using Mapbox.Json;
using Mapbox.Json.Converters;
using Mapbox.Json.Linq;
/// <summary>
/// Bbox to geo coordinate bounds converter.
/// </summary>
public class PolylineToVector2dListConverter : CustomCreationConverter<List<Vector2d>>
{
/// <summary>
/// Gets a value indicating whether this <see cref="T:Mapbox.PolylineToVector2dListConverter"/> can write.
/// </summary>
/// <value><c>true</c> if can write; otherwise, <c>false</c>.</value>
public override bool CanWrite {
get { return true; }
}
/// <summary>
/// Create the specified objectType.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <returns>A List of <see cref="Vector2d"/>.</returns>
public override List<Vector2d> Create(Type objectType)
{
throw new NotImplementedException();
}
/// <summary>
/// Create the specified objectType and jArray.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <param name="polyLine">String representation of a polyLine.</param>
/// <returns>A List of <see cref="Vector2d"/>.</returns>
public List<Vector2d> Create(Type objectType, string polyLine)
{
return PolylineUtils.Decode(polyLine);
}
/// <summary>
/// Writes the JSON as an encoded polyline.
/// </summary>
/// <param name="writer">A <see cref="JsonWriter"/>.</param>
/// <param name="value">The original value.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var val = (List<Vector2d>)value;
serializer.Serialize(writer, PolylineUtils.Encode(val));
}
/// <summary>
/// Reads the json. Must be a linestring.
/// </summary>
/// <returns>The serialized object.</returns>
/// <param name="reader">A Reader.</param>
/// <param name="objectType">Object type.</param>
/// <param name="existingValue">Existing value.</param>
/// <param name="serializer">A <see cref="JsonSerializer"/>.</param>
/// <returns>An object.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken polyLine = JToken.Load(reader);
return Create(objectType, (string)polyLine);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 37d418b3df007437d873ac93f792c69b
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: