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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
#include "map/bookmark.hpp"
#include "map/bookmark_helpers.hpp"
#include "indexer/scales.hpp"
#include "base/string_utils.hpp"
namespace
{
std::string GetBookmarkIconType(kml::BookmarkIcon const & icon)
{
switch (icon)
{
case kml::BookmarkIcon::None: return "default";
case kml::BookmarkIcon::Hotel: return "hotel";
case kml::BookmarkIcon::Animals: return "animals";
case kml::BookmarkIcon::Buddhism: return "buddhism";
case kml::BookmarkIcon::Building: return "building";
case kml::BookmarkIcon::Christianity: return "christianity";
case kml::BookmarkIcon::Entertainment: return "entertainment";
case kml::BookmarkIcon::Exchange: return "exchange";
case kml::BookmarkIcon::Food: return "restaurant";
case kml::BookmarkIcon::Gas: return "gas";
case kml::BookmarkIcon::Judaism: return "judaism";
case kml::BookmarkIcon::Medicine: return "medicine";
case kml::BookmarkIcon::Mountain: return "mountain";
case kml::BookmarkIcon::Museum: return "museum";
case kml::BookmarkIcon::Islam: return "islam";
case kml::BookmarkIcon::Park: return "park";
case kml::BookmarkIcon::Parking: return "parking";
case kml::BookmarkIcon::Shop: return "shop";
case kml::BookmarkIcon::Sights: return "sights";
case kml::BookmarkIcon::Swim: return "swim";
case kml::BookmarkIcon::Water: return "water";
case kml::BookmarkIcon::Bar: return "bar";
case kml::BookmarkIcon::Transport: return "transport";
case kml::BookmarkIcon::Viewpoint: return "viewpoint";
case kml::BookmarkIcon::Sport: return "sport";
case kml::BookmarkIcon::Pub: return "pub";
case kml::BookmarkIcon::Art: return "art";
case kml::BookmarkIcon::Bank: return "bank";
case kml::BookmarkIcon::Cafe: return "cafe";
case kml::BookmarkIcon::Pharmacy: return "pharmacy";
case kml::BookmarkIcon::Stadium: return "stadium";
case kml::BookmarkIcon::Theatre: return "theatre";
case kml::BookmarkIcon::Information: return "information";
case kml::BookmarkIcon::ChargingStation: return "charging_station";
case kml::BookmarkIcon::BicycleParking: return "bicycle_parking";
case kml::BookmarkIcon::BicycleParkingCovered: return "bicycle_parking_covered";
case kml::BookmarkIcon::BicycleRental: return "bicycle_rental";
case kml::BookmarkIcon::FastFood: return "fast_food";
case kml::BookmarkIcon::Airport: return "airport";
case kml::BookmarkIcon::Count: ASSERT(false, ("Invalid bookmark icon type")); return {};
}
UNREACHABLE();
}
std::string const kCustomImageProperty = "CustomImage";
std::string const kHasElevationProfileProperty = "has_elevation_profile";
} // namespace
Bookmark::Bookmark(m2::PointD const & ptOrg) : Base(ptOrg, UserMark::BOOKMARK), m_groupId(kml::kInvalidMarkGroupId)
{
m_data.m_point = ptOrg;
m_data.m_id = GetId();
}
Bookmark::Bookmark(kml::BookmarkData && data)
: Base(data.m_id, data.m_point, UserMark::BOOKMARK)
, m_data(std::move(data))
, m_groupId(kml::kInvalidMarkGroupId)
{
m_data.m_id = GetId();
m_data.m_color = kml::NormalizeBookmarkColorData(m_data.m_color);
}
void Bookmark::SetData(kml::BookmarkData const & data)
{
SetDirty();
m_data = data;
m_data.m_color = kml::NormalizeBookmarkColorData(m_data.m_color);
}
kml::BookmarkData const & Bookmark::GetData() const
{
return m_data;
}
search::ReverseGeocoder::RegionAddress const & Bookmark::GetAddress() const
{
return m_address;
}
void Bookmark::SetAddress(search::ReverseGeocoder::RegionAddress const & address)
{
SetDirty();
m_address = address;
}
void Bookmark::SetIsVisible(bool isVisible)
{
SetDirty();
m_isVisible = isVisible;
}
drape_ptr<df::UserPointMark::TitlesInfo> Bookmark::GetTitleDeclEx(settings::Placement p, dp::Color outlineColor) const
{
if (p == settings::Placement::None)
return nullptr;
dp::TitleDecl title;
switch (p)
{
case settings::Placement::Right: title.m_anchor = dp::Left; break;
case settings::Placement::Bottom: title.m_anchor = dp::Top; break;
default: UNREACHABLE();
}
title.m_primaryTextFont.m_color = GetColorForRendering();
title.m_primaryTextFont.m_outlineColor = outlineColor;
title.m_primaryTextFont.m_size = 11; // most frequent font size in styles
title.m_primaryText = GetPreferredName();
title.m_primaryOffset.x = 1;
auto titles = make_unique_dp<TitlesInfo>();
titles->push_back(std::move(title));
return titles;
}
df::DepthLayer Bookmark::GetDepthLayerEx(settings::Placement p) const
{
if (p == settings::Placement::None)
return df::DepthLayer::UserMarkLayer;
// Used for bookmark captions only, see DrapeEngine::GenerateMarkRenderInfo().
// SearchMarkLayer captions are placed through a separate OverlayTree pass,
// so bookmark captions displace only other bookmark captions.
return df::DepthLayer::SearchMarkLayer;
}
dp::Anchor Bookmark::GetAnchor() const
{
return dp::Bottom;
}
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> Bookmark::GetSymbolNames() const
{
auto symbolNames = GetCustomSymbolNames();
if (symbolNames != nullptr)
return symbolNames;
symbolNames = make_unique_dp<SymbolNameZoomInfo>();
symbolNames->insert(std::make_pair(1 /* zoomLevel */, "bookmark-default-xs"));
symbolNames->insert(std::make_pair(8 /* zoomLevel */, "bookmark-default-s"));
auto const iconType = GetBookmarkIconType(m_data.m_icon);
symbolNames->insert(std::make_pair(14 /* zoomLevel */, "bookmark-" + iconType + "-m"));
return symbolNames;
}
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> Bookmark::GetCustomSymbolNames() const
{
auto const it = m_data.m_properties.find(kCustomImageProperty);
if (it == m_data.m_properties.end())
return nullptr;
auto symbolNames = make_unique_dp<SymbolNameZoomInfo>();
strings::Tokenize(it->second, ";", [&](std::string_view token)
{
uint8_t zoomLevel = 1;
auto pos = token.find(',');
if (pos != std::string::npos && strings::to_uint(token.substr(0, pos), zoomLevel))
token = token.substr(pos + 1);
if (!token.empty() && zoomLevel >= 1 && zoomLevel <= scales::GetUpperStyleScale())
symbolNames->emplace(zoomLevel, std::string(token));
});
if (symbolNames->empty())
return nullptr;
return symbolNames;
}
df::ColorConstant Bookmark::GetColorConstant() const
{
switch (m_data.m_color.m_predefinedColor)
{
case kml::PredefinedColor::Red: return "BookmarkRed";
case kml::PredefinedColor::Blue: return "BookmarkBlue";
case kml::PredefinedColor::Purple: return "BookmarkPurple";
case kml::PredefinedColor::Yellow: return "BookmarkYellow";
case kml::PredefinedColor::Pink: return "BookmarkPink";
case kml::PredefinedColor::Brown: return "BookmarkBrown";
case kml::PredefinedColor::Green: return "BookmarkGreen";
case kml::PredefinedColor::Orange: return "BookmarkOrange";
case kml::PredefinedColor::DeepPurple: return "BookmarkDeepPurple";
case kml::PredefinedColor::LightBlue: return "BookmarkLightBlue";
case kml::PredefinedColor::Cyan: return "BookmarkCyan";
case kml::PredefinedColor::Teal: return "BookmarkTeal";
case kml::PredefinedColor::Lime: return "BookmarkLime";
case kml::PredefinedColor::DeepOrange: return "BookmarkDeepOrange";
case kml::PredefinedColor::Gray: return "BookmarkGray";
case kml::PredefinedColor::BlueGray: return "BookmarkBlueGray";
case kml::PredefinedColor::None:
case kml::PredefinedColor::Count: return "BookmarkRed";
}
UNREACHABLE();
}
bool Bookmark::HasCreationAnimation() const
{
return true;
}
kml::PredefinedColor Bookmark::GetColor() const
{
return m_data.m_color.m_predefinedColor;
}
void Bookmark::SetColor(dp::Color color)
{
auto const colorData = kml::MakeCustomBookmarkColorData(color);
if (m_data.m_color == colorData)
return;
SetDirty();
m_data.m_color = colorData;
}
std::optional<dp::Color> Bookmark::GetCustomColor() const
{
if (kml::IsCustomBookmarkColor(m_data.m_color))
return dp::Color(m_data.m_color.m_rgba);
return std::nullopt;
}
dp::Color Bookmark::GetColorForRendering() const
{
return GetCustomColor().value_or(df::GetColorConstant(GetColorConstant()));
}
std::string Bookmark::GetPreferredName() const
{
return GetPreferredBookmarkName(m_data);
}
kml::LocalizableString Bookmark::GetName() const
{
return m_data.m_name;
}
void Bookmark::SetName(kml::LocalizableString const & name)
{
SetDirty();
m_data.m_name = name;
}
void Bookmark::SetName(std::string const & name, int8_t langCode)
{
SetDirty();
m_data.m_name[langCode] = name;
}
std::string Bookmark::GetCustomName() const
{
return GetPreferredBookmarkStr(m_data.m_customName);
}
void Bookmark::SetCustomName(std::string const & customName)
{
SetDirty();
kml::SetDefaultStr(m_data.m_customName, customName);
}
m2::RectD Bookmark::GetViewport() const
{
return m2::RectD(GetPivot(), GetPivot());
}
std::string Bookmark::GetDescription() const
{
return GetPreferredBookmarkStr(m_data.m_description);
}
void Bookmark::SetDescription(std::string const & description)
{
SetDirty();
kml::SetDefaultStr(m_data.m_description, description);
}
kml::Timestamp Bookmark::GetTimeStamp() const
{
return m_data.m_timestamp;
}
void Bookmark::SetTimeStamp(kml::Timestamp timeStamp)
{
SetDirty();
m_data.m_timestamp = timeStamp;
}
uint8_t Bookmark::GetScale() const
{
return m_data.m_viewportScale;
}
void Bookmark::SetScale(uint8_t scale)
{
SetDirty();
m_data.m_viewportScale = scale;
}
kml::MarkGroupId Bookmark::GetGroupId() const
{
return m_groupId;
}
bool Bookmark::CanFillPlacePageMetadata() const
{
auto const & p = m_data.m_properties;
if (auto const hours = p.find("hours"); hours != p.end() && !hours->second.empty())
return true;
return false;
}
void Bookmark::Attach(kml::MarkGroupId groupId)
{
ASSERT_NOT_EQUAL(groupId, kml::kInvalidMarkGroupId, ());
ASSERT_EQUAL(m_groupId, kml::kInvalidMarkGroupId, ());
m_groupId = groupId;
}
void Bookmark::AttachCompilation(kml::MarkGroupId groupId)
{
ASSERT(groupId != kml::kInvalidMarkGroupId, ());
m_compilationIds.push_back(groupId);
}
void Bookmark::Detach()
{
m_groupId = kml::kInvalidMarkGroupId;
m_compilationIds.clear();
}
BookmarkCategory::BookmarkCategory(std::string const & name, kml::MarkGroupId groupId, bool autoSave)
: Base(UserMark::Type::BOOKMARK)
, m_autoSave(autoSave)
{
m_data.m_id = groupId;
SetName(name);
}
BookmarkCategory::BookmarkCategory(kml::CategoryData && data, bool autoSave)
: Base(UserMark::Type::BOOKMARK)
, m_autoSave(autoSave)
, m_data(std::move(data))
{
Base::SetIsVisible(m_data.m_visible);
}
void BookmarkCategory::SetIsVisible(bool isVisible)
{
Base::SetIsVisible(isVisible);
m_data.m_visible = isVisible;
}
void BookmarkCategory::SetName(std::string const & name)
{
SetDirty(true /* updateModificationTime */);
kml::SetDefaultStr(m_data.m_name, name);
}
void BookmarkCategory::SetDescription(std::string const & desc)
{
SetDirty(true /* updateModificationTime */);
kml::SetDefaultStr(m_data.m_description, desc);
}
void BookmarkCategory::SetServerId(std::string const & serverId)
{
if (m_serverId == serverId)
return;
SetDirty(true /* updateModificationTime */);
m_serverId = serverId;
}
void BookmarkCategory::SetTags(std::vector<std::string> const & tags)
{
if (m_data.m_tags == tags)
return;
SetDirty(true /* updateModificationTime */);
m_data.m_tags = tags;
}
void BookmarkCategory::SetCustomProperty(std::string const & key, std::string const & value)
{
auto it = m_data.m_properties.find(key);
if (it != m_data.m_properties.end() && it->second == value)
return;
SetDirty(true /* updateModificationTime */);
m_data.m_properties[key] = value;
}
std::string BookmarkCategory::GetName() const
{
return GetPreferredBookmarkStr(m_data.m_name);
}
bool BookmarkCategory::HasElevationProfile() const
{
auto const it = m_data.m_properties.find(kHasElevationProfileProperty);
return (it != m_data.m_properties.end()) && (it->second != "0");
}
void BookmarkCategory::SetAuthor(std::string const & name, std::string const & id)
{
if (m_data.m_authorName == name && m_data.m_authorId == id)
return;
SetDirty(true /* updateModificationTime */);
m_data.m_authorName = name;
m_data.m_authorId = id;
}
void BookmarkCategory::SetAccessRules(kml::AccessRules accessRules)
{
if (m_data.m_accessRules == accessRules)
return;
SetDirty(true /* updateModificationTime */);
m_data.m_accessRules = accessRules;
}
void BookmarkCategory::SetDirty(bool updateModificationDate)
{
Base::SetDirty(updateModificationDate);
if (updateModificationDate)
m_data.m_lastModified = kml::TimestampClock::now();
}
|