| 1497 | } |
| 1498 | |
| 1499 | void RoutingManager::LoadRoutePoints(LoadRouteHandler const & handler) |
| 1500 | { |
| 1501 | GetPlatform().RunTask(Platform::Thread::File, [this, handler]() |
| 1502 | { |
| 1503 | if (!HasSavedRoutePoints()) |
| 1504 | { |
| 1505 | if (handler) |
| 1506 | handler(false /* success */); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | // Delete file after loading. |
| 1511 | auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile); |
| 1512 | SCOPE_GUARD(routePointsFileGuard, bind(&FileWriter::DeleteFileX, cref(fileName))); |
| 1513 | |
| 1514 | string data; |
| 1515 | try |
| 1516 | { |
| 1517 | ReaderPtr<Reader>(GetPlatform().GetReader(fileName)).ReadAsString(data); |
| 1518 | } |
| 1519 | catch (RootException const & ex) |
| 1520 | { |
| 1521 | LOG(LWARNING, ("Loading road points failed:", ex.Msg())); |
| 1522 | if (handler) |
| 1523 | handler(false /* success */); |
| 1524 | return; |
| 1525 | } |
| 1526 | |
| 1527 | auto points = DeserializeRoutePoints(data); |
| 1528 | if (handler && points.empty()) |
| 1529 | { |
| 1530 | handler(false /* success */); |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | GetPlatform().RunTask(Platform::Thread::Gui, [this, handler, points = std::move(points)]() mutable |
| 1535 | { |
| 1536 | ASSERT(m_bmManager != nullptr, ()); |
| 1537 | // If we have found my position and the saved route used the user's position, we use my position as start point. |
| 1538 | bool routeUsedPosition = false; |
| 1539 | auto const & myPosMark = m_bmManager->MyPositionMark(); |
| 1540 | auto editSession = m_bmManager->GetEditSession(); |
| 1541 | editSession.ClearGroup(UserMark::Type::ROUTING); |
| 1542 | for (auto & p : points) |
| 1543 | { |
| 1544 | // Check if the saved route used the user's position |
| 1545 | if (p.m_replaceWithMyPositionAfterRestart && p.m_pointType == RouteMarkType::Start) |
| 1546 | routeUsedPosition = true; |
| 1547 | |
| 1548 | if (p.m_replaceWithMyPositionAfterRestart && p.m_pointType == RouteMarkType::Start && myPosMark.HasPosition()) |
| 1549 | { |
| 1550 | RouteMarkData startPt; |
| 1551 | startPt.m_pointType = RouteMarkType::Start; |
| 1552 | startPt.m_isMyPosition = true; |
| 1553 | startPt.m_position = myPosMark.GetPivot(); |
| 1554 | AddRoutePoint(std::move(startPt)); |
| 1555 | } |
| 1556 | else |
no test coverage detected