summaryrefslogtreecommitdiff
path: root/src/mbgl/style/tile_source_impl.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-23 12:00:25 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-24 09:39:51 -0700
commit021d4199cb9ee754e9f0f5bc42f7f75285afd405 (patch)
tree9396f291348c0ab5f3a75e1a217a78fc4dbff4b2 /src/mbgl/style/tile_source_impl.cpp
parent16c435b1517b15a5ea8654987979ef58800b838b (diff)
downloadqtlocation-mapboxgl-021d4199cb9ee754e9f0f5bc42f7f75285afd405.tar.gz
[core, node] Implement bindings for addSource
Diffstat (limited to 'src/mbgl/style/tile_source_impl.cpp')
-rw-r--r--src/mbgl/style/tile_source_impl.cpp94
1 files changed, 8 insertions, 86 deletions
diff --git a/src/mbgl/style/tile_source_impl.cpp b/src/mbgl/style/tile_source_impl.cpp
index 634ef39808..3999a88a07 100644
--- a/src/mbgl/style/tile_source_impl.cpp
+++ b/src/mbgl/style/tile_source_impl.cpp
@@ -1,10 +1,10 @@
#include <mbgl/style/tile_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
-#include <mbgl/style/parser.hpp>
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/conversion/tileset.hpp>
#include <mbgl/util/tileset.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/storage/file_source.hpp>
-#include <mbgl/platform/log.hpp>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
@@ -14,73 +14,6 @@
namespace mbgl {
namespace style {
-namespace {
-
-void parseTileJSONMember(const JSValue& value, std::vector<std::string>& target, const char* name) {
- if (!value.HasMember(name)) {
- return;
- }
-
- const JSValue& 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 parseTileJSONMember(const JSValue& value, std::string& target, const char* name) {
- if (!value.HasMember(name)) {
- return;
- }
-
- const JSValue& property = value[name];
- if (!property.IsString()) {
- return;
- }
-
- target = { property.GetString(), property.GetStringLength() };
-}
-
-void parseTileJSONMember(const JSValue& value, uint8_t& target, const char* name) {
- if (!value.HasMember(name)) {
- return;
- }
-
- const JSValue& property = value[name];
- if (!property.IsUint()) {
- return;
- }
-
- unsigned int uint = property.GetUint();
- if (uint > std::numeric_limits<uint8_t>::max()) {
- return;
- }
-
- target = uint;
-}
-
-Tileset parseTileJSON(const JSValue& value) {
- Tileset result;
-
- parseTileJSONMember(value, result.tiles, "tiles");
- parseTileJSONMember(value, result.zoomRange.min, "minzoom");
- parseTileJSONMember(value, result.zoomRange.max, "maxzoom");
- parseTileJSONMember(value, result.attribution, "attribution");
-
- return result;
-}
-
-} // end namespace
-
Tileset TileSourceImpl::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
document.Parse<0>(json.c_str());
@@ -91,30 +24,19 @@ Tileset TileSourceImpl::parseTileJSON(const std::string& json, const std::string
throw std::runtime_error(message.str());
}
- Tileset result = mbgl::style::parseTileJSON(document);
+ conversion::Result<Tileset> result = conversion::convert<Tileset>(document);
+ if (!result) {
+ throw std::runtime_error(result.error().message);
+ }
// TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with.
if (util::mapbox::isMapboxURL(sourceURL)) {
- for (auto& url : result.tiles) {
+ for (auto& url : (*result).tiles) {
url = util::mapbox::canonicalizeTileURL(url, type, tileSize);
}
}
- return result;
-}
-
-optional<variant<std::string, Tileset>> TileSourceImpl::parseURLOrTileset(const JSValue& value) {
- if (!value.HasMember("url")) {
- return { mbgl::style::parseTileJSON(value) };
- }
-
- const JSValue& urlVal = value["url"];
- if (!urlVal.IsString()) {
- Log::Error(Event::ParseStyle, "source url must be a string");
- return {};
- }
-
- return { std::string(urlVal.GetString(), urlVal.GetStringLength()) };
+ return *result;
}
TileSourceImpl::TileSourceImpl(SourceType type_, std::string id_, Source& base_,