summaryrefslogtreecommitdiff
path: root/src/mbgl/style/parser.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-14 10:46:35 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-14 11:25:45 -0700
commit615a6685a47609310930890203f41815a5f19d48 (patch)
tree2f777fbe6d5e4d33453dbcb7d95d2f295bafa83c /src/mbgl/style/parser.cpp
parent2257ebf1c2297754960b4a1f1d5c3d25717c17db (diff)
downloadqtlocation-mapboxgl-615a6685a47609310930890203f41815a5f19d48.tar.gz
[core] Move GeoJSON-specific parsing into geojson_source.cpp
Diffstat (limited to 'src/mbgl/style/parser.cpp')
-rw-r--r--src/mbgl/style/parser.cpp86
1 files changed, 21 insertions, 65 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 670a5dbd92..8a677d29c8 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -12,9 +12,6 @@
#include <mbgl/platform/log.hpp>
-#include <mapbox/geojsonvt.hpp>
-#include <mapbox/geojsonvt/convert.hpp>
-
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/enum.hpp>
@@ -175,19 +172,15 @@ void Parser::parseSources(const JSValue& value) {
continue;
}
- // Sources can have URLs, either because they reference an external TileJSON file, or
- // because reference a GeoJSON file. They don't have to have one though when all source
- // parameters are specified inline.
- std::string url;
-
- uint16_t tileSize = util::tileSize;
+ const std::string id { nameVal.GetString(), nameVal.GetStringLength() };
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;
+ // Sources can have URLs, either because they reference an external TileJSON file, or
+ // because reference a GeoJSON file. They don't have to have one though when all source
+ // parameters are specified inline.
+ std::string url;
if (sourceVal.HasMember("url")) {
const JSValue& urlVal = sourceVal["url"];
if (urlVal.IsString()) {
@@ -200,18 +193,19 @@ void Parser::parseSources(const JSValue& value) {
tileset = parseTileJSON(sourceVal);
}
- switch (*type) {
- case SourceType::Raster:
- if (sourceVal.HasMember("tileSize")) {
- const JSValue& tileSizeVal = sourceVal["tileSize"];
- if (tileSizeVal.IsNumber() && tileSizeVal.GetUint64() <= std::numeric_limits<uint16_t>::max()) {
- tileSize = tileSizeVal.GetUint64();
- } else {
- Log::Error(Event::ParseStyle, "invalid tileSize");
- continue;
- }
+ uint16_t tileSize = util::tileSize;
+ if (sourceVal.HasMember("tileSize")) {
+ const JSValue& tileSizeVal = sourceVal["tileSize"];
+ if (tileSizeVal.IsNumber() && tileSizeVal.GetUint64() <= std::numeric_limits<uint16_t>::max()) {
+ tileSize = tileSizeVal.GetUint64();
+ } else {
+ Log::Error(Event::ParseStyle, "invalid tileSize");
+ continue;
}
+ }
+ switch (*type) {
+ case SourceType::Raster:
source = std::make_unique<RasterSource>(id, url, tileSize, std::move(tileset));
break;
@@ -220,30 +214,7 @@ void Parser::parseSources(const JSValue& value) {
break;
case SourceType::GeoJSON:
- tileset = std::make_unique<Tileset>();
-
- // We should probably split this up to have URLs in the url property, and actual data
- // in the data property. Until then, we're going to detect the content based on the
- // object type.
- if (sourceVal.HasMember("data")) {
- const JSValue& dataVal = sourceVal["data"];
- if (dataVal.IsString()) {
- // We need to load an external GeoJSON file
- url = { dataVal.GetString(), dataVal.GetStringLength() };
- } else if (dataVal.IsObject()) {
- // We need to parse dataVal as a GeoJSON object
- geojsonvt = parseGeoJSON(dataVal);
- tileset->maxZoom = geojsonvt->options.maxZoom;
- } else {
- Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object");
- continue;
- }
- } else {
- Log::Error(Event::ParseStyle, "GeoJSON source must have a data value");
- continue;
- }
-
- source = std::make_unique<GeoJSONSource>(id, url, tileSize, std::move(tileset), std::move(geojsonvt));
+ source = GeoJSONSource::parse(id, sourceVal);
break;
default:
@@ -251,25 +222,10 @@ void Parser::parseSources(const JSValue& value) {
continue;
}
- sourcesMap.emplace(id, source.get());
- sources.emplace_back(std::move(source));
- }
-}
-
-std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> parseGeoJSON(const JSValue& value) {
- using namespace mapbox::geojsonvt;
-
- Options options;
- options.buffer = util::EXTENT / util::tileSize * 128;
- options.extent = util::EXTENT;
-
- try {
- return std::make_unique<GeoJSONVT>(Convert::convert(value, 0), options);
- } catch (const std::exception& ex) {
- Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s", ex.what());
- // Create an empty GeoJSON VT object to make sure we're not infinitely waiting for
- // tiles to load.
- return std::make_unique<GeoJSONVT>(std::vector<ProjectedFeature>{}, options);
+ if (source) {
+ sourcesMap.emplace(id, source.get());
+ sources.emplace_back(std::move(source));
+ }
}
}