| 555 | } |
| 556 | |
| 557 | void ParsedMapApi::ExecuteMapApiRequest(Framework & fm) const |
| 558 | { |
| 559 | ASSERT_EQUAL(m_requestType, UrlType::Map, ("Must be a Map API request")); |
| 560 | VERIFY(m_mapPoints.size() > 0, ("Map API request must have at least one point")); |
| 561 | |
| 562 | // Clear every current API-mark. |
| 563 | auto editSession = fm.GetBookmarkManager().GetEditSession(); |
| 564 | editSession.ClearGroup(UserMark::Type::API); |
| 565 | editSession.SetIsVisible(UserMark::Type::API, true); |
| 566 | |
| 567 | // Add marks from the request. |
| 568 | m2::RectD viewport; |
| 569 | for (auto const & [lat, lon, name, id, style] : m_mapPoints) |
| 570 | { |
| 571 | m2::PointD const glPoint(mercator::FromLatLon(lat, lon)); |
| 572 | auto * mark = editSession.CreateUserMark<ApiMarkPoint>(glPoint); |
| 573 | mark->SetName(name); |
| 574 | mark->SetApiID(id); |
| 575 | mark->SetStyle(style::GetSupportedStyle(style)); |
| 576 | viewport.Add(glPoint); |
| 577 | } |
| 578 | |
| 579 | // Calculate the optimal viewport. |
| 580 | VERIFY(viewport.IsValid(), ()); |
| 581 | m2::PointD const center = viewport.Center(); |
| 582 | |
| 583 | // Calculate the best zoom. |
| 584 | int zoomLevel; |
| 585 | if (m_mapPoints.size() == 1) |
| 586 | if (m_zoomLevel >= 1.0) // 0 means uninitialized/not passed to the API. |
| 587 | zoomLevel = std::min(scales::GetUpperComfortScale(), static_cast<int>(m_zoomLevel)); |
| 588 | else |
| 589 | zoomLevel = scales::GetUpperComfortScale(); |
| 590 | else |
| 591 | zoomLevel = df::GetDrawTileScale(viewport); |
| 592 | |
| 593 | // Always hide current map selection. |
| 594 | fm.DeactivateMapSelection(); |
| 595 | |
| 596 | // Set viewport and stop follow mode. |
| 597 | fm.StopLocationFollow(); |
| 598 | |
| 599 | // ShowRect function interferes with ActivateMapSelection and we have strange behaviour as a result. |
| 600 | // Use more obvious SetModelViewCenter here. |
| 601 | /// @todo Funny, but animation is still present, but now centering works fine. |
| 602 | /// Looks like there is one more set viewport call somewhere. |
| 603 | fm.SetViewportCenter(center, zoomLevel, false /* isAnim */, true /* trackVisibleViewport */); |
| 604 | |
| 605 | // Don't show the place page in case of multiple points. |
| 606 | if (m_mapPoints.size() > 1) |
| 607 | return; |
| 608 | |
| 609 | place_page::BuildInfo info; |
| 610 | info.m_needAnimationOnSelection = false; |
| 611 | info.m_mercator = mercator::FromLatLon(m_mapPoints[0].m_lat, m_mapPoints[0].m_lon); |
| 612 | // Other details will be filled in by BuildPlacePageInfo(). |
| 613 | fm.BuildAndSetPlacePageInfo(info); |
| 614 | } |
nothing calls this directly
no test coverage detected