]> git.mxchange.org Git - flightgear.git/commitdiff
wrap the json flight history as a feature
authorTorsten Dreyer <torsten@ŧ3r.de>
Fri, 27 Feb 2015 14:54:28 +0000 (15:54 +0100)
committerTorsten Dreyer <torsten@ŧ3r.de>
Fri, 27 Feb 2015 14:54:28 +0000 (15:54 +0100)
this allows to attach properties later

src/Network/http/FlightHistoryUriHandler.cxx

index d5e336c92e9820f2ed75fc96d9d72800fec823a4..c4654ee887b1670017be4f18c266fe27e0249153 100644 (file)
@@ -32,10 +32,30 @@ using std::stringstream;
 namespace flightgear {
 namespace http {
 
+/*
+{
+  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(lineString, "type", cJSON_CreateString("LineString"));
+       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);