Mapbox widget (#20751)
* squash mapbox stuff * only hacks for pc * no hack there * only update when needed * get destination from param * no need for user agent * add athena method * change nav path color * layout cleanups * margin top * add build scripts * rename header file * set pitch * fix icon blinking * keep both options * draw on top to fix last blinking * only recomput with gps * fix include * put map in onroadwidget * update mapbox plugin to allow specifying directions url * cycle through views * dynamic resize * only when present * add map_helpers * whitespace * small fixes * let scons decide * update setup files * implicit dependency * fix alerts * Update selfdrive/ui/SConscript * move clearLayout to util.h * only build when map.cc present * move maps to own folder Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>pull/20930/head
@ -0,0 +1,2 @@ |
||||
x86_64 filter=lfs diff=lfs merge=lfs -text |
||||
larch64 filter=lfs diff=lfs merge=lfs -text |
@ -0,0 +1,7 @@ |
||||
#!/usr/bin/env sh |
||||
cd /tmp |
||||
git clone --recursive https://github.com/commaai/mapbox-gl-native.git |
||||
cd mapbox-gl-native |
||||
mkdir build && cd build |
||||
cmake -DMBGL_WITH_QT=ON .. |
||||
make -j$(nproc) mbgl-qt |
@ -0,0 +1 @@ |
||||
#include "qmapbox.hpp" |
@ -0,0 +1 @@ |
||||
#include "qmapboxgl.hpp" |
@ -0,0 +1,147 @@ |
||||
#ifndef QMAPBOX_H |
||||
#define QMAPBOX_H |
||||
|
||||
#include <QColor> |
||||
#include <QPair> |
||||
#include <QString> |
||||
#include <QVariant> |
||||
#include <QVector> |
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
#if !defined(QT_MAPBOXGL_STATIC) |
||||
# if defined(QT_BUILD_MAPBOXGL_LIB) |
||||
# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT |
||||
# else |
||||
# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT |
||||
# endif |
||||
#else |
||||
# define Q_MAPBOXGL_EXPORT |
||||
#endif |
||||
|
||||
namespace QMapbox { |
||||
|
||||
typedef QPair<double, double> Coordinate; |
||||
typedef QPair<Coordinate, double> CoordinateZoom; |
||||
typedef QPair<double, double> ProjectedMeters; |
||||
|
||||
typedef QVector<Coordinate> Coordinates; |
||||
typedef QVector<Coordinates> CoordinatesCollection; |
||||
|
||||
typedef QVector<CoordinatesCollection> CoordinatesCollections; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT Feature { |
||||
enum Type { |
||||
PointType = 1, |
||||
LineStringType, |
||||
PolygonType |
||||
}; |
||||
|
||||
/*! Class constructor. */ |
||||
Feature(Type type_ = PointType, const CoordinatesCollections& geometry_ = CoordinatesCollections(), |
||||
const QVariantMap& properties_ = QVariantMap(), const QVariant& id_ = QVariant()) |
||||
: type(type_), geometry(geometry_), properties(properties_), id(id_) {} |
||||
|
||||
Type type; |
||||
CoordinatesCollections geometry; |
||||
QVariantMap properties; |
||||
QVariant id; |
||||
}; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT ShapeAnnotationGeometry { |
||||
enum Type { |
||||
LineStringType = 1, |
||||
PolygonType, |
||||
MultiLineStringType, |
||||
MultiPolygonType |
||||
}; |
||||
|
||||
/*! Class constructor. */ |
||||
ShapeAnnotationGeometry(Type type_ = LineStringType, const CoordinatesCollections& geometry_ = CoordinatesCollections()) |
||||
: type(type_), geometry(geometry_) {} |
||||
|
||||
Type type; |
||||
CoordinatesCollections geometry; |
||||
}; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT SymbolAnnotation { |
||||
Coordinate geometry; |
||||
QString icon; |
||||
}; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT LineAnnotation { |
||||
/*! Class constructor. */ |
||||
LineAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), float opacity_ = 1.0f, |
||||
float width_ = 1.0f, const QColor& color_ = Qt::black) |
||||
: geometry(geometry_), opacity(opacity_), width(width_), color(color_) {} |
||||
|
||||
ShapeAnnotationGeometry geometry; |
||||
float opacity; |
||||
float width; |
||||
QColor color; |
||||
}; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT FillAnnotation { |
||||
/*! Class constructor. */ |
||||
FillAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), float opacity_ = 1.0f, |
||||
const QColor& color_ = Qt::black, const QVariant& outlineColor_ = QVariant()) |
||||
: geometry(geometry_), opacity(opacity_), color(color_), outlineColor(outlineColor_) {} |
||||
|
||||
ShapeAnnotationGeometry geometry; |
||||
float opacity; |
||||
QColor color; |
||||
QVariant outlineColor; |
||||
}; |
||||
|
||||
typedef QVariant Annotation; |
||||
typedef quint32 AnnotationID; |
||||
typedef QVector<AnnotationID> AnnotationIDs; |
||||
|
||||
enum NetworkMode { |
||||
Online, // Default
|
||||
Offline, |
||||
}; |
||||
|
||||
Q_MAPBOXGL_EXPORT QVector<QPair<QString, QString> >& defaultStyles(); |
||||
|
||||
Q_MAPBOXGL_EXPORT NetworkMode networkMode(); |
||||
Q_MAPBOXGL_EXPORT void setNetworkMode(NetworkMode); |
||||
|
||||
// This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters.
|
||||
struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters { |
||||
double width; |
||||
double height; |
||||
double latitude; |
||||
double longitude; |
||||
double zoom; |
||||
double bearing; |
||||
double pitch; |
||||
double fieldOfView; |
||||
}; |
||||
|
||||
class Q_MAPBOXGL_EXPORT CustomLayerHostInterface { |
||||
public: |
||||
virtual ~CustomLayerHostInterface() = default; |
||||
virtual void initialize() = 0; |
||||
virtual void render(const CustomLayerRenderParameters&) = 0; |
||||
virtual void deinitialize() = 0; |
||||
}; |
||||
|
||||
Q_MAPBOXGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom); |
||||
Q_MAPBOXGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &); |
||||
Q_MAPBOXGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &); |
||||
|
||||
} // namespace QMapbox
|
||||
|
||||
Q_DECLARE_METATYPE(QMapbox::Coordinate); |
||||
Q_DECLARE_METATYPE(QMapbox::Coordinates); |
||||
Q_DECLARE_METATYPE(QMapbox::CoordinatesCollection); |
||||
Q_DECLARE_METATYPE(QMapbox::CoordinatesCollections); |
||||
Q_DECLARE_METATYPE(QMapbox::Feature); |
||||
|
||||
Q_DECLARE_METATYPE(QMapbox::SymbolAnnotation); |
||||
Q_DECLARE_METATYPE(QMapbox::ShapeAnnotationGeometry); |
||||
Q_DECLARE_METATYPE(QMapbox::LineAnnotation); |
||||
Q_DECLARE_METATYPE(QMapbox::FillAnnotation); |
||||
|
||||
#endif // QMAPBOX_H
|
@ -0,0 +1,277 @@ |
||||
#ifndef QMAPBOXGL_H |
||||
#define QMAPBOXGL_H |
||||
|
||||
#include <QImage> |
||||
#include <QMapbox> |
||||
#include <QMargins> |
||||
#include <QObject> |
||||
#include <QPointF> |
||||
#include <QSize> |
||||
#include <QString> |
||||
#include <QStringList> |
||||
|
||||
#include <functional> |
||||
|
||||
class QMapboxGLPrivate; |
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
class Q_MAPBOXGL_EXPORT QMapboxGLSettings |
||||
{ |
||||
public: |
||||
QMapboxGLSettings(); |
||||
|
||||
enum GLContextMode { |
||||
UniqueGLContext = 0, |
||||
SharedGLContext |
||||
}; |
||||
|
||||
enum MapMode { |
||||
Continuous = 0, |
||||
Static |
||||
}; |
||||
|
||||
enum ConstrainMode { |
||||
NoConstrain = 0, |
||||
ConstrainHeightOnly, |
||||
ConstrainWidthAndHeight |
||||
}; |
||||
|
||||
enum ViewportMode { |
||||
DefaultViewport = 0, |
||||
FlippedYViewport |
||||
}; |
||||
|
||||
GLContextMode contextMode() const; |
||||
void setContextMode(GLContextMode); |
||||
|
||||
MapMode mapMode() const; |
||||
void setMapMode(MapMode); |
||||
|
||||
ConstrainMode constrainMode() const; |
||||
void setConstrainMode(ConstrainMode); |
||||
|
||||
ViewportMode viewportMode() const; |
||||
void setViewportMode(ViewportMode); |
||||
|
||||
unsigned cacheDatabaseMaximumSize() const; |
||||
void setCacheDatabaseMaximumSize(unsigned); |
||||
|
||||
QString cacheDatabasePath() const; |
||||
void setCacheDatabasePath(const QString &); |
||||
|
||||
QString assetPath() const; |
||||
void setAssetPath(const QString &); |
||||
|
||||
QString accessToken() const; |
||||
void setAccessToken(const QString &); |
||||
|
||||
QString apiBaseUrl() const; |
||||
void setApiBaseUrl(const QString &); |
||||
|
||||
QString localFontFamily() const; |
||||
void setLocalFontFamily(const QString &); |
||||
|
||||
std::function<std::string(const std::string &)> resourceTransform() const; |
||||
void setResourceTransform(const std::function<std::string(const std::string &)> &); |
||||
|
||||
private: |
||||
GLContextMode m_contextMode; |
||||
MapMode m_mapMode; |
||||
ConstrainMode m_constrainMode; |
||||
ViewportMode m_viewportMode; |
||||
|
||||
unsigned m_cacheMaximumSize; |
||||
QString m_cacheDatabasePath; |
||||
QString m_assetPath; |
||||
QString m_accessToken; |
||||
QString m_apiBaseUrl; |
||||
QString m_localFontFamily; |
||||
std::function<std::string(const std::string &)> m_resourceTransform; |
||||
}; |
||||
|
||||
struct Q_MAPBOXGL_EXPORT QMapboxGLCameraOptions { |
||||
QVariant center; // Coordinate
|
||||
QVariant anchor; // QPointF
|
||||
QVariant zoom; // double
|
||||
QVariant bearing; // double
|
||||
QVariant pitch; // double
|
||||
}; |
||||
|
||||
class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
Q_PROPERTY(double latitude READ latitude WRITE setLatitude) |
||||
Q_PROPERTY(double longitude READ longitude WRITE setLongitude) |
||||
Q_PROPERTY(double zoom READ zoom WRITE setZoom) |
||||
Q_PROPERTY(double bearing READ bearing WRITE setBearing) |
||||
Q_PROPERTY(double pitch READ pitch WRITE setPitch) |
||||
Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson) |
||||
Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl) |
||||
Q_PROPERTY(double scale READ scale WRITE setScale) |
||||
Q_PROPERTY(QMapbox::Coordinate coordinate READ coordinate WRITE setCoordinate) |
||||
Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
||||
|
||||
public: |
||||
enum MapChange { |
||||
MapChangeRegionWillChange = 0, |
||||
MapChangeRegionWillChangeAnimated, |
||||
MapChangeRegionIsChanging, |
||||
MapChangeRegionDidChange, |
||||
MapChangeRegionDidChangeAnimated, |
||||
MapChangeWillStartLoadingMap, |
||||
MapChangeDidFinishLoadingMap, |
||||
MapChangeDidFailLoadingMap, |
||||
MapChangeWillStartRenderingFrame, |
||||
MapChangeDidFinishRenderingFrame, |
||||
MapChangeDidFinishRenderingFrameFullyRendered, |
||||
MapChangeWillStartRenderingMap, |
||||
MapChangeDidFinishRenderingMap, |
||||
MapChangeDidFinishRenderingMapFullyRendered, |
||||
MapChangeDidFinishLoadingStyle, |
||||
MapChangeSourceDidChange |
||||
}; |
||||
|
||||
enum MapLoadingFailure { |
||||
StyleParseFailure, |
||||
StyleLoadFailure, |
||||
NotFoundFailure, |
||||
UnknownFailure |
||||
}; |
||||
|
||||
// Determines the orientation of the map.
|
||||
enum NorthOrientation { |
||||
NorthUpwards, // Default
|
||||
NorthRightwards, |
||||
NorthDownwards, |
||||
NorthLeftwards, |
||||
}; |
||||
|
||||
QMapboxGL(QObject* parent = 0, |
||||
const QMapboxGLSettings& = QMapboxGLSettings(), |
||||
const QSize& size = QSize(), |
||||
qreal pixelRatio = 1); |
||||
virtual ~QMapboxGL(); |
||||
|
||||
QString styleJson() const; |
||||
QString styleUrl() const; |
||||
|
||||
void setStyleJson(const QString &); |
||||
void setStyleUrl(const QString &); |
||||
|
||||
double latitude() const; |
||||
void setLatitude(double latitude); |
||||
|
||||
double longitude() const; |
||||
void setLongitude(double longitude); |
||||
|
||||
double scale() const; |
||||
void setScale(double scale, const QPointF ¢er = QPointF()); |
||||
|
||||
double zoom() const; |
||||
void setZoom(double zoom); |
||||
|
||||
double minimumZoom() const; |
||||
double maximumZoom() const; |
||||
|
||||
double bearing() const; |
||||
void setBearing(double degrees); |
||||
void setBearing(double degrees, const QPointF ¢er); |
||||
|
||||
double pitch() const; |
||||
void setPitch(double pitch); |
||||
void pitchBy(double pitch); |
||||
|
||||
NorthOrientation northOrientation() const; |
||||
void setNorthOrientation(NorthOrientation); |
||||
|
||||
QMapbox::Coordinate coordinate() const; |
||||
void setCoordinate(const QMapbox::Coordinate &); |
||||
void setCoordinateZoom(const QMapbox::Coordinate &, double zoom); |
||||
|
||||
void jumpTo(const QMapboxGLCameraOptions&); |
||||
|
||||
void setGestureInProgress(bool inProgress); |
||||
|
||||
void setTransitionOptions(qint64 duration, qint64 delay = 0); |
||||
|
||||
void addAnnotationIcon(const QString &name, const QImage &sprite); |
||||
|
||||
QMapbox::AnnotationID addAnnotation(const QMapbox::Annotation &); |
||||
void updateAnnotation(QMapbox::AnnotationID, const QMapbox::Annotation &); |
||||
void removeAnnotation(QMapbox::AnnotationID); |
||||
|
||||
bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value); |
||||
bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value); |
||||
|
||||
bool isFullyLoaded() const; |
||||
|
||||
void moveBy(const QPointF &offset); |
||||
void scaleBy(double scale, const QPointF ¢er = QPointF()); |
||||
void rotateBy(const QPointF &first, const QPointF &second); |
||||
|
||||
void resize(const QSize &size); |
||||
|
||||
double metersPerPixelAtLatitude(double latitude, double zoom) const; |
||||
QMapbox::ProjectedMeters projectedMetersForCoordinate(const QMapbox::Coordinate &) const; |
||||
QMapbox::Coordinate coordinateForProjectedMeters(const QMapbox::ProjectedMeters &) const; |
||||
QPointF pixelForCoordinate(const QMapbox::Coordinate &) const; |
||||
QMapbox::Coordinate coordinateForPixel(const QPointF &) const; |
||||
|
||||
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne) const; |
||||
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne, double bearing, double pitch); |
||||
|
||||
void setMargins(const QMargins &margins); |
||||
QMargins margins() const; |
||||
|
||||
void addSource(const QString &sourceID, const QVariantMap& params); |
||||
bool sourceExists(const QString &sourceID); |
||||
void updateSource(const QString &sourceID, const QVariantMap& params); |
||||
void removeSource(const QString &sourceID); |
||||
|
||||
void addImage(const QString &name, const QImage &sprite); |
||||
void removeImage(const QString &name); |
||||
|
||||
void addCustomLayer(const QString &id, |
||||
QScopedPointer<QMapbox::CustomLayerHostInterface>& host, |
||||
const QString& before = QString()); |
||||
void addLayer(const QVariantMap ¶ms, const QString& before = QString()); |
||||
bool layerExists(const QString &id); |
||||
void removeLayer(const QString &id); |
||||
|
||||
QVector<QString> layerIds() const; |
||||
|
||||
void setFilter(const QString &layer, const QVariant &filter); |
||||
QVariant getFilter(const QString &layer) const; |
||||
// When rendering on a different thread,
|
||||
// should be called on the render thread.
|
||||
void createRenderer(); |
||||
void destroyRenderer(); |
||||
void setFramebufferObject(quint32 fbo, const QSize &size); |
||||
|
||||
public slots: |
||||
void render(); |
||||
void connectionEstablished(); |
||||
|
||||
// Commit changes, load all the resources
|
||||
// and renders the map when completed.
|
||||
void startStaticRender(); |
||||
|
||||
signals: |
||||
void needsRendering(); |
||||
void mapChanged(QMapboxGL::MapChange); |
||||
void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason); |
||||
void copyrightsChanged(const QString ©rightsHtml); |
||||
|
||||
void staticRenderFinished(const QString &error); |
||||
|
||||
private: |
||||
Q_DISABLE_COPY(QMapboxGL) |
||||
|
||||
QMapboxGLPrivate *d_ptr; |
||||
}; |
||||
|
||||
Q_DECLARE_METATYPE(QMapboxGL::MapChange); |
||||
Q_DECLARE_METATYPE(QMapboxGL::MapLoadingFailure); |
||||
|
||||
#endif // QMAPBOXGL_H
|
@ -0,0 +1 @@ |
||||
x86_64 filter=lfs diff=lfs merge=lfs -text |
@ -0,0 +1,8 @@ |
||||
#!/usr/bin/env sh |
||||
|
||||
# Qtlocation plugin with extra fields parsed from api response |
||||
cd /tmp |
||||
git clone https://github.com/commaai/qtlocation.git |
||||
cd qtlocation |
||||
qmake |
||||
make -j$(nproc) |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 865 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 658 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 113 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.7 KiB |