diff --git a/android/jni/com/mapswithme/maps/metrics/UserActionsLogger.cpp b/android/jni/com/mapswithme/maps/metrics/UserActionsLogger.cpp index 6609131559..003a6617b8 100644 --- a/android/jni/com/mapswithme/maps/metrics/UserActionsLogger.cpp +++ b/android/jni/com/mapswithme/maps/metrics/UserActionsLogger.cpp @@ -13,12 +13,12 @@ namespace { void RegisterEventIfPossible(eye::MapObject::Event::Type const type) { - place_page::Info & info = g_framework->GetPlacePageInfo(); + auto & info = g_framework->GetPlacePageInfo(); auto const userPos = g_framework->NativeFramework()->GetCurrentPosition(); if (userPos) { - eye::MapObject const mapObject = utils::MakeEyeMapObject(info); + auto const mapObject = utils::MakeEyeMapObject(info); if (!mapObject.IsEmpty()) eye::Eye::Event::MapObjectEvent(mapObject, type, userPos.get()); } diff --git a/geometry/mercator.hpp b/geometry/mercator.hpp index 0da726428b..7c61f7394e 100644 --- a/geometry/mercator.hpp +++ b/geometry/mercator.hpp @@ -64,6 +64,12 @@ struct MercatorBounds return RectByCenterXYAndSizeInMeters(center.x, center.y, size, size); } + static m2::RectD RectByCenterXYAndOffset(m2::PointD const & center, double offset) + { + return {ClampX(center.x - offset), ClampY(center.y - offset), + ClampX(center.x + offset), ClampY(center.y + offset)}; + } + static m2::PointD GetSmPoint(m2::PointD const & pt, double lonMetresR, double latMetresR); static double constexpr GetCellID2PointAbsEpsilon() { return 1.0E-4; } diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index 2cb5884836..117f67bcb7 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -73,7 +73,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page: auto const userPos = GetFramework().GetCurrentPosition(); if (userPos) { - eye::MapObject const mapObject = utils::MakeEyeMapObject(info); + auto const mapObject = utils::MakeEyeMapObject(info); if (!mapObject.IsEmpty()) eye::Eye::Event::MapObjectEvent(mapObject, type, userPos.get()); } diff --git a/map/framework.cpp b/map/framework.cpp index d79bd8035c..a590137840 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -200,16 +200,19 @@ void OnRouteStartBuild(DataSource const & dataSource, if (pt.m_isMyPosition || pt.m_pointType == RouteMarkType::Start) continue; - m2::RectD rect(MercatorBounds::ClampX(pt.m_position.x - kMwmPointAccuracy), - MercatorBounds::ClampY(pt.m_position.y - kMwmPointAccuracy), - MercatorBounds::ClampX(pt.m_position.x + kMwmPointAccuracy), - MercatorBounds::ClampY(pt.m_position.y + kMwmPointAccuracy)); - - dataSource.ForEachInRect([&userPos](FeatureType & ft) + m2::RectD rect = MercatorBounds::RectByCenterXYAndOffset(pt.m_position, kMwmPointAccuracy); + bool found = false; + dataSource.ForEachInRect([&userPos, &pt, &found](FeatureType & ft) { + if (found || !feature::GetCenter(ft).EqualDxDy(pt.m_position, kMwmPointAccuracy)) + return; + auto const mapObject = utils::MakeEyeMapObject(ft); if (!mapObject.IsEmpty()) + { eye::Eye::Event::MapObjectEvent(mapObject, MapObject::Event::Type::RouteToCreated, userPos); + found = true; + } }, rect, scales::GetUpperScale()); } @@ -2440,7 +2443,7 @@ df::SelectionShape::ESelectedObject Framework::OnTapEventImpl(TapEvent const & t auto const userPos = GetCurrentPosition(); if (userPos) { - eye::MapObject const mapObject = utils::MakeEyeMapObject(outInfo); + auto const mapObject = utils::MakeEyeMapObject(outInfo); if (!mapObject.IsEmpty()) { eye::Eye::Event::MapObjectEvent(mapObject, eye::MapObject::Event::Type::Open, diff --git a/map/notifications/notification_manager.cpp b/map/notifications/notification_manager.cpp index 98c37b3f05..ee7ed0859c 100644 --- a/map/notifications/notification_manager.cpp +++ b/map/notifications/notification_manager.cpp @@ -9,7 +9,6 @@ #include "base/macros.hpp" #include -#include #include using namespace notifications; diff --git a/metrics/eye.cpp b/metrics/eye.cpp index eda6f08ca2..6f8ce75dfd 100644 --- a/metrics/eye.cpp +++ b/metrics/eye.cpp @@ -10,6 +10,7 @@ #include "base/logging.hpp" #include +#include #include #include #include @@ -20,6 +21,7 @@ namespace { // Three months. auto constexpr kMapObjectEventsExpirePeriod = std::chrono::hours(24 * 30 * 3); +auto constexpr kEventCooldown = std::chrono::seconds(2); std::array const kMapEventSupportedTypes = {"amenity-bar", "amenity-cafe", "amenity-pub", "amenity-restaurant", @@ -340,18 +342,30 @@ void Eye::RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event:: event.m_eventTime = Clock::now(); bool found = false; - mapObjects.ForEachInRect(result.GetLimitRect(), [&found, &event, &result](MapObject const & item) + bool duplication = false; + mapObjects.ForEachInRect( + result.GetLimitRect(), [&found, &duplication, &event, &result](MapObject const & item) { - if (!item.AlmostEquals(result)) + if (found || duplication || !item.AlmostEquals(result)) return; if (!found) found = true; + auto & events = item.GetEditableEvents(); + if (!events.empty() && events.back().m_type == event.m_type && + event.m_eventTime - events.back().m_eventTime <= kEventCooldown) + { + duplication = true; + } + item.GetEditableEvents().emplace_back(std::move(event)); result = item; }); + if (duplication) + return; + if (!found) { result.GetEditableEvents() = {std::move(event)}; diff --git a/metrics/eye_info.hpp b/metrics/eye_info.hpp index 8221a2f00f..220c987b1b 100644 --- a/metrics/eye_info.hpp +++ b/metrics/eye_info.hpp @@ -221,10 +221,7 @@ public: void SetPos(m2::PointD const & pos) { m_pos = pos; - m_limitRect = {MercatorBounds::ClampX(pos.x - kMwmPointAccuracy), - MercatorBounds::ClampY(pos.y - kMwmPointAccuracy), - MercatorBounds::ClampX(pos.x + kMwmPointAccuracy), - MercatorBounds::ClampY(pos.y + kMwmPointAccuracy)}; + m_limitRect = MercatorBounds::RectByCenterXYAndOffset(pos, kMwmPointAccuracy); } std::string const & GetDefaultName() const { return m_defaultName; } @@ -248,9 +245,6 @@ public: visitor(m_events, "events")); private: - // We are use 1e-5 eps because of points in mwm have this accuracy. - static double constexpr kMwmPointAccuracy = 1e-5; - std::string m_bestType; m2::PointD m_pos; std::string m_defaultName; diff --git a/ugc/storage.cpp b/ugc/storage.cpp index f59012a10a..95febbe8bf 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -29,6 +29,8 @@ #include +#include "defines.hpp" + using namespace std; namespace @@ -299,8 +301,7 @@ UpdateIndexes::const_iterator Storage::FindIndex(uint32_t bestType, m2::PointD c return find_if( m_indexes.begin(), m_indexes.end(), [typeIndex, &point](UpdateIndex const & index) -> bool { - // We are use 1e-5 eps because of points in mwm have this accuracy. - return typeIndex == index.m_type && point.EqualDxDy(index.m_mercator, 1e-5 /* eps */) && + return typeIndex == index.m_type && point.EqualDxDy(index.m_mercator, kMwmPointAccuracy) && !index.m_deleted; }); }