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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#include "map_object.hpp"
#include "indexer/categories_holder.hpp"
#include "indexer/cuisines.hpp"
#include "indexer/feature.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "platform/measurement_utils.hpp"
#include "platform/preferred_languages.hpp"
#include "base/logging.hpp"
#include "base/string_utils.hpp"
namespace osm
{
namespace
{
constexpr char const * kWlan = "wlan";
constexpr char const * kWired = "wired";
constexpr char const * kYes = "yes";
constexpr char const * kNo = "no";
void SetInetIfNeeded(FeatureType const & ft, feature::Metadata & metadata)
{
if (!ftypes::IsWifiChecker::Instance()(ft) || metadata.Has(feature::Metadata::FMD_INTERNET))
return;
metadata.Set(feature::Metadata::FMD_INTERNET, kWlan);
}
} // namespace
string DebugPrint(osm::Internet internet)
{
switch (internet)
{
case Internet::No: return kNo;
case Internet::Yes: return kYes;
case Internet::Wlan: return kWlan;
case Internet::Wired: return kWired;
case Internet::Unknown: break;
}
return {};
}
string DebugPrint(Props props)
{
string k;
switch (props)
{
case osm::Props::Phone: k = "phone"; break;
case osm::Props::Fax: k = "fax"; break;
case osm::Props::Email: k = "email"; break;
case osm::Props::Website: k = "website"; break;
case osm::Props::Internet: k = "internet_access"; break;
case osm::Props::Cuisine: k = "cuisine"; break;
case osm::Props::OpeningHours: k = "opening_hours"; break;
case osm::Props::Stars: k = "stars"; break;
case osm::Props::Operator: k = "operator"; break;
case osm::Props::Elevation: k = "ele"; break;
case osm::Props::Wikipedia: k = "wikipedia"; break;
case osm::Props::Flats: k = "addr:flats"; break;
case osm::Props::BuildingLevels: k = "building:levels"; break;
case osm::Props::Level: k = "level"; break;
}
return k;
}
void MapObject::SetFromFeatureType(FeatureType const & ft)
{
m_mercator = feature::GetCenter(ft);
m_name = ft.GetNames();
m_types = feature::TypesHolder(ft);
m_metadata = ft.GetMetadata();
m_featureID = ft.GetID();
ASSERT(m_featureID.IsValid(), ());
m_geomType = ft.GetFeatureType();
SetInetIfNeeded(ft, m_metadata);
}
FeatureID const & MapObject::GetID() const { return m_featureID; }
ms::LatLon MapObject::GetLatLon() const { return MercatorBounds::ToLatLon(m_mercator); }
m2::PointD const & MapObject::GetMercator() const { return m_mercator; }
feature::TypesHolder const & MapObject::GetTypes() const { return m_types; }
string MapObject::GetDefaultName() const
{
string name;
UNUSED_VALUE(m_name.GetString(StringUtf8Multilang::kDefaultCode, name));
return name;
}
string MapObject::GetLocalizedType() const
{
ASSERT(!m_types.Empty(), ());
feature::TypesHolder copy(m_types);
copy.SortBySpec();
CategoriesHolder const & categories = GetDefaultCategories();
return categories.GetReadableFeatureType(
*copy.begin(), categories.MapLocaleToInteger(languages::GetCurrentOrig()));
}
vector<osm::Props> MapObject::AvailableProperties() const
{
return MetadataToProps(m_metadata.GetPresentTypes());
}
string MapObject::GetPhone() const { return m_metadata.Get(feature::Metadata::FMD_PHONE_NUMBER); }
string MapObject::GetFax() const { return m_metadata.Get(feature::Metadata::FMD_FAX_NUMBER); }
string MapObject::GetEmail() const { return m_metadata.Get(feature::Metadata::FMD_EMAIL); }
string MapObject::GetWebsite() const
{
string website = m_metadata.Get(feature::Metadata::FMD_WEBSITE);
if (website.empty())
website = m_metadata.Get(feature::Metadata::FMD_URL);
return website;
}
Internet MapObject::GetInternet() const
{
string inet = m_metadata.Get(feature::Metadata::FMD_INTERNET);
strings::AsciiToLower(inet);
// Most popular case.
if (inet.empty())
return Internet::Unknown;
if (inet.find(kWlan) != string::npos)
return Internet::Wlan;
if (inet.find(kWired) != string::npos)
return Internet::Wired;
if (inet == kYes)
return Internet::Yes;
if (inet == kNo)
return Internet::No;
return Internet::Unknown;
}
vector<string> MapObject::GetCuisines() const
{
vector<string> cuisines;
Cuisines::Instance().Parse(m_metadata.Get(feature::Metadata::FMD_CUISINE), cuisines);
return cuisines;
}
vector<string> MapObject::GetLocalizedCuisines() const
{
vector<string> localized;
Cuisines::Instance().ParseAndLocalize(m_metadata.Get(feature::Metadata::FMD_CUISINE), localized);
return localized;
}
string MapObject::FormatCuisines() const { return strings::JoinStrings(GetLocalizedCuisines(), " • "); }
string MapObject::GetOpeningHours() const
{
return m_metadata.Get(feature::Metadata::FMD_OPEN_HOURS);
}
string MapObject::GetOperator() const { return m_metadata.Get(feature::Metadata::FMD_OPERATOR); }
int MapObject::GetStars() const
{
// Most popular case.
if (m_metadata.Has(feature::Metadata::FMD_STARS))
{
int count;
if (strings::to_int(m_metadata.Get(feature::Metadata::FMD_STARS), count))
return count;
}
return 0;
}
string MapObject::GetElevationFormatted() const
{
if (m_metadata.Has(feature::Metadata::FMD_ELE))
{
double value;
if (strings::to_double(m_metadata.Get(feature::Metadata::FMD_ELE), value))
return measurement_utils::FormatAltitude(value);
else
LOG(LWARNING,
("Invalid metadata for elevation:", m_metadata.Get(feature::Metadata::FMD_ELE)));
}
return {};
}
bool MapObject::GetElevation(double & outElevationInMeters) const
{
return strings::to_double(m_metadata.Get(feature::Metadata::FMD_ELE), outElevationInMeters);
}
string MapObject::GetWikipediaLink() const { return m_metadata.GetWikiURL(); }
string MapObject::GetFlats() const { return m_metadata.Get(feature::Metadata::FMD_FLATS); }
string MapObject::GetLevel() const { return m_metadata.Get(feature::Metadata::FMD_LEVEL); }
string MapObject::GetBuildingLevels() const
{
return m_metadata.Get(feature::Metadata::FMD_BUILDING_LEVELS);
}
ftraits::WheelchairAvailability MapObject::GetWheelchairType() const
{
return ftraits::Wheelchair::GetValue(m_types);
}
feature::Metadata const & MapObject::GetMetadata() const { return m_metadata; }
bool MapObject::IsPointType() const { return m_geomType == feature::EGeomType::GEOM_POINT; }
bool MapObject::IsBuilding() const { return ftypes::IsBuildingChecker::Instance()(m_types); }
} // namespace osm
|