mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-06 21:32:08 +08:00
Added updateZoom function to map_renderer, plus custom style.json (#25997)
* Added updateZoom function to map_renderer, plus custom style.json * Render 512x512 maps * Define STYLE_PATH in navd sconscript
This commit is contained in:
@@ -11,6 +11,8 @@ if arch in ['larch64', 'x86_64']:
|
||||
rpath = [Dir(f"#third_party/mapbox-gl-native-qt/{arch}").srcnode().abspath]
|
||||
qt_env["RPATH"] += rpath
|
||||
|
||||
style_path = File("style.json").abspath
|
||||
qt_env['CXXFLAGS'].append(f'-DSTYLE_PATH=\\"{style_path}\\"')
|
||||
qt_libs = ["qt_widgets", "qt_util", "qmapboxgl"] + base_libs
|
||||
|
||||
nav_src = ["main.cc", "map_renderer.cc"]
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#include "selfdrive/navd/map_renderer.h"
|
||||
|
||||
#include <string>
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/timing.h"
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
|
||||
const float ZOOM = 13.5; // Don't go below 13 or features will start to disappear
|
||||
const int WIDTH = 256;
|
||||
const float DEFAULT_ZOOM = 13.5; // Don't go below 13 or features will start to disappear
|
||||
const int WIDTH = 512;
|
||||
const int HEIGHT = WIDTH;
|
||||
|
||||
const int NUM_VIPC_BUFFERS = 4;
|
||||
@@ -35,9 +37,10 @@ MapRenderer::MapRenderer(const QMapboxGLSettings &settings, bool online) : m_set
|
||||
QOpenGLFramebufferObjectFormat fbo_format;
|
||||
fbo.reset(new QOpenGLFramebufferObject(WIDTH, HEIGHT, fbo_format));
|
||||
|
||||
std::string style = util::read_file(STYLE_PATH);
|
||||
m_map.reset(new QMapboxGL(nullptr, m_settings, fbo->size(), 1));
|
||||
m_map->setCoordinateZoom(QMapbox::Coordinate(0, 0), ZOOM);
|
||||
m_map->setStyleUrl("mapbox://styles/commaai/ckvmksrpd4n0a14pfdo5heqzr");
|
||||
m_map->setCoordinateZoom(QMapbox::Coordinate(0, 0), DEFAULT_ZOOM);
|
||||
m_map->setStyleJson(style.c_str());
|
||||
m_map->createRenderer();
|
||||
|
||||
m_map->resize(fbo->size());
|
||||
@@ -82,6 +85,15 @@ void MapRenderer::msgUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
void MapRenderer::updateZoom(float zoom) {
|
||||
if (m_map.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_map->setZoom(zoom);
|
||||
update();
|
||||
}
|
||||
|
||||
void MapRenderer::updatePosition(QMapbox::Coordinate position, float bearing) {
|
||||
if (m_map.isNull()) {
|
||||
return;
|
||||
@@ -185,7 +197,7 @@ void MapRenderer::initLayers() {
|
||||
nav["source"] = "navSource";
|
||||
m_map->addLayer(nav, "road-intersection");
|
||||
m_map->setPaintProperty("navLayer", "line-color", QColor("grey"));
|
||||
m_map->setPaintProperty("navLayer", "line-width", 3);
|
||||
m_map->setPaintProperty("navLayer", "line-width", 5);
|
||||
m_map->setLayoutProperty("navLayer", "line-cap", "round");
|
||||
}
|
||||
}
|
||||
@@ -210,6 +222,11 @@ extern "C" {
|
||||
return new MapRenderer(settings, false);
|
||||
}
|
||||
|
||||
void map_renderer_update_zoom(MapRenderer *inst, float zoom) {
|
||||
inst->updateZoom(zoom);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void map_renderer_update_position(MapRenderer *inst, float lat, float lon, float bearing) {
|
||||
inst->updatePosition({lat, lon}, bearing);
|
||||
QApplication::processEvents();
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
QTimer* timer;
|
||||
|
||||
public slots:
|
||||
void updateZoom(float zoom);
|
||||
void updatePosition(QMapbox::Coordinate position, float bearing);
|
||||
void updateRoute(QList<QGeoCoordinate> coordinates);
|
||||
void msgUpdate();
|
||||
|
||||
@@ -9,7 +9,7 @@ from cffi import FFI
|
||||
from common.ffi_wrapper import suffix
|
||||
from common.basedir import BASEDIR
|
||||
|
||||
HEIGHT = WIDTH = 256
|
||||
HEIGHT = WIDTH = 512
|
||||
|
||||
|
||||
def get_ffi():
|
||||
@@ -18,6 +18,7 @@ def get_ffi():
|
||||
ffi = FFI()
|
||||
ffi.cdef("""
|
||||
void* map_renderer_init(char *maps_host, char *token);
|
||||
void map_renderer_update_zoom(void *inst, float zoom);
|
||||
void map_renderer_update_position(void *inst, float lat, float lon, float bearing);
|
||||
void map_renderer_update_route(void *inst, char *polyline);
|
||||
void map_renderer_update(void *inst);
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user