[core] Replace std::array<double, N> usage in SourceInfo

This commit is contained in:
Bruno de Oliveira Abinader
2016-02-18 17:20:31 +02:00
parent c17e954983
commit fcaafcc428
2 changed files with 14 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
#include <array>
#include <vector>
@@ -19,8 +20,9 @@ public:
uint16_t minZoom = 0;
uint16_t maxZoom = 22;
std::string attribution;
std::array<double, 3> center = { { 0, 0, 0 } };
std::array<double, 4> bounds = { { -util::LONGITUDE_MAX, -util::LATITUDE_MAX, util::LONGITUDE_MAX, util::LATITUDE_MAX } };
LatLng center;
double zoom = 0;
LatLngBounds bounds = LatLngBounds::world();
};
} // namespace mbgl

View File

@@ -77,14 +77,13 @@ void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* nam
target = uint;
}
template <size_t N>
void parseTileJSONMember(const JSValue& value, std::array<double, N>& target, const char* name) {
void parseTileJSONMember(const JSValue& value, std::array<double, 4>& 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<SourceInfo> 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<double, 4> 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;
}