Move SourceInfo into source.hpp/cpp
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/map/live_tile_data.hpp>
|
||||
#include <mbgl/map/live_tile.hpp>
|
||||
#include <mbgl/map/tile_parser.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/map/source.hpp>
|
||||
#include <mbgl/map/vector_tile.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
|
||||
@@ -27,6 +27,74 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void parse(const rapidjson::Value& value, std::vector<std::string>& 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<uint16_t>::max())
|
||||
return;
|
||||
|
||||
target = uint;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
void parse(const rapidjson::Value& value, std::array<float, N>& 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()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
|
||||
#include <mbgl/map/tile.hpp>
|
||||
#include <mbgl/map/tile_data.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/mat4.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <forward_list>
|
||||
#include <iosfwd>
|
||||
@@ -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<std::string> tiles;
|
||||
uint16_t tile_size = 512;
|
||||
uint16_t min_zoom = 0;
|
||||
uint16_t max_zoom = 22;
|
||||
std::string attribution;
|
||||
std::array<float, 3> center = {{0, 0, 0}};
|
||||
std::array<float, 4> bounds = {{-180, -90, 180, 90}};
|
||||
|
||||
void parseTileJSONProperties(const rapidjson::Value&);
|
||||
};
|
||||
|
||||
class Source : public std::enable_shared_from_this<Source>, private util::noncopyable {
|
||||
public:
|
||||
Source();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <mbgl/map/tile_data.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/environment.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/map/source.hpp>
|
||||
|
||||
#include <mbgl/util/token.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/map/source.hpp>
|
||||
#include <mbgl/renderer/fill_bucket.hpp>
|
||||
#include <mbgl/renderer/line_bucket.hpp>
|
||||
#include <mbgl/renderer/symbol_bucket.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
#include <mbgl/style/style_bucket.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/map/source.hpp>
|
||||
#include <mbgl/geometry/glyph_atlas.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/pbf.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/map/source.hpp>
|
||||
#include <mbgl/style/filter_expression.hpp>
|
||||
#include <mbgl/style/class_properties.hpp>
|
||||
#include <mbgl/style/style_bucket.hpp>
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void parse(const rapidjson::Value& value, std::vector<std::string>& 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<uint16_t>::max())
|
||||
return;
|
||||
|
||||
target = uint;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
void parse(const rapidjson::Value& value, std::array<float, N>& 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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef MBGL_STYLE_STYLE_SOURCE
|
||||
#define MBGL_STYLE_STYLE_SOURCE
|
||||
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class SourceInfo : private util::noncopyable {
|
||||
public:
|
||||
SourceType type = SourceType::Vector;
|
||||
std::string url;
|
||||
std::vector<std::string> tiles;
|
||||
uint16_t tile_size = 512;
|
||||
uint16_t min_zoom = 0;
|
||||
uint16_t max_zoom = 22;
|
||||
std::string attribution;
|
||||
std::array<float, 3> center = {{0, 0, 0}};
|
||||
std::array<float, 4> bounds = {{-180, -90, 180, 90}};
|
||||
|
||||
void parseTileJSONProperties(const rapidjson::Value&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user