wrap the json flight history as a feature
this allows to attach properties later
This commit is contained in:
parent
548b899fb6
commit
0fcfbe9221
1 changed files with 24 additions and 4 deletions
|
@ -32,10 +32,30 @@ using std::stringstream;
|
||||||
namespace flightgear {
|
namespace flightgear {
|
||||||
namespace http {
|
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 * coordinates = cJSON_CreateArray();
|
||||||
cJSON_AddItemToObject(lineString, "coordinates", coordinates);
|
cJSON_AddItemToObject(lineString, "coordinates", coordinates);
|
||||||
for (SGGeodVec::const_iterator it = history.begin(); it != history.end();
|
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);
|
string reply(jsonString);
|
||||||
free(jsonString);
|
free(jsonString);
|
||||||
cJSON_Delete(lineString);
|
cJSON_Delete(lineString);
|
||||||
|
|
Loading…
Add table
Reference in a new issue