From 0ba40954b9bf6810e223600c30affdc15a2b4f9c Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 28 Oct 2021 16:13:44 +0200 Subject: [PATCH] maps: allow using MAPBOX_TOKEN env variable (#22721) --- selfdrive/ui/qt/maps/map.h | 3 ++- selfdrive/ui/qt/onroad.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index 917b4d8c1..63f25a625 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -27,7 +27,8 @@ #include "selfdrive/common/util.h" #include "cereal/messaging/messaging.h" -const QString MAPS_HOST = util::getenv("MAPS_HOST", "https://maps.comma.ai").c_str(); +const QString MAPBOX_TOKEN = util::getenv("MAPBOX_TOKEN").c_str(); +const QString MAPS_HOST = util::getenv("MAPS_HOST", MAPBOX_TOKEN.isEmpty() ? "https://maps.comma.ai" : "https://api.mapbox.com").c_str(); class MapInstructions : public QWidget { Q_OBJECT diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 01ace08b3..8279035fa 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -79,11 +79,11 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { void OnroadWindow::offroadTransition(bool offroad) { #ifdef ENABLE_MAPS if (!offroad) { - if (map == nullptr && QUIState::ui_state.has_prime) { + if (map == nullptr && (QUIState::ui_state.has_prime || !MAPBOX_TOKEN.isEmpty())) { QMapboxGLSettings settings; // Valid for 4 weeks since we can't swap tokens on the fly - QString token = CommaApi::create_jwt({}, 4 * 7 * 24 * 3600); + QString token = MAPBOX_TOKEN.isEmpty() ? CommaApi::create_jwt({}, 4 * 7 * 24 * 3600) : MAPBOX_TOKEN; if (!Hardware::PC()) { settings.setCacheDatabasePath("/data/mbgl-cache.db");