mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[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:
committed by
Konstantin Pastbin
parent
21cc2bbf52
commit
cc6958282b
@@ -1297,7 +1297,7 @@ Java_app_organicmaps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jclass)
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_app_organicmaps_Framework_nativeGetRouteJunctionPoints(JNIEnv * env, jclass)
|
||||
{
|
||||
vector<m2::PointD> junctionPoints;
|
||||
vector<geometry::PointWithAltitude> junctionPoints;
|
||||
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(junctionPoints))
|
||||
{
|
||||
LOG(LWARNING, ("Can't get the route junction points"));
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
|
||||
#include "app/organicmaps/core/jni_helper.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/point_with_altitude.hpp"
|
||||
|
||||
#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");
|
||||
// Java signature : JunctionInfo(double lat, double lon)
|
||||
static jmethodID const junctionConstructor = jni::GetConstructorID(env, junctionClazz, "(DD)V");
|
||||
|
||||
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),
|
||||
mercator::XToLon(point.x));
|
||||
});
|
||||
|
||||
@@ -1181,8 +1181,10 @@ std::string BookmarkManager::GenerateSavedRouteName(std::string const & from, st
|
||||
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;
|
||||
geometry.m_lines.emplace_back();
|
||||
geometry.m_timestamps.emplace_back();
|
||||
|
||||
@@ -435,7 +435,7 @@ public:
|
||||
std::string GenerateTrackRecordingName() 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:
|
||||
class MarksChangesTracker : public df::UserMarksProvider
|
||||
|
||||
@@ -1644,12 +1644,12 @@ UNIT_CLASS_TEST(Runner, Bookmarks_TestSaveRoute)
|
||||
{
|
||||
BookmarkManager bmManager(BM_CALLBACKS);
|
||||
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 * track = bmManager.GetTrack(trackId);
|
||||
TEST_EQUAL(track->GetName(), "London - Paris", ());
|
||||
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, ());
|
||||
}
|
||||
|
||||
|
||||
@@ -1100,16 +1100,26 @@ static std::string GetNameFromPoint(RouteMarkData const & rmd)
|
||||
|
||||
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();
|
||||
std::string const from = GetNameFromPoint(routePoints.front());
|
||||
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()
|
||||
|
||||
@@ -801,7 +801,7 @@ bool RoutingSession::IsRouteValid() const
|
||||
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, ());
|
||||
ASSERT(m_route, ());
|
||||
@@ -815,7 +815,7 @@ bool RoutingSession::GetRouteJunctionPoints(std::vector<m2::PointD> & routeJunct
|
||||
for (size_t i = 0; i < segments.size(); ++i)
|
||||
{
|
||||
auto const & junction = segments[i].GetJunction();
|
||||
routeJunctionPoints.push_back(junction.GetPoint());
|
||||
routeJunctionPoints.push_back(junction);
|
||||
}
|
||||
|
||||
ASSERT_EQUAL(routeJunctionPoints.size(), routeJunctionPoints.size(), ());
|
||||
|
||||
@@ -94,9 +94,9 @@ public:
|
||||
bool GetRouteAltitudesAndDistancesM(std::vector<double> & routeSegDistanceM,
|
||||
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.
|
||||
bool GetRouteJunctionPoints(std::vector<m2::PointD> & routeJunctionPoints) const;
|
||||
bool GetRouteJunctionPoints(std::vector<geometry::PointWithAltitude> & routeJunctionPoints) const;
|
||||
|
||||
SessionState OnLocationPositionChanged(location::GpsInfo const & info);
|
||||
void GetRouteFollowingInfo(FollowingInfo & info) const;
|
||||
|
||||
Reference in New Issue
Block a user