From ba03e9429044e40477c3b1f38737688f5a24f4b4 Mon Sep 17 00:00:00 2001 From: Mitchell Goff Date: Thu, 20 Jul 2023 00:54:42 -0700 Subject: [PATCH] nav: draw destination pin on top of navigation path (#29050) * Draw destination pin on top of navigation path * fix draw ordering fix draw ordering * add todo * rename to feature * draft * clean up * testing * testing 2 * Revert "testing 2" This reverts commit fc236aafbc14bbdc5ddb52fb56265302247ddf4b. * Revert "testing" This reverts commit 982a508ad701268ebdae910980fd5464454f44a8. * clean up * add todo * show! * Update selfdrive/ui/qt/maps/map.cc * lgtm --------- Co-authored-by: Shane Smiskol --- selfdrive/ui/qt/maps/map.cc | 35 ++++++++++++++++++++++++++++------- selfdrive/ui/qt/maps/map.h | 1 - 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index 02af445e6c..4a313e654c 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -112,7 +112,25 @@ void MapWindow::initLayers() { m_map->setPaintProperty("navLayer", "line-color-transition", transition); m_map->setPaintProperty("navLayer", "line-width", 7.5); m_map->setLayoutProperty("navLayer", "line-cap", "round"); - m_map->addAnnotationIcon("default_marker", QImage("../assets/navigation/default_marker.svg")); + } + if (!m_map->layerExists("pinLayer")) { + qDebug() << "Initializing pinLayer"; + m_map->addImage("default_marker", QImage("../assets/navigation/default_marker.svg")); + QVariantMap pin; + pin["id"] = "pinLayer"; + pin["type"] = "symbol"; + pin["source"] = "pinSource"; + m_map->addLayer(pin); + + // FIXME: solve, workaround to remove animation on visibility property + QVariantMap transition; + transition["duration"] = 0; // ms + m_map->setPaintProperty("pinLayer", "icon-opacity-transition", transition); + m_map->setLayoutProperty("pinLayer", "icon-pitch-alignment", "viewport"); + m_map->setLayoutProperty("pinLayer", "icon-image", "default_marker"); + m_map->setLayoutProperty("pinLayer", "icon-ignore-placement", true); + m_map->setLayoutProperty("pinLayer", "icon-allow-overlap", true); + m_map->setLayoutProperty("pinLayer", "symbol-sort-key", 0); } if (!m_map->layerExists("carPosLayer")) { qDebug() << "Initializing carPosLayer"; @@ -128,6 +146,7 @@ void MapWindow::initLayers() { m_map->setLayoutProperty("carPosLayer", "icon-size", 0.5); m_map->setLayoutProperty("carPosLayer", "icon-ignore-placement", true); m_map->setLayoutProperty("carPosLayer", "icon-allow-overlap", true); + // TODO: remove, symbol-sort-key does not seem to matter outside of each layer m_map->setLayoutProperty("carPosLayer", "symbol-sort-key", 0); } } @@ -381,15 +400,17 @@ void MapWindow::offroadTransition(bool offroad) { } void MapWindow::updateDestinationMarker() { - if (marker_id != -1) { - m_map->removeAnnotation(marker_id); - marker_id = -1; - } + m_map->setPaintProperty("pinLayer", "icon-opacity", 0); auto nav_dest = coordinate_from_param("NavDestination"); if (nav_dest.has_value()) { - auto ano = QMapbox::SymbolAnnotation {*nav_dest, "default_marker"}; - marker_id = m_map->addAnnotation(QVariant::fromValue(ano)); + auto point = coordinate_to_collection(*nav_dest); + QMapbox::Feature feature(QMapbox::Feature::PointType, point, {}, {}); + QVariantMap pinSource; + pinSource["type"] = "geojson"; + pinSource["data"] = QVariant::fromValue(feature); + m_map->updateSource("pinSource", pinSource); + m_map->setPaintProperty("pinLayer", "icon-opacity", 1); } } diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index f2143af7ae..7e3200aef6 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -74,7 +74,6 @@ private: QMapboxGLSettings m_settings; QScopedPointer m_map; - QMapbox::AnnotationID marker_id = -1; void initLayers();