flighthistory service: use GeoJSON instead of own invention
Track now comes as a LineString object { "type":"LineString", "coordinates": [ [lon,lat,alt], [lon,lat,alt], ... ] } ref: http://geojson.org/geojson-spec.html#linestring
This commit is contained in:
parent
f36c81c8cb
commit
0034d6b59a
1 changed files with 16 additions and 21 deletions
|
@ -32,33 +32,27 @@ using std::stringstream;
|
||||||
namespace flightgear {
|
namespace flightgear {
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
static cJSON * GeodToJson(const SGGeod & geod) {
|
|
||||||
cJSON * json = cJSON_CreateObject();
|
|
||||||
|
|
||||||
cJSON_AddItemToObject(json, "latitude",
|
|
||||||
cJSON_CreateNumber(geod.getLatitudeDeg()));
|
|
||||||
cJSON_AddItemToObject(json, "longitude",
|
|
||||||
cJSON_CreateNumber(geod.getLongitudeDeg()));
|
|
||||||
cJSON_AddItemToObject(json, "altitude",
|
|
||||||
cJSON_CreateNumber(geod.getElevationFt()));
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
static string FlightHistoryToJson(const SGGeodVec & history) {
|
static string FlightHistoryToJson(const SGGeodVec & history) {
|
||||||
cJSON * json = cJSON_CreateObject();
|
cJSON * lineString = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(lineString, "type", cJSON_CreateString("LineString"));
|
||||||
|
|
||||||
cJSON * jsonArray = cJSON_CreateArray();
|
cJSON * coordinates = cJSON_CreateArray();
|
||||||
|
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();
|
||||||
++it) {
|
++it) {
|
||||||
cJSON_AddItemToArray(jsonArray, GeodToJson(*it));
|
cJSON * coordinate = cJSON_CreateArray();
|
||||||
}
|
cJSON_AddItemToArray(coordinates, coordinate);
|
||||||
cJSON_AddItemToObject(json, "flightHistory", jsonArray);
|
|
||||||
|
|
||||||
char * jsonString = cJSON_PrintUnformatted(json);
|
cJSON_AddItemToArray(coordinate, cJSON_CreateNumber(it->getLongitudeDeg()));
|
||||||
|
cJSON_AddItemToArray(coordinate, cJSON_CreateNumber(it->getLatitudeDeg()));
|
||||||
|
cJSON_AddItemToArray(coordinate, cJSON_CreateNumber(it->getElevationM()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char * jsonString = cJSON_PrintUnformatted(lineString);
|
||||||
string reply(jsonString);
|
string reply(jsonString);
|
||||||
free(jsonString);
|
free(jsonString);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(lineString);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,8 +257,9 @@ bool FlightHistoryUriHandler::handleRequest(const HTTPRequest & request,
|
||||||
history->pathForHistory(minEdgeLengthM));
|
history->pathForHistory(minEdgeLengthM));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
response.Header["Content-Type"] = "text/html";
|
||||||
response.StatusCode = 404;
|
response.StatusCode = 404;
|
||||||
response.Content = "{}";
|
response.Content = "<html><head><title>Not found!</title></head><body>404</body></html>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue