summaryrefslogtreecommitdiff
path: root/include/mbgl/style
diff options
context:
space:
mode:
authorIvo van Dongen <ivovandongen@users.noreply.github.com>2016-08-23 14:57:55 +0200
committerGitHub <noreply@github.com>2016-08-23 14:57:55 +0200
commitdf3b44531e1c2a95edd2a035d3744f34ebb8d0e9 (patch)
tree2eb0ae3e4a3b793767643831cd8063aeab56075d /include/mbgl/style
parent50da6e5e715f0356f430fba176dea13d15fe9d52 (diff)
downloadqtlocation-mapboxgl-df3b44531e1c2a95edd2a035d3744f34ebb8d0e9.tar.gz
[core] #6071 - extract GeoJSONOptions conversion from GeoJSONSource conversion
* [core] geojson_options - retain original error message * [core] tests - initial style conversion stub methods * [core] geojsonoptions conversion - initial unit tests * [core] tests - fix forward reference issue * [core] geojsonoptions conversion - unit tests * [core] geojsonoptions conversion - renamed Holder to Value
Diffstat (limited to 'include/mbgl/style')
-rw-r--r--include/mbgl/style/conversion/geojson_options.hpp78
-rw-r--r--include/mbgl/style/conversion/source.hpp60
2 files changed, 83 insertions, 55 deletions
diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp
new file mode 100644
index 0000000000..880090b402
--- /dev/null
+++ b/include/mbgl/style/conversion/geojson_options.hpp
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/sources/geojson_source.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <>
+struct Converter<GeoJSONOptions> {
+
+ template <class V>
+ Result<GeoJSONOptions> operator()(const V& value) const {
+ GeoJSONOptions options;
+
+ const auto maxzoomValue = objectMember(value, "maxzoom");
+ if (maxzoomValue) {
+ if (toNumber(*maxzoomValue)) {
+ options.maxzoom = static_cast<uint8_t>(*toNumber(*maxzoomValue));
+ } else {
+ return Error{ "GeoJSON source maxzoom value must be a number" };
+ }
+ }
+
+ const auto bufferValue = objectMember(value, "buffer");
+ if (bufferValue) {
+ if (toNumber(*bufferValue)) {
+ options.buffer = static_cast<uint16_t>(*toNumber(*bufferValue));
+ } else {
+ return Error{ "GeoJSON source buffer value must be a number" };
+ }
+ }
+
+ const auto toleranceValue = objectMember(value, "tolerance");
+ if (toleranceValue) {
+ if (toNumber(*toleranceValue)) {
+ options.tolerance = static_cast<double>(*toNumber(*toleranceValue));
+ } else {
+ return Error{ "GeoJSON source tolerance value must be a number" };
+ }
+ }
+
+ const auto clusterValue = objectMember(value, "cluster");
+ if (clusterValue) {
+ if (toBool(*clusterValue)) {
+ options.cluster = *toBool(*clusterValue);
+ } else {
+ return Error{ "GeoJSON source cluster value must be a boolean" };
+ }
+ }
+
+ const auto clusterMaxZoomValue = objectMember(value, "clusterMaxZoom");
+ if (clusterMaxZoomValue) {
+ if (toNumber(*clusterMaxZoomValue)) {
+ options.clusterMaxZoom = static_cast<uint8_t>(*toNumber(*clusterMaxZoomValue));
+ } else {
+ return Error{ "GeoJSON source clusterMaxZoom value must be a number" };
+ }
+ }
+
+ const auto clusterRadiusValue = objectMember(value, "clusterRadius");
+ if (clusterRadiusValue) {
+ if (toNumber(*clusterRadiusValue)) {
+ options.clusterRadius = static_cast<double>(*toNumber(*clusterRadiusValue));
+ } else {
+ return Error{ "GeoJSON source clusterRadius value must be a number" };
+ }
+ }
+
+ return { options };
+ }
+
+};
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp
index c4b2fe303f..6e1b4347c3 100644
--- a/include/mbgl/style/conversion/source.hpp
+++ b/include/mbgl/style/conversion/source.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/geojson.hpp>
+#include <mbgl/style/conversion/geojson_options.hpp>
#include <mbgl/style/conversion/tileset.hpp>
#include <mbgl/style/source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
@@ -103,63 +104,12 @@ private:
return Error{ "GeoJSON source must have a data value" };
}
- GeoJSONOptions options;
-
- const auto maxzoomValue = objectMember(value, "maxzoom");
- if (maxzoomValue) {
- if (toNumber(*maxzoomValue)) {
- options.maxzoom = static_cast<uint8_t>(*toNumber(*maxzoomValue));
- } else {
- return Error{ "GeoJSON source maxzoom value must be a number" };
- }
- }
-
- const auto bufferValue = objectMember(value, "buffer");
- if (bufferValue) {
- if (toNumber(*bufferValue)) {
- options.buffer = static_cast<uint16_t>(*toNumber(*bufferValue));
- } else {
- return Error{ "GeoJSON source buffer value must be a number" };
- }
- }
-
- const auto toleranceValue = objectMember(value, "tolerance");
- if (toleranceValue) {
- if (toNumber(*toleranceValue)) {
- options.tolerance = static_cast<double>(*toNumber(*toleranceValue));
- } else {
- return Error{ "GeoJSON source tolerance value must be a number" };
- }
- }
-
- const auto clusterValue = objectMember(value, "cluster");
- if (clusterValue) {
- if (toBool(*clusterValue)) {
- options.cluster = *toBool(*clusterValue);
- } else {
- return Error{ "GeoJSON source cluster value must be a boolean" };
- }
- }
-
- const auto clusterMaxZoomValue = objectMember(value, "clusterMaxZoom");
- if (clusterMaxZoomValue) {
- if (toNumber(*clusterMaxZoomValue)) {
- options.clusterMaxZoom = static_cast<uint8_t>(*toNumber(*clusterMaxZoomValue));
- } else {
- return Error{ "GeoJSON source clusterMaxZoom value must be a number" };
- }
- }
-
- const auto clusterRadiusValue = objectMember(value, "clusterRadius");
- if (clusterRadiusValue) {
- if (toNumber(*clusterRadiusValue)) {
- options.clusterRadius = static_cast<double>(*toNumber(*clusterRadiusValue));
- } else {
- return Error{ "GeoJSON source clusterRadius value must be a number" };
- }
+ Result<GeoJSONOptions> options = convert<GeoJSONOptions>(value);
+ if (!options) {
+ return options.error();
}
- auto result = std::make_unique<GeoJSONSource>(id, options);
+ auto result = std::make_unique<GeoJSONSource>(id, *options);
if (isObject(*dataValue)) {
Result<GeoJSON> geoJSON = convertGeoJSON(*dataValue);