forked from organicmaps/organicmaps
[bookmarks] Track selection. Review fixes.
This commit is contained in:
parent
015f56c8f5
commit
b39ae74700
4 changed files with 46 additions and 43 deletions
|
@ -1082,33 +1082,33 @@ BookmarkManager::TrackSelectionInfo BookmarkManager::FindNearestTrack(m2::RectD
|
|||
for (auto trackId : category.GetUserLines())
|
||||
{
|
||||
auto const track = GetTrack(trackId);
|
||||
auto const trackRect = track->GetLimitRect();
|
||||
auto const & trackRect = track->GetLimitRect();
|
||||
|
||||
if (trackRect.IsIntersect(touchRect))
|
||||
if (!trackRect.IsIntersect(touchRect))
|
||||
continue;
|
||||
|
||||
auto const & pointsWithAlt = track->GetPointsWithAltitudes();
|
||||
for (size_t i = 0; i + 1 < pointsWithAlt.size(); ++i)
|
||||
{
|
||||
auto const & pointsWithAlt = track->GetPointsWithAltitudes();
|
||||
for (size_t i = 0; i + 1 < pointsWithAlt.size(); ++i)
|
||||
{
|
||||
auto pt1 = pointsWithAlt[i].GetPoint();
|
||||
auto pt2 = pointsWithAlt[i + 1].GetPoint();
|
||||
if (m2::Intersect(touchRect, pt1, pt2))
|
||||
{
|
||||
m2::ParametrizedSegment<m2::PointD> seg(pt1, pt2);
|
||||
auto const closestPoint = seg.ClosestPointTo(touchRect.Center());
|
||||
auto const squaredDist = closestPoint.SquaredLength(touchRect.Center());
|
||||
if (squaredDist < minSquaredDist)
|
||||
{
|
||||
minSquaredDist = squaredDist;
|
||||
selectionInfo.m_trackId = trackId;
|
||||
selectionInfo.m_trackPoint = closestPoint;
|
||||
auto pt1 = pointsWithAlt[i].GetPoint();
|
||||
auto pt2 = pointsWithAlt[i + 1].GetPoint();
|
||||
if (!m2::Intersect(touchRect, pt1, pt2))
|
||||
continue;
|
||||
|
||||
auto const segDistInMeters = mercator::DistanceOnEarth(pointsWithAlt[i].GetPoint(),
|
||||
closestPoint);
|
||||
selectionInfo.m_distanceInMeters = segDistInMeters;
|
||||
if (i > 0)
|
||||
selectionInfo.m_distanceInMeters += track->GetLengthMeters(i - 1);
|
||||
}
|
||||
}
|
||||
m2::ParametrizedSegment<m2::PointD> seg(pt1, pt2);
|
||||
auto const closestPoint = seg.ClosestPointTo(touchRect.Center());
|
||||
auto const squaredDist = closestPoint.SquaredLength(touchRect.Center());
|
||||
if (squaredDist < minSquaredDist)
|
||||
{
|
||||
minSquaredDist = squaredDist;
|
||||
selectionInfo.m_trackId = trackId;
|
||||
selectionInfo.m_trackPoint = closestPoint;
|
||||
|
||||
auto const segDistInMeters = mercator::DistanceOnEarth(pointsWithAlt[i].GetPoint(),
|
||||
closestPoint);
|
||||
selectionInfo.m_distanceInMeters = segDistInMeters;
|
||||
if (i > 0)
|
||||
selectionInfo.m_distanceInMeters += track->GetLengthMeters(i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2611,16 +2611,6 @@ std::optional<place_page::Info> Framework::BuildPlacePageInfo(
|
|||
return outInfo;
|
||||
}
|
||||
|
||||
if (buildInfo.IsTrackMatchingEnabled())
|
||||
{
|
||||
auto const trackSelectionInfo = FindTrackInTapPosition(buildInfo);
|
||||
if (trackSelectionInfo.m_trackId != kml::kInvalidTrackId)
|
||||
{
|
||||
BuildTrackPlacePage(trackSelectionInfo, outInfo);
|
||||
return outInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buildInfo.m_postcode.empty())
|
||||
{
|
||||
outInfo.SetSelectedObject(df::SelectionShape::OBJECT_POI);
|
||||
|
@ -2635,6 +2625,18 @@ std::optional<place_page::Info> Framework::BuildPlacePageInfo(
|
|||
|
||||
FeatureID selectedFeature = buildInfo.m_featureId;
|
||||
auto const isFeatureMatchingEnabled = buildInfo.IsFeatureMatchingEnabled();
|
||||
|
||||
if (buildInfo.IsTrackMatchingEnabled() && !buildInfo.m_isLongTap &&
|
||||
!(isFeatureMatchingEnabled && selectedFeature.IsValid()))
|
||||
{
|
||||
auto const trackSelectionInfo = FindTrackInTapPosition(buildInfo);
|
||||
if (trackSelectionInfo.m_trackId != kml::kInvalidTrackId)
|
||||
{
|
||||
BuildTrackPlacePage(trackSelectionInfo, outInfo);
|
||||
return outInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (isFeatureMatchingEnabled && !selectedFeature.IsValid())
|
||||
selectedFeature = FindBuildingAtPoint(buildInfo.m_mercator);
|
||||
|
||||
|
|
|
@ -13,11 +13,13 @@ Track::Track(kml::TrackData && data)
|
|||
{
|
||||
m_data.m_id = GetId();
|
||||
CHECK_GREATER(m_data.m_pointsWithAltitudes.size(), 1, ());
|
||||
CacheLengths();
|
||||
CacheLengthsAndLimitRect();
|
||||
}
|
||||
|
||||
void Track::CacheLengths()
|
||||
void Track::CacheLengthsAndLimitRect()
|
||||
{
|
||||
m_cachedLimitRect.MakeEmpty();
|
||||
m_cachedLimitRect.Add(m_data.m_pointsWithAltitudes.front().GetPoint());
|
||||
m_cachedLengths.resize(m_data.m_pointsWithAltitudes.size() - 1);
|
||||
double length = 0.0;
|
||||
for (size_t i = 1; i < m_data.m_pointsWithAltitudes.size(); ++i)
|
||||
|
@ -27,6 +29,7 @@ void Track::CacheLengths()
|
|||
auto const segmentLength = mercator::DistanceOnEarth(pt1, pt2);
|
||||
length += segmentLength;
|
||||
m_cachedLengths[i - 1] = length;
|
||||
m_cachedLimitRect.Add(pt2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,12 +38,9 @@ std::string Track::GetName() const
|
|||
return GetPreferredBookmarkStr(m_data.m_name);
|
||||
}
|
||||
|
||||
m2::RectD Track::GetLimitRect() const
|
||||
m2::RectD const & Track::GetLimitRect() const
|
||||
{
|
||||
m2::RectD rect;
|
||||
for (auto const & point : m_data.m_pointsWithAltitudes)
|
||||
rect.Add(point.GetPoint());
|
||||
return rect;
|
||||
return m_cachedLimitRect;
|
||||
}
|
||||
|
||||
double Track::GetLengthMeters() const
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
kml::TrackData const & GetData() const { return m_data; }
|
||||
|
||||
std::string GetName() const;
|
||||
m2::RectD GetLimitRect() const;
|
||||
m2::RectD const & GetLimitRect() const;
|
||||
double GetLengthMeters() const;
|
||||
double GetLengthMeters(size_t segmentIndex) const;
|
||||
|
||||
|
@ -41,11 +41,12 @@ public:
|
|||
bool GetPoint(double distanceInMeters, m2::PointD & pt) const;
|
||||
|
||||
private:
|
||||
void CacheLengths();
|
||||
void CacheLengthsAndLimitRect();
|
||||
|
||||
kml::TrackData m_data;
|
||||
kml::MarkGroupId m_groupID = kml::kInvalidMarkGroupId;
|
||||
kml::MarkId m_selectionMarkId = kml::kInvalidMarkId;
|
||||
std::vector<double> m_cachedLengths;
|
||||
m2::RectD m_cachedLimitRect;
|
||||
mutable bool m_isDirty = true;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue