summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-02-07 14:58:55 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-02-08 15:55:47 +0200
commit59d279b68904bbff0b23012cff327ad69abdb8f0 (patch)
tree2bbf7b4223e9576504fc2f0c7e94f2902e1f8c68 /platform/qt
parent8b9a51135738a1e77ec03444fea8ae7fd8a07e4f (diff)
downloadqtlocation-mapboxgl-59d279b68904bbff0b23012cff327ad69abdb8f0.tar.gz
[Qt] Moved GeoJSON-related conversion functions to qt_geojson.hpp
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/qmapboxgl.cpp76
-rw-r--r--platform/qt/src/qt_conversion.hpp2
-rw-r--r--platform/qt/src/qt_geojson.hpp47
3 files changed, 66 insertions, 59 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 61a71cf24d..eb908b6083 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -836,68 +836,26 @@ void QMapboxGL::setTransitionOptions(qint64 duration, qint64 delay) {
d_ptr->mapObj->setTransitionOptions(mbgl::style::TransitionOptions{ convert(duration), convert(delay) });
}
-mbgl::ShapeAnnotationGeometry asMapboxGLGeometry(const QMapbox::ShapeAnnotationGeometry &geometry) {
- auto asMapboxGLLineString = [&](const QMapbox::Coordinates &lineString) {
- mbgl::LineString<double> mbglLineString;
- mbglLineString.reserve(lineString.size());
- for (const auto &coordinate : lineString) {
- mbglLineString.emplace_back(mbgl::Point<double> { coordinate.second, coordinate.first });
- }
- return mbglLineString;
- };
-
- auto asMapboxGLMultiLineString = [&](const QMapbox::CoordinatesCollection &multiLineString) {
- mbgl::MultiLineString<double> mbglMultiLineString;
- mbglMultiLineString.reserve(multiLineString.size());
- for (const auto &lineString : multiLineString) {
- mbglMultiLineString.emplace_back(std::forward<mbgl::LineString<double>>(asMapboxGLLineString(lineString)));
- }
- return mbglMultiLineString;
- };
-
- auto asMapboxGLPolygon = [&](const QMapbox::CoordinatesCollection &polygon) {
- mbgl::Polygon<double> mbglPolygon;
- mbglPolygon.reserve(polygon.size());
- for (const auto &linearRing : polygon) {
- mbgl::LinearRing<double> mbglLinearRing;
- mbglLinearRing.reserve(linearRing.size());
- for (const auto &coordinate: linearRing) {
- mbglLinearRing.emplace_back(mbgl::Point<double> { coordinate.second, coordinate.first });
- }
- mbglPolygon.emplace_back(std::move(mbglLinearRing));
- }
- return mbglPolygon;
- };
-
- auto asMapboxGLMultiPolygon = [&](const QMapbox::CoordinatesCollections &multiPolygon) {
- mbgl::MultiPolygon<double> mbglMultiPolygon;
- mbglMultiPolygon.reserve(multiPolygon.size());
- for (const auto &polygon : multiPolygon) {
- mbglMultiPolygon.emplace_back(std::forward<mbgl::Polygon<double>>(asMapboxGLPolygon(polygon)));
+mbgl::Annotation asMapboxGLAnnotation(const QMapbox::Annotation & annotation) {
+ auto asMapboxGLGeometry = [](const QMapbox::ShapeAnnotationGeometry &geometry) {
+ mbgl::ShapeAnnotationGeometry result;
+ switch (geometry.type) {
+ case QMapbox::ShapeAnnotationGeometry::LineStringType:
+ result = { asMapboxGLLineString(geometry.geometry.first().first()) };
+ break;
+ case QMapbox::ShapeAnnotationGeometry::PolygonType:
+ result = { asMapboxGLPolygon(geometry.geometry.first()) };
+ break;
+ case QMapbox::ShapeAnnotationGeometry::MultiLineStringType:
+ result = { asMapboxGLMultiLineString(geometry.geometry.first()) };
+ break;
+ case QMapbox::ShapeAnnotationGeometry::MultiPolygonType:
+ result = { asMapboxGLMultiPolygon(geometry.geometry) };
+ break;
}
- return mbglMultiPolygon;
+ return result;
};
- mbgl::ShapeAnnotationGeometry result;
- switch (geometry.type) {
- case QMapbox::ShapeAnnotationGeometry::LineStringType:
- result = { asMapboxGLLineString(geometry.geometry.first().first()) };
- break;
- case QMapbox::ShapeAnnotationGeometry::PolygonType:
- result = { asMapboxGLPolygon(geometry.geometry.first()) };
- break;
- case QMapbox::ShapeAnnotationGeometry::MultiLineStringType:
- result = { asMapboxGLMultiLineString(geometry.geometry.first()) };
- break;
- case QMapbox::ShapeAnnotationGeometry::MultiPolygonType:
- result = { asMapboxGLMultiPolygon(geometry.geometry) };
- break;
- }
-
- return result;
-}
-
-mbgl::Annotation asMapboxGLAnnotation(const QMapbox::Annotation & annotation) {
if (annotation.canConvert<QMapbox::SymbolAnnotation>()) {
QMapbox::SymbolAnnotation symbolAnnotation = annotation.value<QMapbox::SymbolAnnotation>();
QMapbox::Coordinate& pair = symbolAnnotation.geometry;
diff --git a/platform/qt/src/qt_conversion.hpp b/platform/qt/src/qt_conversion.hpp
index e49b6dbe3e..ae05200d66 100644
--- a/platform/qt/src/qt_conversion.hpp
+++ b/platform/qt/src/qt_conversion.hpp
@@ -4,6 +4,8 @@
#include <mbgl/util/feature.hpp>
#include <mbgl/util/optional.hpp>
+#include <QMapbox>
+
#include <QColor>
#include <QVariant>
diff --git a/platform/qt/src/qt_geojson.hpp b/platform/qt/src/qt_geojson.hpp
index 07813623fd..f01db51bf7 100644
--- a/platform/qt/src/qt_geojson.hpp
+++ b/platform/qt/src/qt_geojson.hpp
@@ -4,12 +4,59 @@
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/util/rapidjson.hpp>
+#include <QMapbox>
+
#include <QByteArray>
#include <QVariant>
#include <sstream>
#include <string>
+namespace QMapbox {
+
+mbgl::LineString<double> asMapboxGLLineString(const QMapbox::Coordinates &lineString) {
+ mbgl::LineString<double> mbglLineString;
+ mbglLineString.reserve(lineString.size());
+ for (const auto &coordinate : lineString) {
+ mbglLineString.emplace_back(mbgl::Point<double> { coordinate.second, coordinate.first });
+ }
+ return mbglLineString;
+};
+
+mbgl::MultiLineString<double> asMapboxGLMultiLineString(const QMapbox::CoordinatesCollection &multiLineString) {
+ mbgl::MultiLineString<double> mbglMultiLineString;
+ mbglMultiLineString.reserve(multiLineString.size());
+ for (const auto &lineString : multiLineString) {
+ mbglMultiLineString.emplace_back(std::forward<mbgl::LineString<double>>(asMapboxGLLineString(lineString)));
+ }
+ return mbglMultiLineString;
+};
+
+mbgl::Polygon<double> asMapboxGLPolygon(const QMapbox::CoordinatesCollection &polygon) {
+ mbgl::Polygon<double> mbglPolygon;
+ mbglPolygon.reserve(polygon.size());
+ for (const auto &linearRing : polygon) {
+ mbgl::LinearRing<double> mbglLinearRing;
+ mbglLinearRing.reserve(linearRing.size());
+ for (const auto &coordinate: linearRing) {
+ mbglLinearRing.emplace_back(mbgl::Point<double> { coordinate.second, coordinate.first });
+ }
+ mbglPolygon.emplace_back(std::move(mbglLinearRing));
+ }
+ return mbglPolygon;
+};
+
+mbgl::MultiPolygon<double> asMapboxGLMultiPolygon(const QMapbox::CoordinatesCollections &multiPolygon) {
+ mbgl::MultiPolygon<double> mbglMultiPolygon;
+ mbglMultiPolygon.reserve(multiPolygon.size());
+ for (const auto &polygon : multiPolygon) {
+ mbglMultiPolygon.emplace_back(std::forward<mbgl::Polygon<double>>(asMapboxGLPolygon(polygon)));
+ }
+ return mbglMultiPolygon;
+};
+
+} // namespace QMapbox
+
namespace mbgl {
namespace style {
namespace conversion {