[routing] Make 'auto reordering of intermediate stops' optional

Signed-off-by: Gonzalo Pesquero <gpesquero@yahoo.es>
This commit is contained in:
Gonzalo Pesquero
2025-03-02 23:17:00 +01:00
committed by Konstantin Pastbin
parent 8b096035df
commit 5bb2569e76
6 changed files with 20 additions and 43 deletions

View File

@@ -1452,7 +1452,8 @@ Java_app_organicmaps_Framework_nativeAddRoutePoint(JNIEnv * env, jclass, jstring
jstring subtitle, jobject markType, jstring subtitle, jobject markType,
jint intermediateIndex, jint intermediateIndex,
jboolean isMyPosition, jboolean isMyPosition,
jdouble lat, jdouble lon) jdouble lat, jdouble lon,
jboolean reorderIntermediatePoints)
{ {
RouteMarkData data; RouteMarkData data;
data.m_title = jni::ToNativeString(env, title); data.m_title = jni::ToNativeString(env, title);
@@ -1462,7 +1463,7 @@ Java_app_organicmaps_Framework_nativeAddRoutePoint(JNIEnv * env, jclass, jstring
data.m_isMyPosition = static_cast<bool>(isMyPosition); data.m_isMyPosition = static_cast<bool>(isMyPosition);
data.m_position = m2::PointD(mercator::FromLatLon(lat, lon)); data.m_position = m2::PointD(mercator::FromLatLon(lat, lon));
frm()->GetRoutingManager().AddRoutePoint(std::move(data)); frm()->GetRoutingManager().AddRoutePoint(std::move(data), reorderIntermediatePoints);
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL

View File

@@ -230,15 +230,21 @@ public class Framework
public static native void nativeShowCountry(String countryId, boolean zoomToDownloadButton); public static native void nativeShowCountry(String countryId, boolean zoomToDownloadButton);
public static void addRoutePoint(RouteMarkData point) public static void addRoutePoint(RouteMarkData point)
{
addRoutePoint(point, true);
}
public static void addRoutePoint(RouteMarkData point, boolean reorderIntermediatePoints)
{ {
Framework.nativeAddRoutePoint(point.mTitle, point.mSubtitle, point.mPointType, Framework.nativeAddRoutePoint(point.mTitle, point.mSubtitle, point.mPointType,
point.mIntermediateIndex, point.mIsMyPosition, point.mIntermediateIndex, point.mIsMyPosition,
point.mLat, point.mLon); point.mLat, point.mLon, reorderIntermediatePoints);
} }
public static native void nativeAddRoutePoint(String title, String subtitle, @NonNull RouteMarkType markType, public static native void nativeAddRoutePoint(String title, String subtitle, @NonNull RouteMarkType markType,
int intermediateIndex, boolean isMyPosition, int intermediateIndex, boolean isMyPosition,
double lat, double lon); double lat, double lon,
boolean reorderIntermediatePoints);
public static native void nativeRemoveRoutePoints(); public static native void nativeRemoveRoutePoints();

View File

@@ -141,42 +141,9 @@ public class ManageRouteBottomSheet extends BottomSheetDialogFragment
// Secondly, add the starting point. // Secondly, add the starting point.
Framework.addRoutePoint(newRoutePoints.get(0)); Framework.addRoutePoint(newRoutePoints.get(0));
// And then, add all intermediate points. // And then, add all intermediate points (with no reordering).
for (int pos = 1; pos < newRoutePoints.size() - 1; pos++) for (int pos = 1; pos < newRoutePoints.size() - 1; pos++)
Framework.addRoutePoint(newRoutePoints.get(pos)); Framework.addRoutePoint(newRoutePoints.get(pos), false);
// Intermediate route points are added sorted by distance.
// We have to make sure that they follow the requested order.
RouteMarkData[] finalRoutePoints = Framework.nativeGetRoutePoints();
for (int first = 1; first < newRoutePoints.size() - 1; first++)
{
int secondIndex = -1;
for (int second = first; second < newRoutePoints.size() - 1; second++)
{
if (finalRoutePoints[first].equals(newRoutePoints.get(second)))
{
secondIndex = second;
break;
}
}
if (secondIndex < 0)
{
// Something went bad. Intermediate point not found in the route points.
break;
}
if (first != secondIndex)
{
// Intermediate point needs to be moved.
Framework.nativeMoveRoutePoint(secondIndex, first);
// Refresh final route points.
finalRoutePoints = Framework.nativeGetRoutePoints();
}
}
// Launch route planning. // Launch route planning.
RoutingController.get().launchPlanning(); RoutingController.get().launchPlanning();

View File

@@ -778,7 +778,8 @@ public class RoutingController
Framework.nativeAddRoutePoint(description.first /* title */, description.second /* subtitle */, Framework.nativeAddRoutePoint(description.first /* title */, description.second /* subtitle */,
type, 0 /* intermediateIndex */, type, 0 /* intermediateIndex */,
point.isMyPosition(), point.isMyPosition(),
point.getLat(), point.getLon()); point.getLat(), point.getLon(),
true /* reorderIntermediatePoints */);
} }
@NonNull @NonNull

View File

@@ -841,7 +841,7 @@ bool RoutingManager::CouldAddIntermediatePoint() const
< RoutePointsLayout::kMaxIntermediatePointsCount + 2; < RoutePointsLayout::kMaxIntermediatePointsCount + 2;
} }
void RoutingManager::AddRoutePoint(RouteMarkData && markData) void RoutingManager::AddRoutePoint(RouteMarkData && markData, bool reorderIntermediatePoints)
{ {
ASSERT(m_bmManager != nullptr, ()); ASSERT(m_bmManager != nullptr, ());
RoutePointsLayout routePoints(*m_bmManager); RoutePointsLayout routePoints(*m_bmManager);
@@ -859,7 +859,9 @@ void RoutingManager::AddRoutePoint(RouteMarkData && markData)
markData.m_isVisible = !markData.m_isMyPosition; markData.m_isVisible = !markData.m_isMyPosition;
routePoints.AddRoutePoint(std::move(markData)); routePoints.AddRoutePoint(std::move(markData));
ReorderIntermediatePoints();
if (reorderIntermediatePoints)
ReorderIntermediatePoints();
} }
void RoutingManager::ContinueRouteToPoint(RouteMarkData && markData) void RoutingManager::ContinueRouteToPoint(RouteMarkData && markData)

View File

@@ -226,7 +226,7 @@ public:
/// will not return previous data, only newer. /// will not return previous data, only newer.
void GenerateNotifications(std::vector<std::string> & notifications, bool announceStreets); void GenerateNotifications(std::vector<std::string> & notifications, bool announceStreets);
void AddRoutePoint(RouteMarkData && markData); void AddRoutePoint(RouteMarkData && markData, bool reorderIntermediatePoints = true);
void ContinueRouteToPoint(RouteMarkData && markData); void ContinueRouteToPoint(RouteMarkData && markData);
std::vector<RouteMarkData> GetRoutePoints() const; std::vector<RouteMarkData> GetRoutePoints() const;
size_t GetRoutePointsCount() const; size_t GetRoutePointsCount() const;