blob: c57a7e186a0656c8c328138a40679703f69394ae (
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
73
74
75
76
77
78
79
80
|
#include "storage/country_info_reader_light.hpp"
#include "storage/country_decl.hpp"
#include "storage/country_polygon.hpp"
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "coding/file_name_utils.hpp"
#include "coding/file_reader.hpp"
#include "coding/geometry_coding.hpp"
#include "coding/read_write_utils.hpp"
#include "geometry/region2d.hpp"
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include <chrono>
#include <string>
#include <utility>
#include <vector>
#include "defines.hpp"
namespace lightweight
{
CountryInfoReader::CountryInfoReader()
: CountryInfoGetterBase(true)
{
try
{
m_reader = std::make_unique<FilesContainerR>(GetPlatform().GetReader(PACKED_POLYGONS_FILE));
ReaderSource<ModelReaderPtr> src(m_reader->GetReader(PACKED_POLYGONS_INFO_TAG));
rw::Read(src, m_countries);
}
catch (FileReader::Exception const & exception)
{
LOG(LERROR,
("Exception while reading file:", PACKED_POLYGONS_FILE, "reason:", exception.what()));
m_reader.reset();
m_countries.clear();
}
m_nameGetter.SetLocale(languages::GetCurrentTwine());
}
bool CountryInfoReader::IsBelongToRegionImpl(size_t id, m2::PointD const & pt) const
{
// Load regions from file.
ReaderSource<ModelReaderPtr> src(m_reader->GetReader(strings::to_string(id)));
uint32_t const count = ReadVarUint<uint32_t>(src);
std::vector<m2::RegionD> regions;
for (size_t i = 0; i < count; ++i)
{
std::vector<m2::PointD> points;
serial::LoadOuterPath(src, serial::GeometryCodingParams(), points);
regions.emplace_back(move(points));
}
for (auto const & region : regions)
{
if (region.Contains(pt))
return true;
}
return false;
}
CountryInfoReader::Info CountryInfoReader::GetMwmInfo(m2::PointD const & pt) const
{
Info info;
info.m_id = GetRegionCountryId(pt);
info.m_name = m_nameGetter(info.m_id);
return info;
}
} // namespace lightweight
|