diff options
Diffstat (limited to 'src/mbgl/style/conversion/tileset.cpp')
-rw-r--r-- | src/mbgl/style/conversion/tileset.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/tileset.cpp b/src/mbgl/style/conversion/tileset.cpp index b9383c41b8..6e559c0cac 100644 --- a/src/mbgl/style/conversion/tileset.cpp +++ b/src/mbgl/style/conversion/tileset.cpp @@ -1,9 +1,14 @@ #include <mbgl/style/conversion/tileset.hpp> +#include <mbgl/util/geo.hpp> namespace mbgl { namespace style { namespace conversion { +bool validateLatitude(const double lat) { + return lat < 90 && lat > -90; +} + optional<Tileset> Converter<Tileset>::operator()(const Convertible& value, Error& error) const { Tileset result; @@ -65,6 +70,32 @@ optional<Tileset> Converter<Tileset>::operator()(const Convertible& value, Error result.attribution = std::move(*attribution); } + auto boundsValue = objectMember(value, "bounds"); + if (boundsValue) { + if (!isArray(*boundsValue) || arrayLength(*boundsValue) != 4) { + error = { "bounds must be an array with left, bottom, top, and right values" }; + return {}; + } + optional<double> left = toDouble(arrayMember(*boundsValue, 0)); + optional<double> bottom = toDouble(arrayMember(*boundsValue, 1)); + optional<double> right = toDouble(arrayMember(*boundsValue, 2)); + optional<double> top = toDouble(arrayMember(*boundsValue, 3)); + + if (!left || !right || !bottom || !top) { + error = { "bounds array must contain numeric longitude and latitude values" }; + return {}; + } + if (!validateLatitude(*bottom) || !validateLatitude(*top) || top <= bottom){ + error = { "bounds latitude values must be between -90 and 90 with bottom less than top" }; + return {}; + } + if(*left >= *right) { + error = { "bounds left longitude should be less than right longitude" }; + return {}; + } + result.bounds = LatLngBounds::hull({ *bottom, *left }, { *top, *right }); + } + return result; } |