summaryrefslogtreecommitdiff
path: root/src/mbgl/style/parser.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-13 11:38:18 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-14 11:25:45 -0700
commit9b0093e32dece62abc6fd7add789613871252a58 (patch)
treed6e8f90b12d64c41d4f95d9433e2dfca58be4f60 /src/mbgl/style/parser.cpp
parent7080196bf6b749de5f25b298c0acf49cced20b1e (diff)
downloadqtlocation-mapboxgl-9b0093e32dece62abc6fd7add789613871252a58.tar.gz
[core] Introduce source subclasses
Diffstat (limited to 'src/mbgl/style/parser.cpp')
-rw-r--r--src/mbgl/style/parser.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 870fd6d71e..0a11d6f978 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -1,4 +1,7 @@
#include <mbgl/style/parser.hpp>
+#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/sources/vector_source.hpp>
+#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
@@ -182,6 +185,21 @@ void Parser::parseSources(const JSValue& value) {
std::unique_ptr<Tileset> tileset;
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt;
+ const std::string id { nameVal.GetString(), nameVal.GetStringLength() };
+ std::unique_ptr<Source> source;
+
+ if (sourceVal.HasMember("url")) {
+ const JSValue& urlVal = sourceVal["url"];
+ if (urlVal.IsString()) {
+ url = { urlVal.GetString(), urlVal.GetStringLength() };
+ } else {
+ Log::Error(Event::ParseStyle, "source url must be a string");
+ continue;
+ }
+ } else {
+ tileset = parseTileJSON(sourceVal);
+ }
+
switch (*type) {
case SourceType::Raster:
if (sourceVal.HasMember("tileSize")) {
@@ -193,20 +211,12 @@ void Parser::parseSources(const JSValue& value) {
continue;
}
}
- // Fall through. Vector sources are forbidden from having a tileSize.
+
+ source = std::make_unique<RasterSource>(id, url, tileSize, std::move(tileset), std::move(geojsonvt));
+ break;
case SourceType::Vector:
- if (sourceVal.HasMember("url")) {
- const JSValue& urlVal = sourceVal["url"];
- if (urlVal.IsString()) {
- url = { urlVal.GetString(), urlVal.GetStringLength() };
- } else {
- Log::Error(Event::ParseStyle, "source url must be a string");
- continue;
- }
- } else {
- tileset = parseTileJSON(sourceVal);
- }
+ source = std::make_unique<VectorSource>(id, url, tileSize, std::move(tileset), std::move(geojsonvt));
break;
case SourceType::GeoJSON:
@@ -233,6 +243,7 @@ void Parser::parseSources(const JSValue& value) {
continue;
}
+ source = std::make_unique<GeoJSONSource>(id, url, tileSize, std::move(tileset), std::move(geojsonvt));
break;
default:
@@ -240,9 +251,6 @@ void Parser::parseSources(const JSValue& value) {
continue;
}
- const std::string id { nameVal.GetString(), nameVal.GetStringLength() };
- std::unique_ptr<Source> source = std::make_unique<Source>(*type, id, url, tileSize, std::move(tileset), std::move(geojsonvt));
-
sourcesMap.emplace(id, source.get());
sources.emplace_back(std::move(source));
}