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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#include "drape_frontend/tile_info.hpp"
#include "drape_frontend/engine_context.hpp"
#include "drape_frontend/stylist.hpp"
#include "drape_frontend/rule_drawer.hpp"
#include "drape_frontend/map_data_provider.hpp"
#include "indexer/scales.hpp"
#include "base/scope_guard.hpp"
#include "std/bind.hpp"
namespace
{
struct IDsAccumulator
{
IDsAccumulator(vector<FeatureID> & ids, vector<df::FeatureInfo> const & src)
: m_ids(ids)
, m_src(src)
{
}
void operator()(size_t index)
{
ASSERT_LESS(index, m_src.size(), ());
m_ids.push_back(m_src[index].m_id);
}
vector<FeatureID> & m_ids;
vector<df::FeatureInfo> const & m_src;
};
} // namespace
namespace df
{
TileInfo::TileInfo(TileKey const & key)
: m_key(key)
, m_isCanceled(false)
{}
m2::RectD TileInfo::GetGlobalRect() const
{
return m_key.GetGlobalRect();
}
void TileInfo::ReadFeatureIndex(MapDataProvider const & model)
{
threads::MutexGuard guard(m_mutex);
UNUSED_VALUE(guard);
if (DoNeedReadIndex())
{
CheckCanceled();
model.ReadFeaturesID(bind(&TileInfo::ProcessID, this, _1), GetGlobalRect(), GetZoomLevel());
sort(m_featureInfo.begin(), m_featureInfo.end());
}
}
void TileInfo::ReadFeatures(MapDataProvider const & model,
MemoryFeatureIndex & memIndex,
EngineContext & context)
{
CheckCanceled();
vector<size_t> indexes;
RequestFeatures(memIndex, indexes);
if (!indexes.empty())
{
context.BeginReadTile(m_key);
// Reading can be interrupted by exception throwing
MY_SCOPE_GUARD(ReleaseReadTile, bind(&EngineContext::EndReadTile, &context, m_key));
vector<FeatureID> featuresToRead;
for_each(indexes.begin(), indexes.end(), IDsAccumulator(featuresToRead, m_featureInfo));
RuleDrawer drawer(bind(&TileInfo::InitStylist, this, _1 ,_2), m_key, context);
model.ReadFeatures(ref(drawer), featuresToRead);
}
}
void TileInfo::Cancel(MemoryFeatureIndex & memIndex)
{
m_isCanceled = true;
threads::MutexGuard guard(m_mutex);
UNUSED_VALUE(guard);
memIndex.RemoveFeatures(m_featureInfo);
}
void TileInfo::ProcessID(FeatureID const & id)
{
m_featureInfo.push_back(id);
CheckCanceled();
}
void TileInfo::InitStylist(FeatureType const & f, Stylist & s)
{
CheckCanceled();
df::InitStylist(f, GetZoomLevel(), s);
}
//====================================================//
bool TileInfo::DoNeedReadIndex() const
{
return m_featureInfo.empty();
}
void TileInfo::RequestFeatures(MemoryFeatureIndex & memIndex, vector<size_t> & featureIndexes)
{
threads::MutexGuard guard(m_mutex);
memIndex.ReadFeaturesRequest(m_featureInfo, featureIndexes);
}
void TileInfo::CheckCanceled() const
{
if (m_isCanceled)
MYTHROW(ReadCanceledException, ());
}
int TileInfo::GetZoomLevel() const
{
int const upperScale = scales::GetUpperScale();
return (m_key.m_zoomLevel <= upperScale ? m_key.m_zoomLevel : upperScale);
}
} // namespace df
|