diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-12-08 16:36:33 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-12-11 15:25:12 -0800 |
commit | 132b68e4fc277da10e2fbc457e54931e1c8ffd4e (patch) | |
tree | 107ea3497b5e76330b3c977041ec44568582b5a2 | |
parent | 2b9f20461af3b1637d29abdca38188549e21cc41 (diff) | |
download | qtlocation-mapboxgl-132b68e4fc277da10e2fbc457e54931e1c8ffd4e.tar.gz |
[core] split Source parsing into separate functions
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 84 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.hpp | 2 |
2 files changed, 65 insertions, 21 deletions
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index a22615d435..d029f633af 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -73,39 +73,81 @@ void StyleParser::parseSources(const JSVal& value) { source->info.type = SourceTypeClass({ typeVal.GetString(), typeVal.GetStringLength() }); - if (sourceVal.HasMember("url")) { - const JSVal& urlVal = sourceVal["url"]; - - if (!urlVal.IsString()) { - Log::Warning(Event::ParseStyle, "source url must be a string"); + switch (source->info.type) { + case SourceType::Vector: + if (!parseVectorSource(*source, sourceVal)) { + continue; + } + break; + case SourceType::Raster: + if (!parseRasterSource(*source, sourceVal)) { continue; } + break; + default: + Log::Warning(Event::ParseStyle, "source type %s is not supported", SourceTypeClass(source->info.type).c_str()); + } - source->info.url = { urlVal.GetString(), urlVal.GetStringLength() }; + sourcesMap.emplace(source->info.source_id, source.get()); + sources.emplace_back(std::move(source)); + } +} + +bool StyleParser::parseVectorSource(Source& source, const JSVal& sourceVal) { + // A vector tile source either specifies the URL of a TileJSON file... + if (sourceVal.HasMember("url")) { + const JSVal& urlVal = sourceVal["url"]; + + if (!urlVal.IsString()) { + Log::Warning(Event::ParseStyle, "source url must be a string"); + return false; } - if (sourceVal.HasMember("tileSize")) { - const JSVal& tileSizeVal = sourceVal["tileSize"]; + source.info.url = { urlVal.GetString(), urlVal.GetStringLength() }; - if (!tileSizeVal.IsUint()) { - Log::Warning(Event::ParseStyle, "source tileSize must be an unsigned integer"); - continue; - } + } else { + // ...or the TileJSON directly. + source.info.parseTileJSONProperties(sourceVal); + } - unsigned int intValue = tileSizeVal.GetUint(); - if (intValue > std::numeric_limits<uint16_t>::max()) { - Log::Warning(Event::ParseStyle, "values for tileSize that are larger than %d are not supported", std::numeric_limits<uint16_t>::max()); - continue; - } + return true; +} - source->info.tile_size = intValue; +bool StyleParser::parseRasterSource(Source& source, const JSVal& sourceVal) { + if (sourceVal.HasMember("tileSize")) { + const JSVal& tileSizeVal = sourceVal["tileSize"]; + + if (!tileSizeVal.IsUint()) { + Log::Warning(Event::ParseStyle, "source tileSize must be an unsigned integer"); + return false; } - source->info.parseTileJSONProperties(sourceVal); + unsigned int intValue = tileSizeVal.GetUint(); + if (intValue > std::numeric_limits<uint16_t>::max()) { + Log::Warning(Event::ParseStyle, "values for tileSize that are larger than %d are not supported", std::numeric_limits<uint16_t>::max()); + return false; + } - sourcesMap.emplace(source->info.source_id, source.get()); - sources.emplace_back(std::move(source)); + source.info.tile_size = intValue; + } + + // A raster tile source either specifies the URL of a TileJSON file... + if (sourceVal.HasMember("url")) { + const JSVal& urlVal = sourceVal["url"]; + + if (!urlVal.IsString()) { + Log::Warning(Event::ParseStyle, "source url must be a string"); + return false; + } + + source.info.url = { urlVal.GetString(), urlVal.GetStringLength() }; + + } else { + // ...or the TileJSON directly. + source.info.parseTileJSONProperties(sourceVal); } + + return true; } void StyleParser::parseLayers(const JSVal& value) { diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 2c5a43065d..2307517e37 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -33,6 +33,8 @@ public: private: void parseSources(const JSVal&); + bool parseVectorSource(Source&, const JSVal&); + bool parseRasterSource(Source&, const JSVal&); void parseLayers(const JSVal&); void parseLayer(const std::string& id, const JSVal&, std::unique_ptr<StyleLayer>&); void parseVisibility(StyleLayer&, const JSVal& value); |