diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index 35eaa1d2f7..83b1f5d118 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -22,6 +22,12 @@ const float MAP_SCALE = 2; MapWindow::MapWindow(const QMapLibre::Settings &settings) : m_settings(settings), velocity_filter(0, 10, 0.05, false) { QObject::connect(uiState(), &UIState::uiUpdate, this, &MapWindow::updateState); + reinit_timer.setSingleShot(true); + QObject::connect(&reinit_timer, &QTimer::timeout, this, [=] { + m_settings.setApiKey(get_mapbox_token()); + initializeGL(); + }); + map_overlay = new QWidget (this); map_overlay->setAttribute(Qt::WA_TranslucentBackground, true); QVBoxLayout *overlay_layout = new QVBoxLayout(map_overlay); @@ -256,10 +262,11 @@ void MapWindow::initializeGL() { QObject::connect(m_map.data(), &QMapLibre::Map::mapLoadingFailed, [=](QMapLibre::Map::MapLoadingFailure err_code, const QString &reason) { LOGE("Map loading failed with %d: '%s'\n", err_code, reason.toStdString().c_str()); - // if time is wrong, re-create token and try connecting again in 5s - if (err_code == QMapLibre::Map::MapLoadingFailure::StyleLoadFailure && reason.contains("SSL handshake failed")) { - m_settings.setApiKey(get_mapbox_token()); - QTimer::singleShot(5000, this, &MapWindow::initializeGL); + // time could be wrong, re-create token and try connecting again in 5s + if (err_code == QMapLibre::Map::MapLoadingFailure::StyleLoadFailure && !loaded_once) { + if (!reinit_timer.isActive()) { + reinit_timer.start(5000); + } } }); diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index 8193d55729..8061fb4733 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -51,6 +51,7 @@ private: void setError(const QString &err_str); bool loaded_once = false; + QTimer reinit_timer; // Panning QPointF m_lastPos;