14 , m_positionDirty(true)
15 , m_closestSegmentIndex(-1)
20void Route::addRouteSegment(
const RouteSegment &segment)
22 if (segment.isValid()) {
23 m_bounds = m_bounds.united(segment.bounds());
24 m_distance += segment.distance();
25 m_path << segment.path();
26 if (segment.maneuver().position().isValid()) {
27 m_turnPoints << segment.maneuver().position();
29 if (segment.maneuver().hasWaypoint()) {
30 m_waypoints << segment.maneuver().waypoint();
32 m_segments.push_back(segment);
33 m_positionDirty =
true;
35 for (
int i = 1; i < m_segments.size(); ++i) {
36 m_segments[i - 1].setNextRouteSegment(&m_segments[i]);
41GeoDataLatLonBox Route::bounds()
const
46qreal Route::distance()
const
51int Route::size()
const
53 return m_segments.size();
56const RouteSegment &Route::at(
int index)
const
58 return m_segments[index];
61int Route::indexOf(
const RouteSegment &segment)
const
63 return m_segments.indexOf(segment);
66const GeoDataLineString &Route::path()
const
71int Route::travelTime()
const
76const GeoDataLineString &Route::turnPoints()
const
81const GeoDataLineString &Route::waypoints()
const
86void Route::setPosition(
const GeoDataCoordinates &position)
88 m_position = position;
89 m_positionDirty =
true;
92GeoDataCoordinates Route::position()
const
97void Route::updatePosition()
const
99 if (!m_segments.isEmpty()) {
100 if (m_closestSegmentIndex < 0 || m_closestSegmentIndex >= m_segments.size()) {
101 m_closestSegmentIndex = 0;
104 qreal
distance = m_segments[m_closestSegmentIndex].distanceTo(m_position, m_currentWaypoint, m_positionOnRoute);
107 for (
int i = 0; i < m_segments.size(); ++i) {
108 if (i != m_closestSegmentIndex && m_segments[i].minimalDistanceTo(m_position) <= distance) {
113 GeoDataCoordinates closest, interpolated;
114 for (
int i : std::as_const(candidates)) {
115 qreal
const dist = m_segments[i].distanceTo(m_position, closest, interpolated);
116 if (distance < 0.0 || dist < distance) {
118 m_closestSegmentIndex = i;
119 m_positionOnRoute = interpolated;
120 m_currentWaypoint = closest;
125 m_positionDirty =
false;
128const RouteSegment &Route::currentSegment()
const
130 if (m_positionDirty) {
134 if (m_closestSegmentIndex < 0 || m_closestSegmentIndex >= m_segments.size()) {
135 static RouteSegment invalid;
139 return m_segments[m_closestSegmentIndex];
142GeoDataCoordinates Route::positionOnRoute()
const
144 if (m_positionDirty) {
148 return m_positionOnRoute;
151GeoDataCoordinates Route::currentWaypoint()
const
153 if (m_positionDirty) {
157 return m_currentWaypoint;
Binds a QML item to a specific geodetic location in screen coordinates.
KOSM_EXPORT double distance(const std::vector< const OSM::Node * > &path, Coordinate coord)