diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp index dd83ed422..8109b7e6e 100644 --- a/src/mbgl/map/live_tile_data.cpp +++ b/src/mbgl/map/live_tile_data.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 0b8760b56..c8ee0ee3e 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -27,6 +27,74 @@ namespace mbgl { +void parse(const rapidjson::Value& value, std::vector& target, const char *name) { + if (!value.HasMember(name)) + return; + + const rapidjson::Value& property = value[name]; + if (!property.IsArray()) + return; + + for (rapidjson::SizeType i = 0; i < property.Size(); i++) + if (!property[i].IsString()) + return; + + for (rapidjson::SizeType i = 0; i < property.Size(); i++) + target.emplace_back(std::string(property[i].GetString(), property[i].GetStringLength())); +} + +void parse(const rapidjson::Value& value, std::string& target, const char* name) { + if (!value.HasMember(name)) + return; + + const rapidjson::Value& property = value[name]; + if (!property.IsString()) + return; + + target = { property.GetString(), property.GetStringLength() }; +} + +void parse(const rapidjson::Value& value, uint16_t& target, const char* name) { + if (!value.HasMember(name)) + return; + + const rapidjson::Value& property = value[name]; + if (!property.IsUint()) + return; + + unsigned int uint = property.GetUint(); + if (uint > std::numeric_limits::max()) + return; + + target = uint; +} + +template +void parse(const rapidjson::Value& value, std::array& target, const char* name) { + if (!value.HasMember(name)) + return; + + const rapidjson::Value& property = value[name]; + if (!property.IsArray() || property.Size() != N) + return; + + for (rapidjson::SizeType i = 0; i < property.Size(); i++) + if (!property[i].IsNumber()) + return; + + for (rapidjson::SizeType i = 0; i < property.Size(); i++) + target[i] = property[i].GetDouble(); +} + +void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) { + parse(value, tiles, "tiles"); + parse(value, min_zoom, "minzoom"); + parse(value, max_zoom, "maxzoom"); + parse(value, attribution, "attribution"); + parse(value, center, "center"); + parse(value, bounds, "bounds"); +} + Source::Source() { } diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 0831f7b0b..b683f44a2 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -3,13 +3,15 @@ #include #include -#include +#include #include #include #include #include +#include + #include #include #include @@ -30,6 +32,21 @@ class StyleLayer; class TransformState; struct box; +class SourceInfo : private util::noncopyable { +public: + SourceType type = SourceType::Vector; + std::string url; + std::vector tiles; + uint16_t tile_size = 512; + uint16_t min_zoom = 0; + uint16_t max_zoom = 22; + std::string attribution; + std::array center = {{0, 0, 0}}; + std::array bounds = {{-180, -90, 180, 90}}; + + void parseTileJSONProperties(const rapidjson::Value&); +}; + class Source : public std::enable_shared_from_this, private util::noncopyable { public: Source(); diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp index 1832bd8f0..aa8e159fa 100644 --- a/src/mbgl/map/tile_data.cpp +++ b/src/mbgl/map/tile_data.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index bc6de4056..275b77be9 100644 --- a/src/mbgl/map/tile_parser.cpp +++ b/src/mbgl/map/tile_parser.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp index 3bed7a1c3..0f04efd28 100644 --- a/src/mbgl/map/vector_tile_data.cpp +++ b/src/mbgl/map/vector_tile_data.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index bf8e0fef8..6f970d21e 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/mbgl/style/style_source.cpp b/src/mbgl/style/style_source.cpp deleted file mode 100644 index f46a6fb09..000000000 --- a/src/mbgl/style/style_source.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include - -#include - -namespace mbgl { - -void parse(const rapidjson::Value& value, std::vector& target, const char *name) { - if (!value.HasMember(name)) - return; - - const rapidjson::Value& property = value[name]; - if (!property.IsArray()) - return; - - for (rapidjson::SizeType i = 0; i < property.Size(); i++) - if (!property[i].IsString()) - return; - - for (rapidjson::SizeType i = 0; i < property.Size(); i++) - target.emplace_back(std::string(property[i].GetString(), property[i].GetStringLength())); -} - -void parse(const rapidjson::Value& value, std::string& target, const char* name) { - if (!value.HasMember(name)) - return; - - const rapidjson::Value& property = value[name]; - if (!property.IsString()) - return; - - target = { property.GetString(), property.GetStringLength() }; -} - -void parse(const rapidjson::Value& value, uint16_t& target, const char* name) { - if (!value.HasMember(name)) - return; - - const rapidjson::Value& property = value[name]; - if (!property.IsUint()) - return; - - unsigned int uint = property.GetUint(); - if (uint > std::numeric_limits::max()) - return; - - target = uint; -} - -template -void parse(const rapidjson::Value& value, std::array& target, const char* name) { - if (!value.HasMember(name)) - return; - - const rapidjson::Value& property = value[name]; - if (!property.IsArray() || property.Size() != N) - return; - - for (rapidjson::SizeType i = 0; i < property.Size(); i++) - if (!property[i].IsNumber()) - return; - - for (rapidjson::SizeType i = 0; i < property.Size(); i++) - target[i] = property[i].GetDouble(); -} - -void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) { - parse(value, tiles, "tiles"); - parse(value, min_zoom, "minzoom"); - parse(value, max_zoom, "maxzoom"); - parse(value, attribution, "attribution"); - parse(value, center, "center"); - parse(value, bounds, "bounds"); -} - -} diff --git a/src/mbgl/style/style_source.hpp b/src/mbgl/style/style_source.hpp deleted file mode 100644 index 93abca63b..000000000 --- a/src/mbgl/style/style_source.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_SOURCE -#define MBGL_STYLE_STYLE_SOURCE - -#include -#include -#include - -#include -#include - -namespace mbgl { - -class SourceInfo : private util::noncopyable { -public: - SourceType type = SourceType::Vector; - std::string url; - std::vector tiles; - uint16_t tile_size = 512; - uint16_t min_zoom = 0; - uint16_t max_zoom = 22; - std::string attribution; - std::array center = {{0, 0, 0}}; - std::array bounds = {{-180, -90, 180, 90}}; - - void parseTileJSONProperties(const rapidjson::Value&); -}; - -} - -#endif