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:
@@ -1241,16 +1241,32 @@ JNIEXPORT jobject JNICALL Java_app_organicmaps_sdk_Framework_nativeGetRouteFollo
|
||||
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;
|
||||
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(junctionPoints))
|
||||
vector<geometry::PointWithAltitude> points;
|
||||
if (!frm()->GetRoutingManager().RoutingSession().GetRouteJunctionPoints(points))
|
||||
{
|
||||
LOG(LWARNING, ("Can't get the route junction points"));
|
||||
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(
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "app/organicmaps/sdk/core/jni_helper.hpp"
|
||||
|
||||
#include "geometry/point_with_altitude.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
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,
|
||||
[](JNIEnv * env, geometry::PointWithAltitude const & pointWithAltitude)
|
||||
{
|
||||
auto & point = pointWithAltitude.GetPoint();
|
||||
return env->NewObject(junctionClazz, junctionConstructor, mercator::YToLat(point.y), mercator::XToLon(point.x));
|
||||
auto const & ll = pointWithAltitude.ToLatLon();
|
||||
return env->NewObject(junctionClazz, junctionConstructor, ll.m_lat, ll.m_lon);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -201,7 +201,8 @@ public class Framework
|
||||
public static native RoutingInfo nativeGetRouteFollowingInfo();
|
||||
|
||||
@Nullable
|
||||
public static native JunctionInfo[] nativeGetRouteJunctionPoints();
|
||||
/// @param[in] maxDistM Max distance between points in meters.
|
||||
public static native JunctionInfo[] nativeGetRouteJunctionPoints(double maxDistM);
|
||||
|
||||
@Nullable
|
||||
public static native final int[] nativeGenerateRouteAltitudeChartBits(int width, int height,
|
||||
|
||||
@@ -16,6 +16,7 @@ class RouteSimulationProvider extends BaseLocationProvider
|
||||
|
||||
private final JunctionInfo[] mPoints;
|
||||
private int mCurrentPoint = 0;
|
||||
private Location mPrev = null;
|
||||
private boolean mActive = false;
|
||||
|
||||
RouteSimulationProvider(@NonNull Context context, @NonNull Listener listener, JunctionInfo[] points)
|
||||
@@ -56,9 +57,20 @@ class RouteSimulationProvider extends BaseLocationProvider
|
||||
location.setLatitude(mPoints[mCurrentPoint].mLat);
|
||||
location.setLongitude(mPoints[mCurrentPoint].mLon);
|
||||
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.setTime(System.currentTimeMillis());
|
||||
|
||||
mListener.onLocationChanged(location);
|
||||
mCurrentPoint += 1;
|
||||
mPrev = location;
|
||||
|
||||
UiThread.runLater(this::nextPoint, INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user