diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp index cabfc88b0..41b90c9f3 100644 --- a/platform/qt/include/qmapboxgl.hpp +++ b/platform/qt/include/qmapboxgl.hpp @@ -48,6 +48,18 @@ class Q_DECL_EXPORT QMapboxGL : public QObject public: typedef QPair Coordinate; + typedef QList Coordinates; + typedef QList CoordinateSegments; + + typedef quint32 AnnotationID; + typedef QList AnnotationIDs; + + typedef QPair PointAnnotation; + typedef QList PointAnnotations; + + // FIXME: We need to add support for custom style properties + typedef QPair ShapeAnnotation; + typedef QList ShapeAnnotations; QMapboxGL(QObject *parent = 0, const QMapboxGLSettings& = QMapboxGLSettings()); virtual ~QMapboxGL(); @@ -94,6 +106,15 @@ public: void setClasses(const QStringList &); QStringList getClasses() const; + AnnotationID addPointAnnotation(const PointAnnotation &); + AnnotationIDs addPointAnnotations(const PointAnnotations &); + + AnnotationID addShapeAnnotation(const ShapeAnnotation &); + AnnotationIDs addShapeAnnotations(const ShapeAnnotations &); + + void removeAnnotation(AnnotationID); + void removeAnnotations(const AnnotationIDs &); + bool isRotating() const; bool isScaling() const; bool isPanning() const; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 3baa68f20..5eca20864 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1,6 +1,7 @@ #include "qmapboxgl_p.hpp" #include +#include #include #include #include @@ -237,6 +238,95 @@ QStringList QMapboxGL::getClasses() const return classNames; } +mbgl::PointAnnotation fromQMapboxGLPointAnnotation(const QMapboxGL::PointAnnotation &pointAnnotation) { + const QMapboxGL::Coordinate &coordinate = pointAnnotation.first; + const QString &icon = pointAnnotation.second; + return { { coordinate.first, coordinate.second }, icon.toUtf8().constData() }; +} + +QMapboxGL::AnnotationID QMapboxGL::addPointAnnotation(const PointAnnotation &pointAnnotation) +{ + return d_ptr->mapObj->addPointAnnotation(fromQMapboxGLPointAnnotation(pointAnnotation)); +} + +QMapboxGL::AnnotationIDs QMapboxGL::addPointAnnotations(const PointAnnotations &pointAnnotations) +{ + std::vector mbglPointAnnotations; + mbglPointAnnotations.reserve(pointAnnotations.size()); + + for (const PointAnnotation &pointAnnotation : pointAnnotations) { + mbglPointAnnotations.emplace_back(fromQMapboxGLPointAnnotation(pointAnnotation)); + } + + AnnotationIDs ids; + for (const mbgl::AnnotationID &id : d_ptr->mapObj->addPointAnnotations(mbglPointAnnotations)) { + ids << id; + } + + return ids; +} + +mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const QMapboxGL::ShapeAnnotation &shapeAnnotation) { + const QMapboxGL::CoordinateSegments &segments = shapeAnnotation.first; + const QString &styleLayer = shapeAnnotation.second; + + mbgl::AnnotationSegments mbglAnnotationSegments; + mbglAnnotationSegments.reserve(segments.size()); + + for (const QMapboxGL::Coordinates &coordinates : segments) { + mbgl::AnnotationSegment mbglAnnotationSegment; + mbglAnnotationSegment.reserve(coordinates.size()); + + for (const QMapboxGL::Coordinate &coordinate : coordinates) { + mbgl::LatLng mbglCoordinate(coordinate.first, coordinate.second); + mbglAnnotationSegment.emplace_back(mbglCoordinate); + } + + mbglAnnotationSegments.emplace_back(mbglAnnotationSegment); + } + + return { mbglAnnotationSegments, styleLayer.toUtf8().constData() }; +} + +QMapboxGL::AnnotationID QMapboxGL::addShapeAnnotation(const ShapeAnnotation &shapeAnnotation) +{ + return d_ptr->mapObj->addShapeAnnotation(fromQMapboxGLShapeAnnotation(shapeAnnotation)); +} + +QMapboxGL::AnnotationIDs QMapboxGL::addShapeAnnotations(const ShapeAnnotations &shapeAnnotations) +{ + std::vector mbglShapeAnnotations; + mbglShapeAnnotations.reserve(shapeAnnotations.size()); + + for (const ShapeAnnotation &shapeAnnotation : shapeAnnotations) { + mbglShapeAnnotations.emplace_back(fromQMapboxGLShapeAnnotation(shapeAnnotation)); + } + + AnnotationIDs ids; + for (const mbgl::AnnotationID &id : d_ptr->mapObj->addShapeAnnotations(mbglShapeAnnotations)) { + ids << id; + } + + return ids; +} + +void QMapboxGL::removeAnnotation(AnnotationID annotationID) +{ + d_ptr->mapObj->removeAnnotation(annotationID); +} + +void QMapboxGL::removeAnnotations(const AnnotationIDs &annotationIDs) +{ + std::vector mbglAnnotationIds; + mbglAnnotationIds.reserve(annotationIDs.size()); + + for (const AnnotationID annotationID : annotationIDs) { + mbglAnnotationIds.emplace_back(annotationID); + } + + d_ptr->mapObj->removeAnnotations(mbglAnnotationIds); +} + bool QMapboxGL::isRotating() const { return d_ptr->mapObj->isRotating();