summaryrefslogtreecommitdiff
path: root/src/mbgl/style/parser.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/parser.cpp
parent16c435b1517b15a5ea8654987979ef58800b838b (diff)
downloadqtlocation-mapboxgl-021d4199cb9ee754e9f0f5bc42f7f75285afd405.tar.gz
[core, node] Implement bindings for addSource
Diffstat (limited to 'src/mbgl/style/parser.cpp')
-rw-r--r--src/mbgl/style/parser.cpp66
1 files changed, 10 insertions, 56 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index ac263dbc57..41b23c1bae 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -1,23 +1,13 @@
#include <mbgl/style/parser.hpp>
-#include <mbgl/style/sources/raster_source_impl.hpp>
-#include <mbgl/style/sources/vector_source_impl.hpp>
-#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/layer_impl.hpp>
-#include <mbgl/style/layers/fill_layer.hpp>
-#include <mbgl/style/layers/line_layer.hpp>
-#include <mbgl/style/layers/circle_layer.hpp>
-#include <mbgl/style/layers/symbol_layer.hpp>
-#include <mbgl/style/layers/raster_layer.hpp>
-#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/source.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/platform/log.hpp>
-#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/util/enum.hpp>
-#include <mbgl/util/tileset.hpp>
+#include <mapbox/geojsonvt.hpp>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
@@ -75,54 +65,18 @@ void Parser::parseSources(const JSValue& value) {
return;
}
- JSValue::ConstMemberIterator itr = value.MemberBegin();
- for (; itr != value.MemberEnd(); ++itr) {
- const JSValue& nameVal = itr->name;
- const JSValue& sourceVal = itr->value;
+ for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) {
+ std::string id = *conversion::toString(it->name);
- if (!sourceVal.HasMember("type")) {
- Log::Warning(Event::ParseStyle, "source must have a type");
+ conversion::Result<std::unique_ptr<Source>> source
+ = conversion::convert<std::unique_ptr<Source>>(it->value, id);
+ if (!source) {
+ Log::Warning(Event::ParseStyle, source.error().message);
continue;
}
- const JSValue& typeVal = sourceVal["type"];
- if (!typeVal.IsString()) {
- Log::Warning(Event::ParseStyle, "source type must be a string");
- continue;
- }
-
- const auto type = Enum<SourceType>::toEnum({ typeVal.GetString(), typeVal.GetStringLength() });
- if (!type) {
- Log::Warning(Event::ParseStyle, "source type must have one of the enum values");
- continue;
- }
-
- const std::string id { nameVal.GetString(), nameVal.GetStringLength() };
- std::unique_ptr<Source> source;
-
- switch (*type) {
- case SourceType::Raster: {
- source = RasterSource::Impl::parse(id, sourceVal);
- break;
- }
-
- case SourceType::Vector:
- source = VectorSource::Impl::parse(id, sourceVal);
- break;
-
- case SourceType::GeoJSON:
- source = GeoJSONSource::Impl::parse(id, sourceVal);
- break;
-
- default:
- Log::Error(Event::ParseStyle, "source type '%s' is not supported", typeVal.GetString());
- continue;
- }
-
- if (source) {
- sourcesMap.emplace(id, source.get());
- sources.emplace_back(std::move(source));
- }
+ sourcesMap.emplace(id, (*source).get());
+ sources.emplace_back(std::move(*source));
}
}