[map] Save points altitudes when saving route as a track (#10759)

[map] Save points altitudes when saving route as a track

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn
2025-06-24 18:19:09 +04:00
committed by Konstantin Pastbin
parent 21cc2bbf52
commit cc6958282b
8 changed files with 31 additions and 18 deletions

View File

@@ -1297,7 +1297,7 @@ Java_app_organicmaps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jclass)
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_app_organicmaps_Framework_nativeGetRouteJunctionPoints(JNIEnv * env, jclass) Java_app_organicmaps_Framework_nativeGetRouteJunctionPoints(JNIEnv * env, jclass)
{ {
vector<m2::PointD> junctionPoints; vector<geometry::PointWithAltitude> junctionPoints;
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(junctionPoints)) if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(junctionPoints))
{ {
LOG(LWARNING, ("Can't get the route junction points")); LOG(LWARNING, ("Can't get the route junction points"));

View File

@@ -2,19 +2,20 @@
#include "app/organicmaps/core/jni_helper.hpp" #include "app/organicmaps/core/jni_helper.hpp"
#include "geometry/point2d.hpp" #include "geometry/point_with_altitude.hpp"
#include <vector> #include <vector>
jobjectArray CreateJunctionInfoArray(JNIEnv * env, std::vector<m2::PointD> const & junctionPoints) jobjectArray CreateJunctionInfoArray(JNIEnv * env, std::vector<geometry::PointWithAltitude> const & junctionPoints)
{ {
static jclass const junctionClazz = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/routing/JunctionInfo"); static jclass const junctionClazz = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/routing/JunctionInfo");
// Java signature : JunctionInfo(double lat, double lon) // Java signature : JunctionInfo(double lat, double lon)
static jmethodID const junctionConstructor = jni::GetConstructorID(env, junctionClazz, "(DD)V"); static jmethodID const junctionConstructor = jni::GetConstructorID(env, junctionClazz, "(DD)V");
return jni::ToJavaArray(env, junctionClazz, junctionPoints, return jni::ToJavaArray(env, junctionClazz, junctionPoints,
[](JNIEnv * env, m2::PointD const & point) [](JNIEnv * env, geometry::PointWithAltitude const & pointWithAltitude)
{ {
auto & point = pointWithAltitude.GetPoint();
return env->NewObject(junctionClazz, junctionConstructor, mercator::YToLat(point.y), return env->NewObject(junctionClazz, junctionConstructor, mercator::YToLat(point.y),
mercator::XToLon(point.x)); mercator::XToLon(point.x));
}); });

View File

@@ -1181,8 +1181,10 @@ std::string BookmarkManager::GenerateSavedRouteName(std::string const & from, st
return GenerateTrackRecordingName(); return GenerateTrackRecordingName();
} }
kml::TrackId BookmarkManager::SaveRoute(std::vector<m2::PointD> const & points, std::string const & from, std::string const & to) kml::TrackId BookmarkManager::SaveRoute(std::vector<geometry::PointWithAltitude> const & points, std::string const & from, std::string const & to)
{ {
CHECK(!points.empty(), ("Route points should not be empty"));
kml::MultiGeometry geometry; kml::MultiGeometry geometry;
geometry.m_lines.emplace_back(); geometry.m_lines.emplace_back();
geometry.m_timestamps.emplace_back(); geometry.m_timestamps.emplace_back();

View File

@@ -435,7 +435,7 @@ public:
std::string GenerateTrackRecordingName() const; std::string GenerateTrackRecordingName() const;
dp::Color GenerateTrackRecordingColor() const; dp::Color GenerateTrackRecordingColor() const;
kml::TrackId SaveRoute(std::vector<m2::PointD> const & points, std::string const & from, std::string const & to); kml::TrackId SaveRoute(std::vector<geometry::PointWithAltitude> const & points, std::string const & from, std::string const & to);
private: private:
class MarksChangesTracker : public df::UserMarksProvider class MarksChangesTracker : public df::UserMarksProvider

View File

@@ -1644,12 +1644,12 @@ UNIT_CLASS_TEST(Runner, Bookmarks_TestSaveRoute)
{ {
BookmarkManager bmManager(BM_CALLBACKS); BookmarkManager bmManager(BM_CALLBACKS);
bmManager.EnableTestMode(true); bmManager.EnableTestMode(true);
auto const points = {m2::PointD(0.0, 0.0), m2::PointD(0.001, 0.001)}; auto const points = {geometry::PointWithAltitude({0.0, 0.0}, 0.0), geometry::PointWithAltitude({0.001, 0.001}, 0.001)};
auto const trackId = bmManager.SaveRoute(points, "London", "Paris"); auto const trackId = bmManager.SaveRoute(points, "London", "Paris");
auto const * track = bmManager.GetTrack(trackId); auto const * track = bmManager.GetTrack(trackId);
TEST_EQUAL(track->GetName(), "London - Paris", ()); TEST_EQUAL(track->GetName(), "London - Paris", ());
auto const line = track->GetData().m_geometry.m_lines[0]; auto const line = track->GetData().m_geometry.m_lines[0];
std::vector const expectedLine = {{geometry::PointWithAltitude(m2::PointD(0.0, 0.0)), geometry::PointWithAltitude(m2::PointD(0.001, 0.001))}}; std::vector const expectedLine = {{geometry::PointWithAltitude(m2::PointD(0.0, 0.0), 0.0), geometry::PointWithAltitude(m2::PointD(0.001, 0.001), 0.001)}};
TEST_EQUAL(line, expectedLine, ()); TEST_EQUAL(line, expectedLine, ());
} }

View File

@@ -1100,16 +1100,26 @@ static std::string GetNameFromPoint(RouteMarkData const & rmd)
kml::TrackId RoutingManager::SaveRoute() kml::TrackId RoutingManager::SaveRoute()
{ {
auto points = GetRoutePolyline().GetPolyline().GetPoints(); std::vector<geometry::PointWithAltitude> junctions;
RoutingSession().GetRouteJunctionPoints(junctions);
junctions.erase(
std::unique(
junctions.begin(),
junctions.end(),
[](const geometry::PointWithAltitude & p1, const geometry::PointWithAltitude & p2)
{
return AlmostEqualAbs(p1, p2, kMwmPointAccuracy);
}
),
junctions.end()
);
auto const routePoints = GetRoutePoints(); auto const routePoints = GetRoutePoints();
std::string const from = GetNameFromPoint(routePoints.front()); std::string const from = GetNameFromPoint(routePoints.front());
std::string const to = GetNameFromPoint(routePoints.back()); std::string const to = GetNameFromPoint(routePoints.back());
// remove equal sequential points
points.erase(
std::unique(points.begin(), points.end(), [](const m2::PointD & p1, const m2::PointD & p2) { return AlmostEqualAbs(p1, p2, kMwmPointAccuracy); }),
points.end());
return m_bmManager->SaveRoute(points, from, to); return m_bmManager->SaveRoute(junctions, from, to);
} }
bool RoutingManager::DisableFollowMode() bool RoutingManager::DisableFollowMode()

View File

@@ -801,7 +801,7 @@ bool RoutingSession::IsRouteValid() const
return m_route && m_route->IsValid(); return m_route && m_route->IsValid();
} }
bool RoutingSession::GetRouteJunctionPoints(std::vector<m2::PointD> & routeJunctionPoints) const bool RoutingSession::GetRouteJunctionPoints(std::vector<geometry::PointWithAltitude> & routeJunctionPoints) const
{ {
CHECK_THREAD_CHECKER(m_threadChecker, ()); CHECK_THREAD_CHECKER(m_threadChecker, ());
ASSERT(m_route, ()); ASSERT(m_route, ());
@@ -815,7 +815,7 @@ bool RoutingSession::GetRouteJunctionPoints(std::vector<m2::PointD> & routeJunct
for (size_t i = 0; i < segments.size(); ++i) for (size_t i = 0; i < segments.size(); ++i)
{ {
auto const & junction = segments[i].GetJunction(); auto const & junction = segments[i].GetJunction();
routeJunctionPoints.push_back(junction.GetPoint()); routeJunctionPoints.push_back(junction);
} }
ASSERT_EQUAL(routeJunctionPoints.size(), routeJunctionPoints.size(), ()); ASSERT_EQUAL(routeJunctionPoints.size(), routeJunctionPoints.size(), ());

View File

@@ -94,9 +94,9 @@ public:
bool GetRouteAltitudesAndDistancesM(std::vector<double> & routeSegDistanceM, bool GetRouteAltitudesAndDistancesM(std::vector<double> & routeSegDistanceM,
geometry::Altitudes & routeAltitudesM) const; geometry::Altitudes & routeAltitudesM) const;
/// \brief returns coordinates of route junctions. /// \brief returns points of route junctions.
/// \returns true if there is valid route information. If the route is not valid returns false. /// \returns true if there is valid route information. If the route is not valid returns false.
bool GetRouteJunctionPoints(std::vector<m2::PointD> & routeJunctionPoints) const; bool GetRouteJunctionPoints(std::vector<geometry::PointWithAltitude> & routeJunctionPoints) const;
SessionState OnLocationPositionChanged(location::GpsInfo const & info); SessionState OnLocationPositionChanged(location::GpsInfo const & info);
void GetRouteFollowingInfo(FollowingInfo & info) const; void GetRouteFollowingInfo(FollowingInfo & info) const;