mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-25 03:12:09 +08:00
maps: split
This commit is contained in:
@@ -8,7 +8,11 @@
|
||||
#include "common/util.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/swaglog.h"
|
||||
#ifdef SUNNYPILOT
|
||||
#include "selfdrive/ui/sunnypilot/qt/maps/sp_priv_map_helpers.h"
|
||||
#else
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
#endif
|
||||
|
||||
const float DEFAULT_ZOOM = 13.5; // Don't go below 13 or features will start to disappear
|
||||
const int HEIGHT = 256, WIDTH = 256;
|
||||
|
||||
@@ -18,10 +18,11 @@ if arch == "Darwin":
|
||||
qt_env['CXXFLAGS'] += ["-Wno-deprecated-declarations"]
|
||||
|
||||
sp_widgets_src = []
|
||||
sp_maps_widgets_src = []
|
||||
sp_qt_src = []
|
||||
if GetOption('sunnypilot'):
|
||||
SConscript(['sunnypilot/SConscript'])
|
||||
Import('sp_widgets_src', 'sp_qt_src')
|
||||
Import('sp_widgets_src', 'sp_maps_widgets_src', 'sp_qt_src')
|
||||
|
||||
qt_util = qt_env.Library("qt_util", ["#selfdrive/ui/qt/api.cc", "#selfdrive/ui/qt/util.cc"], LIBS=base_libs)
|
||||
widgets_src = ["ui.cc", "qt/widgets/input.cc", "qt/widgets/wifi.cc",
|
||||
@@ -34,7 +35,7 @@ qt_env['CPPDEFINES'] = ["SUNNYPILOT"] if GetOption('sunnypilot') else []
|
||||
if maps:
|
||||
base_libs += ['QMapLibre']
|
||||
widgets_src += ["qt/maps/map_helpers.cc", "qt/maps/map_settings.cc", "qt/maps/map.cc", "qt/maps/map_panel.cc",
|
||||
"qt/maps/map_eta.cc", "qt/maps/map_instructions.cc"]
|
||||
"qt/maps/map_eta.cc", "qt/maps/map_instructions.cc"] + sp_maps_widgets_src
|
||||
qt_env['CPPDEFINES'] += ["ENABLE_MAPS"]
|
||||
|
||||
widgets = qt_env.Library("qt_widgets", widgets_src, LIBS=base_libs)
|
||||
|
||||
@@ -75,7 +75,7 @@ void MapWindow::initLayers() {
|
||||
|
||||
QVariantMap transition;
|
||||
transition["duration"] = 400; // ms
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(uiState()->scene.navigate_on_openpilot_deprecated));
|
||||
m_map->setPaintProperty("navLayer", "line-color", QColor("#31a1ee"));
|
||||
m_map->setPaintProperty("navLayer", "line-color-transition", transition);
|
||||
m_map->setPaintProperty("navLayer", "line-width", 7.5);
|
||||
m_map->setLayoutProperty("navLayer", "line-cap", "round");
|
||||
@@ -110,52 +110,10 @@ void MapWindow::initLayers() {
|
||||
// TODO: remove, symbol-sort-key does not seem to matter outside of each layer
|
||||
m_map->setLayoutProperty("carPosLayer", "symbol-sort-key", 0);
|
||||
}
|
||||
if ((!m_map->layerExists("buildingsLayer")) && uiState()->scene.map_3d_buildings) { // Could put this behind the cellular metered toggle in case it increases data usage
|
||||
qDebug() << "Initializing buildingsLayer";
|
||||
QVariantMap buildings;
|
||||
buildings["id"] = "buildingsLayer";
|
||||
buildings["source"] = "composite";
|
||||
buildings["source-layer"] = "building";
|
||||
buildings["type"] = "fill-extrusion";
|
||||
buildings["minzoom"] = 15;
|
||||
m_map->addLayer("buildingsLayer", buildings);
|
||||
m_map->setFilter("buildingsLayer", QVariantList({"==", "extrude", "true"}));
|
||||
|
||||
QVariantList fillExtrusionHeight = { // scale buildings as you zoom in
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0,
|
||||
15.05, QVariantList{"get", "height"}
|
||||
};
|
||||
|
||||
QVariantList fillExtrusionBase = {
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0,
|
||||
15.05, QVariantList{"get", "min_height"}
|
||||
};
|
||||
|
||||
QVariantList fillExtrusionOpacity = {
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0, // transparent at zoom level 15
|
||||
15.5, .6, // fade in
|
||||
17, .6, // begin fading out
|
||||
20, 0 // fade out when zoomed in
|
||||
};
|
||||
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-color", QColor("grey"));
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-opacity", fillExtrusionOpacity);
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-height", fillExtrusionHeight);
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-base", fillExtrusionBase);
|
||||
m_map->setLayoutProperty("buildingsLayer", "visibility", "visible");
|
||||
}
|
||||
}
|
||||
|
||||
void MapWindow::updateState(const UIState &s) {
|
||||
#ifdef SUNNYPILOT
|
||||
if (!uiState()->scene.started) {
|
||||
return;
|
||||
}
|
||||
@@ -169,22 +127,7 @@ void MapWindow::updateState(const UIState &s) {
|
||||
initializeGL();
|
||||
}
|
||||
prev_time_valid = sm.valid("clocks");
|
||||
|
||||
if (sm.updated("modelV2")) {
|
||||
// set path color on change, and show map on rising edge of navigate on openpilot
|
||||
auto car_control = sm["carControl"].getCarControl();
|
||||
bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabledDEPRECATED() &&
|
||||
(sm["controlsState"].getControlsState().getEnabled() || car_control.getLatActive() || car_control.getLongActive());
|
||||
if (nav_enabled != uiState()->scene.navigate_on_openpilot_deprecated) {
|
||||
if (loaded_once) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(nav_enabled));
|
||||
}
|
||||
if (nav_enabled) {
|
||||
emit requestVisible(true);
|
||||
}
|
||||
}
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = nav_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sm.updated("liveLocationKalman")) {
|
||||
auto locationd_location = sm["liveLocationKalman"].getLiveLocationKalman();
|
||||
@@ -425,7 +368,6 @@ void MapWindow::pinchTriggered(QPinchGesture *gesture) {
|
||||
void MapWindow::offroadTransition(bool offroad) {
|
||||
if (offroad) {
|
||||
clearRoute();
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = false;
|
||||
routing_problem = false;
|
||||
} else {
|
||||
auto dest = coordinate_from_param("NavDestination");
|
||||
|
||||
@@ -32,15 +32,17 @@ public:
|
||||
~MapWindow();
|
||||
|
||||
private:
|
||||
void initializeGL() final;
|
||||
void paintGL() final;
|
||||
void resizeGL(int w, int h) override;
|
||||
|
||||
protected:
|
||||
void initializeGL() final;
|
||||
QMapLibre::Settings m_settings;
|
||||
QScopedPointer<QMapLibre::Map> m_map;
|
||||
|
||||
void initLayers();
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *ev) final;
|
||||
void mouseDoubleClickEvent(QMouseEvent *ev) final;
|
||||
void mouseMoveEvent(QMouseEvent *ev) final;
|
||||
@@ -50,9 +52,11 @@ private:
|
||||
void pinchTriggered(QPinchGesture *gesture);
|
||||
void setError(const QString &err_str);
|
||||
|
||||
protected:
|
||||
bool loaded_once = false;
|
||||
bool prev_time_valid = true;
|
||||
|
||||
private:
|
||||
// Panning
|
||||
QPointF m_lastPos;
|
||||
int interaction_counter = 0;
|
||||
@@ -70,16 +74,11 @@ private:
|
||||
MapInstructions* map_instructions;
|
||||
MapETA* map_eta;
|
||||
|
||||
// Blue with normal nav, green when nav is input into the model
|
||||
QColor getNavPathColor(bool nav_enabled) {
|
||||
return nav_enabled ? QColor("#31ee73") : QColor("#31a1ee");
|
||||
}
|
||||
|
||||
void clearRoute();
|
||||
void updateDestinationMarker();
|
||||
uint64_t route_rcv_frame = 0;
|
||||
|
||||
private slots:
|
||||
protected slots:
|
||||
void updateState(const UIState &s);
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
#include "common/transformations/coordinates.hpp"
|
||||
#include "common/transformations/orientation.hpp"
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "common/params.h"
|
||||
|
||||
const QString MAPBOX_TOKEN = QString::fromStdString(Params().get("CustomMapboxTokenSk")) != "" ? QString::fromStdString(Params().get("CustomMapboxTokenSk")) : util::getenv("MAPBOX_TOKEN").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();
|
||||
const QString MAPS_CACHE_PATH = "/data/mbgl-cache-navd.db";
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@ widgets_src = [
|
||||
"sunnypilot/qt/widgets/sp_priv_toggle.cc"
|
||||
]
|
||||
|
||||
sp_maps_widgets_src = [
|
||||
"sunnypilot/qt/maps/sp_priv_map.cc"
|
||||
]
|
||||
|
||||
network_src = [
|
||||
"sunnypilot/qt/network/sunnylink/sp_priv_sunnylink_client.cc",
|
||||
"sunnypilot/qt/network/sunnylink/services/sp_priv_base_device_service.cc",
|
||||
@@ -45,4 +49,4 @@ qt_src = [
|
||||
sp_widgets_src = widgets_src + network_src
|
||||
sp_qt_src = qt_src
|
||||
|
||||
Export('sp_widgets_src', 'sp_qt_src')
|
||||
Export('sp_widgets_src', 'sp_maps_widgets_src', 'sp_qt_src')
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "selfdrive/ui/sunnypilot/qt/maps/sp_priv_map.h"
|
||||
|
||||
#include "common/swaglog.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/maps/sp_priv_map_helpers.h"
|
||||
|
||||
void MapWindowSP::initLayers() {
|
||||
if (!m_map->layerExists("navLayer")) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(uiState()->scene.navigate_on_openpilot_deprecated));
|
||||
}
|
||||
if ((!m_map->layerExists("buildingsLayer")) && uiState()->scene.map_3d_buildings) { // Could put this behind the cellular metered toggle in case it increases data usage
|
||||
qDebug() << "Initializing buildingsLayer";
|
||||
QVariantMap buildings;
|
||||
buildings["id"] = "buildingsLayer";
|
||||
buildings["source"] = "composite";
|
||||
buildings["source-layer"] = "building";
|
||||
buildings["type"] = "fill-extrusion";
|
||||
buildings["minzoom"] = 15;
|
||||
m_map->addLayer("buildingsLayer", buildings);
|
||||
m_map->setFilter("buildingsLayer", QVariantList({"==", "extrude", "true"}));
|
||||
|
||||
QVariantList fillExtrusionHeight = { // scale buildings as you zoom in
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0,
|
||||
15.05, QVariantList{"get", "height"}
|
||||
};
|
||||
|
||||
QVariantList fillExtrusionBase = {
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0,
|
||||
15.05, QVariantList{"get", "min_height"}
|
||||
};
|
||||
|
||||
QVariantList fillExtrusionOpacity = {
|
||||
"interpolate",
|
||||
QVariantList{"linear"},
|
||||
QVariantList{"zoom"},
|
||||
15, 0, // transparent at zoom level 15
|
||||
15.5, .6, // fade in
|
||||
17, .6, // begin fading out
|
||||
20, 0 // fade out when zoomed in
|
||||
};
|
||||
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-color", QColor("grey"));
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-opacity", fillExtrusionOpacity);
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-height", fillExtrusionHeight);
|
||||
m_map->setPaintProperty("buildingsLayer", "fill-extrusion-base", fillExtrusionBase);
|
||||
m_map->setLayoutProperty("buildingsLayer", "visibility", "visible");
|
||||
}
|
||||
}
|
||||
|
||||
void MapWindowSP::updateState(const UIState &s) {
|
||||
if (!uiState()->scene.started) {
|
||||
return;
|
||||
}
|
||||
const SubMaster &sm = *(s.sm);
|
||||
update();
|
||||
|
||||
// on rising edge of a valid system time, reinitialize the map to set a new token
|
||||
if (sm.valid("clocks") && !prev_time_valid) {
|
||||
LOGW("Time is now valid, reinitializing map");
|
||||
m_settings.setApiKey(get_mapbox_token());
|
||||
initializeGL();
|
||||
}
|
||||
prev_time_valid = sm.valid("clocks");
|
||||
|
||||
if (sm.updated("modelV2")) {
|
||||
// set path color on change, and show map on rising edge of navigate on openpilot
|
||||
auto car_control = sm["carControl"].getCarControl();
|
||||
bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabledDEPRECATED() &&
|
||||
(sm["controlsState"].getControlsState().getEnabled() || car_control.getLatActive() || car_control.getLongActive());
|
||||
if (nav_enabled != uiState()->scene.navigate_on_openpilot_deprecated) {
|
||||
if (loaded_once) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(nav_enabled));
|
||||
}
|
||||
if (nav_enabled) {
|
||||
emit requestVisible(true);
|
||||
}
|
||||
}
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = nav_enabled;
|
||||
}
|
||||
|
||||
MapWindow::initLayers();
|
||||
}
|
||||
|
||||
void MapWindowSP::offroadTransition(bool offroad) {
|
||||
if (offroad) {
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = false;
|
||||
}
|
||||
|
||||
MapWindow::offroadTransition(offroad);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "selfdrive/ui/qt/maps/map.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
class MapWindowSP : public MapWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapWindowSP(const QMapLibre::Settings &settings) : MapWindow(settings) {}
|
||||
|
||||
private:
|
||||
void initLayers();
|
||||
// Blue with normal nav, green when nav is input into the model
|
||||
QColor getNavPathColor(bool nav_enabled) {
|
||||
return nav_enabled ? QColor("#31ee73") : QColor("#31a1ee");
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void updateState(const UIState &s);
|
||||
|
||||
public slots:
|
||||
void offroadTransition(bool offroad);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
|
||||
#define MAPBOX_TOKEN MAPBOX_TOKEN_SP
|
||||
#define MAPS_HOST MAPS_HOST_SP
|
||||
|
||||
#include "common/params.h"
|
||||
|
||||
const QString MAPBOX_TOKEN = QString::fromStdString(Params().get("CustomMapboxTokenSk")) != "" ?
|
||||
QString::fromStdString(Params().get("CustomMapboxTokenSk")) : 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();
|
||||
Reference in New Issue
Block a user