From fcaafcc428f932e36e195e6801855344798ca33e Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 18 Feb 2016 17:20:31 +0200 Subject: [PATCH] [core] Replace std::array usage in SourceInfo --- src/mbgl/source/source_info.hpp | 6 ++++-- src/mbgl/style/style_parser.cpp | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mbgl/source/source_info.hpp b/src/mbgl/source/source_info.hpp index 9e905d2b9..db584d9e3 100644 --- a/src/mbgl/source/source_info.hpp +++ b/src/mbgl/source/source_info.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -19,8 +20,9 @@ public: uint16_t minZoom = 0; uint16_t maxZoom = 22; std::string attribution; - std::array center = { { 0, 0, 0 } }; - std::array bounds = { { -util::LONGITUDE_MAX, -util::LATITUDE_MAX, util::LONGITUDE_MAX, util::LATITUDE_MAX } }; + LatLng center; + double zoom = 0; + LatLngBounds bounds = LatLngBounds::world(); }; } // namespace mbgl diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 767bee095..797f20ade 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -77,14 +77,13 @@ void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* nam target = uint; } -template -void parseTileJSONMember(const JSValue& value, std::array& target, const char* name) { +void parseTileJSONMember(const JSValue& value, std::array& target, const char* name) { if (!value.HasMember(name)) { return; } const JSValue& property = value[name]; - if (!property.IsArray() || property.Size() != N) { + if (!property.IsArray() || property.Size() > 4) { return; } @@ -284,8 +283,14 @@ std::unique_ptr StyleParser::parseTileJSON(const JSValue& value) { parseTileJSONMember(value, info->minZoom, "minzoom"); parseTileJSONMember(value, info->maxZoom, "maxzoom"); parseTileJSONMember(value, info->attribution, "attribution"); - parseTileJSONMember(value, info->center, "center"); - parseTileJSONMember(value, info->bounds, "bounds"); + + std::array array; + parseTileJSONMember(value, array, "center"); + info->center = { array[0], array[1] }; + info->zoom = array[2]; + parseTileJSONMember(value, array, "bounds"); + info->bounds = LatLngBounds::hull({ array[0], array[1] }, { array[2], array[3] }); + return info; }