- double hdg = rwy->_heading;
- hdg += 180.0;
- if ( hdg > 360.0 ) {
- hdg -= 360.0;
- }
-
- // calculate runway threshold point
- double thresh_lat, thresh_lon, return_az;
- geo_direct_wgs_84 ( 0.0, rwy->_lat, rwy->_lon, hdg,
- rwy->_length/2.0 * SG_FEET_TO_METER,
- &thresh_lat, &thresh_lon, &return_az );
- // cout << "Threshold = " << thresh_lat << "," << thresh_lon << endl;
-
- // calculate distance from threshold to localizer
- double az1, az2, dist_m;
- geo_inverse_wgs_84( 0.0, loc->get_lat(), loc->get_lon(),
- thresh_lat, thresh_lon,
- &az1, &az2, &dist_m );
- // cout << "Distance = " << dist_m << endl;
-
- // back project that distance along the runway center line
- double nloc_lat, nloc_lon;
- geo_direct_wgs_84 ( 0.0, thresh_lat, thresh_lon, hdg + 180.0,
- dist_m, &nloc_lat, &nloc_lon, &return_az );
- // printf("New localizer = %.6f %.6f\n", nloc_lat, nloc_lon );
-
- // sanity check, how far have we moved the localizer?
- geo_inverse_wgs_84( 0.0, loc->get_lat(), loc->get_lon(),
- nloc_lat, nloc_lon,
- &az1, &az2, &dist_m );
- // cout << "Distance moved = " << dist_m << endl;
-
- // cout << "orig heading = " << loc->get_multiuse() << endl;
- // cout << "new heading = " << rwy->_heading << endl;
-
- double hdg_diff = loc->get_multiuse() - rwy->_heading;
-
- // clamp to [-180.0 ... 180.0]
- if ( hdg_diff < -180.0 ) {
- hdg_diff += 360.0;
- } else if ( hdg_diff > 180.0 ) {
- hdg_diff -= 360.0;
- }
-
- if ( fabs(hdg_diff) <= threshold ) {
- loc->set_lat( nloc_lat );
- loc->set_lon( nloc_lon );
- loc->set_multiuse( rwy->_heading );
+ if (!fgGetBool("/sim/paths/use-custom-scenery-data")) {
+ return NULL;
+ }
+
+ if (!aRunway) {
+ return NULL;
+ }
+
+ FGAirport* apt = aRunway->airport();
+// find (or load) the airprot ILS data
+ AirportPropertyMap::iterator it = static_airportIlsData.find(apt);
+ if (it == static_airportIlsData.end()) {
+ SGPath path;
+ if (!XMLLoader::findAirportData(apt->ident(), "ils", path)) {
+ // no ils.xml file for this airpot, insert a NULL entry so we don't
+ // check again
+ static_airportIlsData.insert(it, std::make_pair(apt, SGPropertyNode_ptr()));
+ return NULL;