mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-24 06:53:46 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
114
map/gps_tracker.cpp
Normal file
114
map/gps_tracker.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "map/gps_tracker.hpp"
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "base/file_name_utils.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
char const kEnabledKey[] = "GpsTrackingEnabled";
|
||||
|
||||
inline std::string GetFilePath()
|
||||
{
|
||||
return base::JoinPath(GetPlatform().WritableDir(), GPS_TRACK_FILENAME);
|
||||
}
|
||||
|
||||
inline bool GetSettingsIsEnabled()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kEnabledKey, enabled))
|
||||
enabled = false;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
inline void SetSettingsIsEnabled(bool enabled)
|
||||
{
|
||||
settings::Set(kEnabledKey, enabled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GpsTracker & GpsTracker::Instance()
|
||||
{
|
||||
static GpsTracker instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
GpsTracker::GpsTracker()
|
||||
: m_enabled(GetSettingsIsEnabled())
|
||||
, m_track(GetFilePath(), std::make_unique<GpsTrackFilter>())
|
||||
{
|
||||
}
|
||||
|
||||
void GpsTracker::SetEnabled(bool enabled)
|
||||
{
|
||||
if (enabled == m_enabled)
|
||||
return;
|
||||
|
||||
SetSettingsIsEnabled(enabled);
|
||||
m_enabled = enabled;
|
||||
|
||||
if (enabled)
|
||||
m_track.Clear();
|
||||
}
|
||||
|
||||
void GpsTracker::Clear()
|
||||
{
|
||||
m_track.Clear();
|
||||
}
|
||||
|
||||
bool GpsTracker::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
bool GpsTracker::IsEmpty() const
|
||||
{
|
||||
return m_track.IsEmpty();
|
||||
}
|
||||
|
||||
size_t GpsTracker::GetTrackSize() const
|
||||
{
|
||||
return m_track.GetSize();
|
||||
}
|
||||
|
||||
TrackStatistics GpsTracker::GetTrackStatistics() const
|
||||
{
|
||||
return m_track.GetTrackStatistics();
|
||||
}
|
||||
|
||||
const ElevationInfo & GpsTracker::GetElevationInfo() const
|
||||
{
|
||||
return m_track.GetElevationInfo();
|
||||
}
|
||||
|
||||
void GpsTracker::Connect(TGpsTrackDiffCallback const & fn)
|
||||
{
|
||||
m_track.SetCallback(fn);
|
||||
}
|
||||
|
||||
void GpsTracker::Disconnect()
|
||||
{
|
||||
m_track.SetCallback(nullptr);
|
||||
}
|
||||
|
||||
void GpsTracker::OnLocationUpdated(location::GpsInfo const & info)
|
||||
{
|
||||
if (!m_enabled)
|
||||
return;
|
||||
m_track.AddPoint(info);
|
||||
}
|
||||
|
||||
void GpsTracker::ForEachTrackPoint(GpsTrackCallback const & callback) const
|
||||
{
|
||||
CHECK(callback != nullptr, ("Callback should be provided"));
|
||||
m_track.ForEachPoint(callback);
|
||||
}
|
||||
Reference in New Issue
Block a user