summaryrefslogtreecommitdiff
path: root/platform/qt/app/mapwindow.cpp
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-01-24 18:05:22 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-01-26 14:53:45 +0200
commitbe43310b6ff5465e6717128b577f6e61c0335c44 (patch)
tree330ba9aa8c9a1af84e9d504301c9d716fafe53b6 /platform/qt/app/mapwindow.cpp
parentfb759e949fc6381b92eb2149cbea1db3e282de4b (diff)
downloadqtlocation-mapboxgl-be43310b6ff5465e6717128b577f6e61c0335c44.tar.gz
[Qt] Refactor QMapbox Annotations API
Diffstat (limited to 'platform/qt/app/mapwindow.cpp')
-rw-r--r--platform/qt/app/mapwindow.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index 0b453406f3..3e6a14736f 100644
--- a/platform/qt/app/mapwindow.cpp
+++ b/platform/qt/app/mapwindow.cpp
@@ -203,6 +203,61 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
m_map->setLayoutProperty("road-label-small", "text-size", 30.0);
}
break;
+ case Qt::Key_1: {
+ if (m_symbolAnnotationId.isNull()) {
+ QMapbox::Coordinate coordinate = m_map->coordinate();
+ QMapbox::SymbolAnnotation symbol { coordinate, "default_marker" };
+ m_map->addAnnotationIcon("default_marker", QImage(":default_marker.svg"));
+ m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::SymbolAnnotation>(symbol));
+ } else {
+ m_map->removeAnnotation(m_symbolAnnotationId.toUInt());
+ m_symbolAnnotationId.clear();
+ }
+ }
+ break;
+ case Qt::Key_2: {
+ if (m_lineAnnotationId.isNull()) {
+ QMapbox::Coordinate topLeft = m_map->coordinateForPixel({ 0, 0 });
+ QMapbox::Coordinate bottomRight = m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) });
+ QMapbox::CoordinatesCollections geometry { { { topLeft, bottomRight } } };
+ QMapbox::LineAnnotation line { { QMapbox::ShapeAnnotationGeometry::Type::LineStringType, geometry }, 0.5f, 1.0f, Qt::red };
+ m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::LineAnnotation>(line));
+ } else {
+ m_map->removeAnnotation(m_lineAnnotationId.toUInt());
+ m_lineAnnotationId.clear();
+ }
+ }
+ break;
+ case Qt::Key_3: {
+ if (m_fillAnnotationId.isNull()) {
+ QMapbox::Coordinate topLeft = m_map->coordinateForPixel({ 0, 0 });
+ QMapbox::Coordinate topRight = m_map->coordinateForPixel({ 0, qreal(size().height()) });
+ QMapbox::Coordinate bottomLeft = m_map->coordinateForPixel({ qreal(size().width()), 0 });
+ QMapbox::Coordinate bottomRight = m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) });
+ QMapbox::CoordinatesCollections geometry { { { bottomLeft, bottomRight, topRight, topLeft, bottomLeft } } };
+ QMapbox::FillAnnotation fill { { QMapbox::ShapeAnnotationGeometry::Type::PolygonType, geometry }, 0.5f, Qt::green, QVariant::fromValue<QColor>(QColor(Qt::black)) };
+ m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::FillAnnotation>(fill));
+ } else {
+ m_map->removeAnnotation(m_fillAnnotationId.toUInt());
+ m_fillAnnotationId.clear();
+ }
+ }
+ break;
+ case Qt::Key_4: {
+ if (m_styleSourcedAnnotationId.isNull()) {
+ QMapbox::Coordinate topLeft = m_map->coordinateForPixel({ 0, 0 });
+ QMapbox::Coordinate topRight = m_map->coordinateForPixel({ 0, qreal(size().height()) });
+ QMapbox::Coordinate bottomLeft = m_map->coordinateForPixel({ qreal(size().width()), 0 });
+ QMapbox::Coordinate bottomRight = m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) });
+ QMapbox::CoordinatesCollections geometry { { { bottomLeft, bottomRight, topRight, topLeft, bottomLeft } } };
+ QMapbox::StyleSourcedAnnotation styleSourced { { QMapbox::ShapeAnnotationGeometry::Type::PolygonType, geometry }, "water" };
+ m_styleSourcedAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::StyleSourcedAnnotation>(styleSourced));
+ } else {
+ m_map->removeAnnotation(m_styleSourcedAnnotationId.toUInt());
+ m_styleSourcedAnnotationId.clear();
+ }
+ }
+ break;
case Qt::Key_Tab:
m_map->cycleDebugOptions();
break;