52 assert( navRecord != NULL );
54 cJSON * geometry = cJSON_CreateObject();
66 for (
int i = -1;
i <= +1;
i++) {
67 double c = SGMiscd::normalizeAngle((course + 180 +
i * width / 2) * SG_DEGREES_TO_RADIANS);
68 SGGeoc geoc = SGGeoc::fromGeod(navRecord->
geod());
69 SGGeod
p2 = SGGeod::fromGeoc(geoc.advanceRadM(c, range * SG_NM_TO_METER));
70 px[
i + 2] =
p2.getLongitudeDeg();
71 py[
i + 2] =
p2.getLatitudeDeg();
74 cJSON_AddItemToObject(geometry,
"type", cJSON_CreateString(
"MultiLineString"));
75 cJSON * coordinates = cJSON_CreateArray();
76 cJSON_AddItemToObject(geometry,
"coordinates", coordinates);
77 for (
int i = 1;
i < 4;
i++) {
78 cJSON * line = cJSON_CreateArray();
79 cJSON_AddItemToArray(coordinates, line);
98 cJSON * polygon = cJSON_CreateObject();
99 cJSON_AddItemToObject(polygon,
"type", cJSON_CreateString(
"Polygon"));
100 cJSON * coordinates = cJSON_CreateArray();
101 cJSON_AddItemToObject(polygon,
"coordinates", coordinates );
102 cJSON * linearRing = cJSON_CreateArray();
103 cJSON_AddItemToArray( coordinates, linearRing );
110 cJSON_AddItemToArray( linearRing,
createPositionArray(p1.getLongitudeDeg(), p1.getLatitudeDeg()) );
112 cJSON_AddItemToArray( linearRing,
createPositionArray(p3.getLongitudeDeg(), p3.getLatitudeDeg()) );
113 cJSON_AddItemToArray( linearRing,
createPositionArray(p4.getLongitudeDeg(), p4.getLatitudeDeg()) );
115 cJSON_AddItemToArray( linearRing,
createPositionArray(p1.getLongitudeDeg(), p1.getLatitudeDeg()) );
121 assert( airport != NULL );
124 if( runways.empty() ) {
129 cJSON * geometry = cJSON_CreateObject();
132 cJSON_AddItemToObject(geometry,
"type", cJSON_CreateString(
"GeometryCollection"));
133 cJSON * geometryCollection = cJSON_CreateArray();
134 cJSON_AddItemToObject(geometry,
"geometries", geometryCollection);
140 for( FGRunwayList::iterator it = runways.begin(); it != runways.end(); ++it ) {
146 for( FGTaxiwayList::iterator it = taxiways.begin(); it != taxiways.end(); ++it ) {
170 if( NULL == airport )
return;
171 double longestRunwayLength = 0.0;
172 double longestRunwayHeading = 0.0;
173 const char * longestRunwaySurface =
"";
175 cJSON_AddItemToObject(json,
"name", cJSON_CreateString(airport->
getName().c_str()));
176 cJSON * runwaysJson = cJSON_CreateArray();
177 cJSON_AddItemToObject(json,
"runways", runwaysJson);
180 for( FGRunwayList::iterator it = runways.begin(); it != runways.end(); ++it ) {
182 cJSON * runwayJson = cJSON_CreateObject();
183 cJSON_AddItemToArray( runwaysJson, runwayJson );
184 cJSON_AddItemToObject(runwayJson,
"id", cJSON_CreateString(runway->
ident().c_str()));
185 cJSON_AddItemToObject(runwayJson,
"length_m", cJSON_CreateNumber(runway->
lengthM()));
186 cJSON_AddItemToObject(runwayJson,
"width_m", cJSON_CreateNumber(runway->
widthM()));
187 cJSON_AddItemToObject(runwayJson,
"surface", cJSON_CreateString(runway->
surfaceName()));
188 cJSON_AddItemToObject(runwayJson,
"heading_deg", cJSON_CreateNumber(runway->
headingDeg()));
191 cJSON_AddItemToObject(runwayJson,
"dispacedThreshold_m", cJSON_CreateNumber(d));
195 cJSON_AddItemToObject(runwayJson,
"stopway_m", cJSON_CreateNumber(d));
197 if( runway->
lengthM() > longestRunwayLength ) {
198 longestRunwayLength = runway->
lengthM();
203 cJSON_AddItemToObject(json,
"longestRwyLength_m", cJSON_CreateNumber(longestRunwayLength));
204 cJSON_AddItemToObject(json,
"longestRwyHeading_deg", cJSON_CreateNumber(longestRunwayHeading));
205 cJSON_AddItemToObject(json,
"longestRwySurface", cJSON_CreateString(longestRunwaySurface));
207 cJSON_AddItemToObject(json,
"metar", cJSON_CreateTrue());
210 cJSON * commsJson = cJSON_CreateArray();
211 cJSON_AddItemToObject(json,
"comm", commsJson);
213 for( flightgear::CommStationList::iterator it = comms.begin(); it != comms.end(); ++it ) {
215 cJSON * commJson = cJSON_CreateObject();
216 cJSON_AddItemToArray( commsJson, commJson );
217 cJSON_AddItemToObject(commJson,
"id", cJSON_CreateString(comm->
ident().c_str()));
218 cJSON_AddItemToObject(commJson,
"mhz", cJSON_CreateNumber(comm->
freqMHz()));
224 if( NULL == navRecord )
return;
225 cJSON_AddItemToObject(json,
"range_nm", cJSON_CreateNumber(navRecord->
get_range()));
226 cJSON_AddItemToObject(json,
"frequency", cJSON_CreateNumber((
double) navRecord->
get_freq() / 100.0));
227 switch (navRecord->
type()) {
230 cJSON_AddItemToObject(json,
"localizer-course", cJSON_CreateNumber(navRecord->
get_multiuse()));
234 cJSON_AddItemToObject(json,
"variation", cJSON_CreateNumber(navRecord->
get_multiuse()));
244 cJSON * properties = cJSON_CreateObject();
246 cJSON_AddItemToObject(properties,
"name", cJSON_CreateString(positioned->
name().c_str()));
248 cJSON_AddItemToObject(properties,
"id", cJSON_CreateString(positioned->
ident().c_str()));
249 cJSON_AddItemToObject(properties,
"type", cJSON_CreateString(positioned->
typeString()));
250 cJSON_AddItemToObject(properties,
"elevation-m", cJSON_CreateNumber(positioned->
elevationM()));
281 response.
Header[
"Content-Type"] =
"application/json; charset=UTF-8";
282 response.
Header[
"Access-Control-Allow-Origin"] =
"*";
283 response.
Header[
"Access-Control-Allow-Methods"] =
"OPTIONS, GET";
284 response.
Header[
"Access-Control-Allow-Headers"] =
"Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token";
286 if( request.
Method ==
"OPTIONS" ){
290 if( request.
Method !=
"GET" ){
291 response.
Header[
"Allow"] =
"OPTIONS, GET";
302 if (query ==
"findWithinRange") {
305 double lat, lon, range = -1;
315 if (range <= 1.0)
goto fail;
318 SGGeod pos = SGGeod::fromDeg(lon, lat);
328 }
else if (query ==
"airports") {
329 cJSON * json = cJSON_CreateArray();
331 cJSON_AddItemToArray(json, cJSON_CreateString(*airports));
333 char * jsonString = indent ? cJSON_Print(json) : cJSON_PrintUnformatted(json);
339 }
else if (query ==
"airport") {
341 if( airport.valid() )
342 result.push_back( airport );
349 cJSON * geoJSON = cJSON_CreateObject();
353 cJSON_AddItemToObject(geoJSON,
"type", cJSON_CreateString(
"FeatureCollection"));
359 cJSON * featureCollection = cJSON_CreateArray();
360 cJSON_AddItemToObject(geoJSON,
"features", featureCollection);
362 for (FGPositionedList::iterator it = result.begin(); it != result.end(); ++it) {
367 char * jsonString = indent ? cJSON_Print(geoJSON) : cJSON_PrintUnformatted(geoJSON);
368 cJSON_Delete(geoJSON);
376 response.
Content =
"{ 'error': 'bad request' }";