@@ -169,6 +169,23 @@ bool Sky::init()
169169 else
170170 m_mode = TEXTURE ; });
171171
172+ jumpToSkyButton = new ui::Button (skyGroup, " jumpToSky" );
173+ jumpToSkyButton->setText (" Jump to Sky" );
174+ jumpToSkyButton->setCallback ([this ](bool state)
175+ {
176+ if (state)
177+ {
178+ int selection = skyList->selectedIndex ();
179+ if (selection >= skyListNameStart)
180+ {
181+ const auto &sky = m_skies[selection - skyListNameStart];
182+ osg::Vec3d globalSkyOrigin (sky.longitude , sky.latitude , sky.altitude );
183+ osg::Vec3 projectSkyOrigin = GeoData::instance ()->globalToProject (globalSkyOrigin);
184+ GeoData::instance ()->jumpToLocation (projectSkyOrigin);
185+ }
186+ jumpToSkyButton->setState (false );
187+ } });
188+
172189 northAngle = 0 ;
173190 update ();
174191
@@ -234,7 +251,7 @@ void Sky::loadSkies()
234251 updateSkyMenu ();
235252}
236253
237- void parseExifData (const std::filesystem::path &path, double &longitude, double &latitude, double &trueNorth)
254+ void parseExifData (const std::filesystem::path &path, double &longitude, double &latitude, double &altitude, double & trueNorth)
238255{
239256 std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open (path.string ().c_str ());
240257 if (!image)
@@ -263,6 +280,12 @@ void parseExifData(const std::filesystem::path &path, double &longitude, double
263280 longitude = deg.first / (1.0 * deg.second ) + min.first / (60.0 * min.second ) + sec.first / (3600.0 * sec.second );
264281 }
265282
283+ auto altIt = exif.findKey (Exiv2::ExifKey (" Exif.GPSInfo.GPSAltitude" ));
284+ if (altIt != exif.end ())
285+ {
286+ altitude = exif[" Exif.GPSInfo.GPSAltitude" ].toFloat ();
287+ }
288+
266289 Exiv2::XmpData &xmpData = image->xmpData ();
267290 if (!xmpData.empty ())
268291 {
@@ -295,16 +318,16 @@ std::optional<std::reference_wrapper<SkyEntry>> Sky::addSkyFile(std::filesystem:
295318 return std::nullopt ;
296319 }
297320
298- double latitude = 0 , longitude = 0 , trueNorth = 0 ;
299- parseExifData (path, longitude, latitude, trueNorth);
321+ double latitude = 0 , longitude = 0 , altitude = 0 , trueNorth = 0 ;
322+ parseExifData (path, longitude, latitude, altitude, trueNorth);
300323
301324 trueNorth = std::fmod (trueNorth + 360.0 + 180.0 , 360.0 ) - 180.0 ;
302325 longitude = std::fmod (longitude + 360.0 + 180.0 , 360.0 ) - 180.0 ;
303326 latitude = std::clamp (latitude, -90.0 , 90.0 );
304327
305- std::cout << " Parsed from EXIF: latitude=" << latitude << " longitude=" << longitude << " trueNorth=" << trueNorth << std::endl;
328+ std::cout << " EXIF: Parsed " << path. parent_path (). filename (). string () << " / " << fileName << " latitude=" << latitude << " longitude=" << longitude << " altitude= " << altitude << " trueNorth=" << trueNorth << std::endl;
306329
307- return m_skies.emplace_back (SkyEntry (name, std::regex_replace (name, std::regex (" /" ), " → " ), path.string (), longitude, latitude, trueNorth));
330+ return m_skies.emplace_back (SkyEntry (name, std::regex_replace (name, std::regex (" /" ), " → " ), path.string (), longitude, latitude, altitude, trueNorth));
308331
309332 return std::nullopt ;
310333}
0 commit comments