diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2015-10-22 19:04:35 -0700 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-04-20 20:55:51 +0300 |
commit | 0e6cc4006f77184f93a9cf180779b2e87b7a699b (patch) | |
tree | 1521df72491583e1ebfb2f71c37c4102c9b8bc4f /platform | |
parent | 814a12a63c3683996c78a9b7d2ca638a72ecda55 (diff) | |
download | qtlocation-mapboxgl-0e6cc4006f77184f93a9cf180779b2e87b7a699b.tar.gz |
[Qt] Forward annotations functions
Support for custom style properties in shape annotations will be
implemented in the future.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/qt/include/qmapboxgl.hpp | 21 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 90 |
2 files changed, 111 insertions, 0 deletions
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp index cabfc88b0b..41b90c9f3a 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<double, double> Coordinate; + typedef QList<Coordinate> Coordinates; + typedef QList<Coordinates> CoordinateSegments; + + typedef quint32 AnnotationID; + typedef QList<AnnotationID> AnnotationIDs; + + typedef QPair<Coordinate, QString> PointAnnotation; + typedef QList<PointAnnotation> PointAnnotations; + + // FIXME: We need to add support for custom style properties + typedef QPair<CoordinateSegments, QString> ShapeAnnotation; + typedef QList<ShapeAnnotation> 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 3baa68f201..5eca208640 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1,6 +1,7 @@ #include "qmapboxgl_p.hpp" #include <mbgl/annotation/point_annotation.hpp> +#include <mbgl/annotation/shape_annotation.hpp> #include <mbgl/gl/gl.hpp> #include <mbgl/map/map.hpp> #include <mbgl/sprite/sprite_image.hpp> @@ -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<mbgl::PointAnnotation> 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<mbgl::ShapeAnnotation> 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<mbgl::AnnotationID> 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(); |