diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2018-10-15 18:58:31 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2018-10-16 12:16:52 +0300 |
commit | ff9fdf07b9432305a1b1f6e0e3b1322e5b425765 (patch) | |
tree | 49c8ae381c2e1e2b30ef0ee5bd17bb422d9af264 /map/framework.cpp | |
parent | 984e0d4801b8a75612215942d12ca605cfbf927d (diff) |
Visualization of city roads.
Diffstat (limited to 'map/framework.cpp')
-rw-r--r-- | map/framework.cpp | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/map/framework.cpp b/map/framework.cpp index e5d3253adf..0ba5ae56bf 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -13,6 +13,7 @@ #include "defines.hpp" #include "private.h" +#include "routing/city_roads.hpp" #include "routing/index_router.hpp" #include "routing/online_absent_fetcher.hpp" #include "routing/route.hpp" @@ -3261,35 +3262,42 @@ void DrawLine(Box const & box, dp::Color const & color, df::DrapeApi & drapeApi, drapeApi.AddLine(id, df::DrapeApiLineData(points, color).Width(3.0f).ShowPoints(true).ShowId()); } + +void VisualizeFeatureInRect(m2::RectD const & rect, FeatureType & ft, df::DrapeApi & drapeApi, + size_t & counter) +{ + bool allPointsOutside = true; + vector<m2::PointD> points; + ft.ForEachPoint([&points, &rect, &allPointsOutside](m2::PointD const & pt) + { + if (rect.IsPointInside(pt)) + allPointsOutside = false; + points.push_back(pt); + }, scales::GetUpperScale()); + + if (!allPointsOutside) + { + size_t const colorIndex = counter % colorList.size(); + // Note. The first param at DrapeApi::AddLine() should be unique. Other way last added line + // replaces the previous added line with the same name. + // As a consequence VisualizeFeatureInRect() should be applied to single mwm. Other way + // feature ids will be dubbed. + drapeApi.AddLine( + strings::to_string(ft.GetID().m_index), + df::DrapeApiLineData(points, colorList[colorIndex]).Width(3.0f).ShowPoints(true).ShowId()); + counter++; + } +} } // namespace void Framework::VisualizeRoadsInRect(m2::RectD const & rect) { - int constexpr kScale = scales::GetUpperScale(); size_t counter = 0; m_model.ForEachFeature(rect, [this, &counter, &rect](FeatureType & ft) { if (routing::IsRoad(feature::TypesHolder(ft))) - { - bool allPointsOutside = true; - vector<m2::PointD> points; - ft.ForEachPoint([&points, &rect, &allPointsOutside](m2::PointD const & pt) - { - if (rect.IsPointInside(pt)) - allPointsOutside = false; - points.push_back(pt); - }, kScale); - - if (!allPointsOutside) - { - size_t const colorIndex = counter % colorList.size(); - m_drapeApi.AddLine(strings::to_string(ft.GetID().m_index), - df::DrapeApiLineData(points, colorList[colorIndex]) - .Width(3.0f).ShowPoints(true).ShowId()); - counter++; - } - } - }, kScale); + VisualizeFeatureInRect(rect, ft, m_drapeApi, counter); + }, scales::GetUpperScale()); } void Framework::VisualizeCityBoundariesInRect(m2::RectD const & rect) @@ -3330,6 +3338,31 @@ void Framework::VisualizeCityBoundariesInRect(m2::RectD const & rect) } } +void Framework::VisualizeCityRoadsInRect(m2::RectD const & rect) +{ + map<MwmSet::MwmId, unique_ptr<CityRoads>> cityRoads; + size_t counter = 0; + GetDataSource().ForEachInRect( + [this, &rect, &cityRoads, &counter](FeatureType & ft) { + auto const & mwmId = ft.GetID().m_mwmId; + auto const it = cityRoads.find(mwmId); + if (it == cityRoads.cend()) + { + MwmSet::MwmHandle handle = m_model.GetDataSource().GetMwmHandleById(mwmId); + if (!handle.IsAlive()) + return; + + cityRoads[mwmId] = LoadCityRoads(GetDataSource(), handle); + } + + if (!cityRoads[mwmId]->IsCityRoad(ft.GetID().m_index)) + return; // ft is not a city road. + + VisualizeFeatureInRect(rect, ft, m_drapeApi, counter); + }, + rect, scales::GetUpperScale()); +} + ads::Engine const & Framework::GetAdsEngine() const { ASSERT(m_adsEngine, ()); |