Load TileJSON; support inline TileJSON sources
Fixes #412 Refs https://github.com/mapbox/mapbox-gl-style-spec/pull/143
This commit is contained in:
committed by
John Firebaugh
parent
b9c7e1bdd9
commit
0168612ed3
@@ -1,3 +1,4 @@
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/style/style_layer_group.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
@@ -175,21 +176,14 @@ void StyleParser::parseSources(JSVal value) {
|
||||
rapidjson::Value::ConstMemberIterator itr = value.MemberBegin();
|
||||
for (; itr != value.MemberEnd(); ++itr) {
|
||||
std::string name { itr->name.GetString(), itr->name.GetStringLength() };
|
||||
SourceType type = SourceType::Vector;
|
||||
std::string url;
|
||||
uint16_t tile_size = 512;
|
||||
int32_t min_zoom = 0;
|
||||
int32_t max_zoom = 22;
|
||||
SourceInfo info;
|
||||
|
||||
parseRenderProperty<SourceTypeClass>(itr->value, type, "type");
|
||||
parseRenderProperty(itr->value, url, "url");
|
||||
if (type == SourceType::Raster) {
|
||||
parseRenderProperty(itr->value, tile_size, "tileSize");
|
||||
}
|
||||
parseRenderProperty(itr->value, min_zoom, "minZoom");
|
||||
parseRenderProperty(itr->value, max_zoom, "maxZoom");
|
||||
parseRenderProperty<SourceTypeClass>(itr->value, info.type, "type");
|
||||
parseRenderProperty(itr->value, info.url, "url");
|
||||
parseRenderProperty(itr->value, info.tile_size, "tileSize");
|
||||
info.parseTileJSONProperties(itr->value);
|
||||
|
||||
sources.emplace(std::move(name), std::make_shared<StyleSource>(SourceInfo { type, url, tile_size, min_zoom, max_zoom }));
|
||||
sources.emplace(std::move(name), std::make_shared<StyleSource>(info));
|
||||
}
|
||||
} else {
|
||||
Log::Warning(Event::ParseStyle, "sources must be an object");
|
||||
|
||||
77
src/style/style_source.cpp
Normal file
77
src/style/style_source.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user