Welcome to mirror list, hosted at ThFree Co, Russian Federation.

street_vicinity_loader.cpp « v2 « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b5a4bddb639920e9d61930ad00971316336beec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "search/v2/street_vicinity_loader.hpp"

#include "indexer/feature_covering.hpp"
#include "indexer/feature_decl.hpp"
#include "indexer/index.hpp"

#include "geometry/mercator.hpp"

#include "geometry/point2d.hpp"

#include "base/math.hpp"
#include "base/stl_add.hpp"

namespace search
{
namespace v2
{
StreetVicinityLoader::StreetVicinityLoader(int scale, double offsetMeters)
  : m_context(nullptr), m_scale(scale), m_offsetMeters(offsetMeters), m_cache("Streets")
{
}

void StreetVicinityLoader::SetContext(MwmContext * context)
{
  ASSERT(context, ());
  if (m_context == context)
    return;

  m_context = context;
  auto const scaleRange = m_context->m_value.GetHeader().GetScaleRange();
  m_scale = my::clamp(m_scale, scaleRange.first, scaleRange.second);
}

void StreetVicinityLoader::OnQueryFinished()
{
  m_cache.ClearIfNeeded();
}

StreetVicinityLoader::Street const & StreetVicinityLoader::GetStreet(uint32_t featureId)
{
  auto r = m_cache.Get(featureId);
  if (!r.second)
    return r.first;

  LoadStreet(featureId, r.first);
  return r.first;
}

void StreetVicinityLoader::LoadStreet(uint32_t featureId, Street & street)
{
  FeatureType feature;
  if (!m_context->GetFeature(featureId, feature))
    return;

  if (feature.GetFeatureType() != feature::GEOM_LINE)
    return;

  vector<m2::PointD> points;
  feature.ForEachPoint(MakeBackInsertFunctor(points), FeatureType::BEST_GEOMETRY);
  ASSERT(!points.empty(), ());

  for (auto const & point : points)
    street.m_rect.Add(MercatorBounds::RectByCenterXYAndSizeInMeters(point, m_offsetMeters));

  covering::CoveringGetter coveringGetter(street.m_rect, covering::ViewportWithLowLevels);
  auto const & intervals = coveringGetter.Get(m_scale);
  m_context->ForEachIndex(intervals, m_scale, MakeBackInsertFunctor(street.m_features));

  street.m_calculator = make_unique<ProjectionOnStreetCalculator>(points);
}
}  // namespace v2
}  // namespace search