diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-17 17:27:52 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-18 12:53:01 -0700 |
commit | 8d7f2c854ef9adbd2dbfd6b31699c2e45fde90b3 (patch) | |
tree | 53342084b84cb10d3c6c6a421f63d6d925cd1188 | |
parent | d61c6697d212c75462e297411bb99b942a433610 (diff) | |
download | qtlocation-mapboxgl-8d7f2c854ef9adbd2dbfd6b31699c2e45fde90b3.tar.gz |
Converter for CustomVectorSource::Options
-rw-r--r-- | cmake/core-files.cmake | 1 | ||||
-rw-r--r-- | include/mbgl/style/conversion/custom_vector_source_options.hpp | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 6a62d8fb40..146436db9d 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -367,6 +367,7 @@ set(MBGL_CORE_FILES # style/conversion include/mbgl/style/conversion/constant.hpp include/mbgl/style/conversion/coordinate.hpp + include/mbgl/style/conversion/custom_vector_source_options.hpp include/mbgl/style/conversion/data_driven_property_value.hpp include/mbgl/style/conversion/filter.hpp include/mbgl/style/conversion/function.hpp diff --git a/include/mbgl/style/conversion/custom_vector_source_options.hpp b/include/mbgl/style/conversion/custom_vector_source_options.hpp new file mode 100644 index 0000000000..82b107fd0d --- /dev/null +++ b/include/mbgl/style/conversion/custom_vector_source_options.hpp @@ -0,0 +1,64 @@ +#pragma once + +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/sources/custom_vector_source.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter<CustomVectorSource::Options> { + + template <class V> + optional<CustomVectorSource::Options> operator()(const V& value, Error& error) const { + CustomVectorSource::Options options; + + const auto minzoomValue = objectMember(value, "minzoom"); + if (minzoomValue) { + if (toNumber(*minzoomValue)) { + options.zoomRange.min = static_cast<uint8_t>(*toNumber(*minzoomValue)); + } else { + error = { "GeoJSON source minzoom value must be a number" }; + return {}; + } + } + + const auto maxzoomValue = objectMember(value, "maxzoom"); + if (maxzoomValue) { + if (toNumber(*maxzoomValue)) { + options.zoomRange.max = static_cast<uint8_t>(*toNumber(*maxzoomValue)); + } else { + error = { "GeoJSON source maxzoom value must be a number" }; + return {}; + } + } + + const auto bufferValue = objectMember(value, "buffer"); + if (bufferValue) { + if (toNumber(*bufferValue)) { + options.tileOptions.buffer = static_cast<uint16_t>(*toNumber(*bufferValue)); + } else { + error = { "GeoJSON source buffer value must be a number" }; + return {}; + } + } + + const auto toleranceValue = objectMember(value, "tolerance"); + if (toleranceValue) { + if (toNumber(*toleranceValue)) { + options.tileOptions.tolerance = static_cast<double>(*toNumber(*toleranceValue)); + } else { + error = { "GeoJSON source tolerance value must be a number" }; + return {}; + } + } + + return { options }; + } + +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl |