diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-04-20 12:39:51 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-06-01 15:38:01 -0700 |
commit | 7a010df9560e8807b9be938bb5ff7360e8e730a6 (patch) | |
tree | acb862796062e35d2ffdf77deb9514ee73f3d6ad /include/mbgl/style/conversion/coordinate.hpp | |
parent | 9068c90fc4b1b8b4938d89028fc3f7b46beeac29 (diff) | |
download | qtlocation-mapboxgl-7a010df9560e8807b9be938bb5ff7360e8e730a6.tar.gz |
[core] Add ImageSource support to style parsers
Diffstat (limited to 'include/mbgl/style/conversion/coordinate.hpp')
-rw-r--r-- | include/mbgl/style/conversion/coordinate.hpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp new file mode 100644 index 0000000000..0adbb9a7ee --- /dev/null +++ b/include/mbgl/style/conversion/coordinate.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <mbgl/style/conversion.hpp> +#include <mbgl/util/geo.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template<> +struct Converter<std::unique_ptr<LatLng>> { +public: + template <class V> + optional<std::unique_ptr<LatLng>> operator() (const V& value, Error& error) const { + if (!isArray(value) || arrayLength(value) < 2 ) { + error = { "coordinate array must contain numeric longtitude and latitude values" }; + return {}; + } + //Style spec uses GeoJSON convention for specifying coordinates + optional<float> latitude = toNumber(arrayMember(value, 1)); + optional<float> longitude = toNumber(arrayMember(value, 0)); + + if (!latitude || !longitude) { + error = { "coordinate array must contain numeric longtitude and latitude values" }; + return {}; + } + if (*latitude < -90 || *latitude > 90 ){ + error = { "coordinate latitude must be between -90 and 90" }; + return {}; + } + return { std::make_unique<LatLng>(*latitude, *longitude) }; + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl |