mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[android] Improve AA route simulator.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
@@ -104,7 +104,11 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
|
|||||||
public void onAutoDriveEnabled()
|
public void onAutoDriveEnabled()
|
||||||
{
|
{
|
||||||
Logger.i(TAG);
|
Logger.i(TAG);
|
||||||
final JunctionInfo[] points = Framework.nativeGetRouteJunctionPoints();
|
|
||||||
|
/// @todo Pass maxDistM from RouteSimulationProvider?
|
||||||
|
/// Result speed between points will be in range (25, 50] km/h (for 1 second update interval).
|
||||||
|
final double kMaxDistM = 13.9; // 13.9 m/s == 50 km/h
|
||||||
|
final JunctionInfo[] points = Framework.nativeGetRouteJunctionPoints(kMaxDistM);
|
||||||
if (points == null)
|
if (points == null)
|
||||||
{
|
{
|
||||||
Logger.e(TAG, "Navigation has not started yet");
|
Logger.e(TAG, "Navigation has not started yet");
|
||||||
|
|||||||
@@ -1241,16 +1241,32 @@ JNIEXPORT jobject JNICALL Java_app_organicmaps_sdk_Framework_nativeGetRouteFollo
|
|||||||
return CreateRoutingInfo(env, info, rm);
|
return CreateRoutingInfo(env, info, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jobjectArray JNICALL Java_app_organicmaps_sdk_Framework_nativeGetRouteJunctionPoints(JNIEnv * env, jclass)
|
JNIEXPORT jobjectArray JNICALL Java_app_organicmaps_sdk_Framework_nativeGetRouteJunctionPoints(JNIEnv * env, jclass,
|
||||||
|
jdouble maxDistM)
|
||||||
{
|
{
|
||||||
vector<geometry::PointWithAltitude> junctionPoints;
|
vector<geometry::PointWithAltitude> points;
|
||||||
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(junctionPoints))
|
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(points))
|
||||||
{
|
{
|
||||||
LOG(LWARNING, ("Can't get the route junction points"));
|
LOG(LWARNING, ("Can't get the route junction points"));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateJunctionInfoArray(env, junctionPoints);
|
vector<geometry::PointWithAltitude> result;
|
||||||
|
result.reserve(points.size());
|
||||||
|
result.push_back(points[0]);
|
||||||
|
for (size_t i = 1; i < points.size(); ++i)
|
||||||
|
{
|
||||||
|
double const dist = ms::DistanceOnEarth(points[i - 1].ToLatLon(), points[i].ToLatLon());
|
||||||
|
if (dist > maxDistM)
|
||||||
|
{
|
||||||
|
int const steps = static_cast<int>(dist / maxDistM) + 1;
|
||||||
|
for (int s = 1; s < steps; ++s)
|
||||||
|
result.push_back(points[i - 1].Interpolate(points[i], static_cast<double>(s) / steps));
|
||||||
|
}
|
||||||
|
result.push_back(points[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateJunctionInfoArray(env, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL Java_app_organicmaps_sdk_Framework_nativeGenerateRouteAltitudeChartBits(
|
JNIEXPORT jintArray JNICALL Java_app_organicmaps_sdk_Framework_nativeGenerateRouteAltitudeChartBits(
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include "app/organicmaps/sdk/core/jni_helper.hpp"
|
#include "app/organicmaps/sdk/core/jni_helper.hpp"
|
||||||
|
|
||||||
#include "geometry/point_with_altitude.hpp"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
jobjectArray CreateJunctionInfoArray(JNIEnv * env, std::vector<geometry::PointWithAltitude> const & junctionPoints)
|
jobjectArray CreateJunctionInfoArray(JNIEnv * env, std::vector<geometry::PointWithAltitude> const & junctionPoints)
|
||||||
@@ -15,7 +13,7 @@ jobjectArray CreateJunctionInfoArray(JNIEnv * env, std::vector<geometry::PointWi
|
|||||||
return jni::ToJavaArray(env, junctionClazz, junctionPoints,
|
return jni::ToJavaArray(env, junctionClazz, junctionPoints,
|
||||||
[](JNIEnv * env, geometry::PointWithAltitude const & pointWithAltitude)
|
[](JNIEnv * env, geometry::PointWithAltitude const & pointWithAltitude)
|
||||||
{
|
{
|
||||||
auto & point = pointWithAltitude.GetPoint();
|
auto const & ll = pointWithAltitude.ToLatLon();
|
||||||
return env->NewObject(junctionClazz, junctionConstructor, mercator::YToLat(point.y), mercator::XToLon(point.x));
|
return env->NewObject(junctionClazz, junctionConstructor, ll.m_lat, ll.m_lon);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,8 @@ public class Framework
|
|||||||
public static native RoutingInfo nativeGetRouteFollowingInfo();
|
public static native RoutingInfo nativeGetRouteFollowingInfo();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static native JunctionInfo[] nativeGetRouteJunctionPoints();
|
/// @param[in] maxDistM Max distance between points in meters.
|
||||||
|
public static native JunctionInfo[] nativeGetRouteJunctionPoints(double maxDistM);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static native final int[] nativeGenerateRouteAltitudeChartBits(int width, int height,
|
public static native final int[] nativeGenerateRouteAltitudeChartBits(int width, int height,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class RouteSimulationProvider extends BaseLocationProvider
|
|||||||
|
|
||||||
private final JunctionInfo[] mPoints;
|
private final JunctionInfo[] mPoints;
|
||||||
private int mCurrentPoint = 0;
|
private int mCurrentPoint = 0;
|
||||||
|
private Location mPrev = null;
|
||||||
private boolean mActive = false;
|
private boolean mActive = false;
|
||||||
|
|
||||||
RouteSimulationProvider(@NonNull Context context, @NonNull Listener listener, JunctionInfo[] points)
|
RouteSimulationProvider(@NonNull Context context, @NonNull Listener listener, JunctionInfo[] points)
|
||||||
@@ -56,9 +57,20 @@ class RouteSimulationProvider extends BaseLocationProvider
|
|||||||
location.setLatitude(mPoints[mCurrentPoint].mLat);
|
location.setLatitude(mPoints[mCurrentPoint].mLat);
|
||||||
location.setLongitude(mPoints[mCurrentPoint].mLon);
|
location.setLongitude(mPoints[mCurrentPoint].mLon);
|
||||||
location.setAccuracy(1.0f);
|
location.setAccuracy(1.0f);
|
||||||
|
|
||||||
|
if (mPrev != null)
|
||||||
|
{
|
||||||
|
location.setSpeed(mPrev.distanceTo(location) / (INTERVAL_MS / 1000));
|
||||||
|
location.setBearing(mPrev.bearingTo(location));
|
||||||
|
}
|
||||||
|
|
||||||
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
|
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
|
||||||
|
location.setTime(System.currentTimeMillis());
|
||||||
|
|
||||||
mListener.onLocationChanged(location);
|
mListener.onLocationChanged(location);
|
||||||
mCurrentPoint += 1;
|
mCurrentPoint += 1;
|
||||||
|
mPrev = location;
|
||||||
|
|
||||||
UiThread.runLater(this::nextPoint, INTERVAL_MS);
|
UiThread.runLater(this::nextPoint, INTERVAL_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "geometry/point_with_altitude.hpp"
|
#include "geometry/point_with_altitude.hpp"
|
||||||
|
|
||||||
#include "std/boost_container_hash.hpp"
|
#include "geometry/mercator.hpp"
|
||||||
|
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -26,6 +28,11 @@ bool PointWithAltitude::operator<(PointWithAltitude const & r) const
|
|||||||
return m_altitude < r.m_altitude;
|
return m_altitude < r.m_altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ms::LatLon PointWithAltitude::ToLatLon() const
|
||||||
|
{
|
||||||
|
return ms::LatLon(mercator::YToLat(m_point.y), mercator::XToLon(m_point.x));
|
||||||
|
}
|
||||||
|
|
||||||
std::string DebugPrint(PointWithAltitude const & r)
|
std::string DebugPrint(PointWithAltitude const & r)
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "geometry/latlon.hpp"
|
||||||
#include "geometry/point2d.hpp"
|
#include "geometry/point2d.hpp"
|
||||||
|
|
||||||
|
#include "base/math.hpp"
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -26,11 +29,19 @@ public:
|
|||||||
bool operator<(PointWithAltitude const & r) const;
|
bool operator<(PointWithAltitude const & r) const;
|
||||||
|
|
||||||
m2::PointD const & GetPoint() const { return m_point; }
|
m2::PointD const & GetPoint() const { return m_point; }
|
||||||
|
ms::LatLon ToLatLon() const;
|
||||||
Altitude GetAltitude() const { return m_altitude; }
|
Altitude GetAltitude() const { return m_altitude; }
|
||||||
|
|
||||||
void SetPoint(m2::PointD const & point) { m_point = point; }
|
void SetPoint(m2::PointD const & point) { m_point = point; }
|
||||||
void SetAltitude(Altitude altitude) { m_altitude = altitude; }
|
void SetAltitude(Altitude altitude) { m_altitude = altitude; }
|
||||||
|
|
||||||
|
/// @param[in] f in range [0, 1]
|
||||||
|
PointWithAltitude Interpolate(PointWithAltitude const & to, double f) const
|
||||||
|
{
|
||||||
|
return PointWithAltitude(m_point + (to.m_point - m_point) * f,
|
||||||
|
math::iround(m_altitude + (to.m_altitude - m_altitude) * f));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::string DebugPrint(PointWithAltitude const & r);
|
friend std::string DebugPrint(PointWithAltitude const & r);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user