From 0fcfbe9221b84357c25266cecc34ac2f17bb6d14 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Fri, 27 Feb 2015 15:54:28 +0100 Subject: [PATCH] wrap the json flight history as a feature this allows to attach properties later --- src/Network/http/FlightHistoryUriHandler.cxx | 28 +++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Network/http/FlightHistoryUriHandler.cxx b/src/Network/http/FlightHistoryUriHandler.cxx index d5e336c92..c4654ee88 100644 --- a/src/Network/http/FlightHistoryUriHandler.cxx +++ b/src/Network/http/FlightHistoryUriHandler.cxx @@ -32,10 +32,30 @@ using std::stringstream; namespace flightgear { namespace http { -static string FlightHistoryToJson(const SGGeodVec & history) { - cJSON * lineString = cJSON_CreateObject(); - cJSON_AddItemToObject(lineString, "type", cJSON_CreateString("LineString")); +/* +{ + type: "Feature", + geometry: { + type: "LineString", + coordinates: [lon,lat,alt],..] + }, + properties: { + type: "FlightHistory" + }, +} +*/ +static string FlightHistoryToJson(const SGGeodVec & history) { + cJSON * feature = cJSON_CreateObject(); + cJSON_AddItemToObject(feature, "type", cJSON_CreateString("Feature")); + + cJSON * lineString = cJSON_CreateObject(); + cJSON_AddItemToObject(feature, "geometry", lineString ); + + cJSON * properties = cJSON_CreateObject(); + cJSON_AddItemToObject(feature, "properties", properties ); + + cJSON_AddItemToObject(lineString, "type", cJSON_CreateString("LineString")); cJSON * coordinates = cJSON_CreateArray(); cJSON_AddItemToObject(lineString, "coordinates", coordinates); for (SGGeodVec::const_iterator it = history.begin(); it != history.end(); @@ -49,7 +69,7 @@ static string FlightHistoryToJson(const SGGeodVec & history) { } - char * jsonString = cJSON_PrintUnformatted(lineString); + char * jsonString = cJSON_PrintUnformatted(feature); string reply(jsonString); free(jsonString); cJSON_Delete(lineString);