summaryrefslogtreecommitdiff
path: root/src/mbgl/style/style_parser.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-29 17:48:58 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-01 15:33:37 -0800
commit04cc019f54c9b821d287f1b679708955b6519fe1 (patch)
tree8714298f13431818b0b9353528f0cfc5469083e3 /src/mbgl/style/style_parser.cpp
parent716997b99eed50ecf35fd1ec3124a85760a05753 (diff)
downloadqtlocation-mapboxgl-04cc019f54c9b821d287f1b679708955b6519fe1.tar.gz
[core] Refactor TileJSON parsing for offline
Diffstat (limited to 'src/mbgl/style/style_parser.cpp')
-rw-r--r--src/mbgl/style/style_parser.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index aca4e647d2..1b088bd38f 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -11,10 +11,13 @@
#include <mapbox/geojsonvt.hpp>
#include <mapbox/geojsonvt/convert.hpp>
+#include <mbgl/util/mapbox.hpp>
+
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <algorithm>
+#include <sstream>
namespace mbgl {
@@ -101,7 +104,7 @@ StyleParser::~StyleParser() = default;
void StyleParser::parse(const std::string& json) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
- document.Parse<0>((const char *const)json.c_str());
+ document.Parse<0>(json.c_str());
if (document.HasParseError()) {
Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", document.GetErrorOffset(), rapidjson::GetParseError_En(document.GetParseError()));
@@ -252,6 +255,29 @@ std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> StyleParser::parseGeoJSON(const JS
}
}
+std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
+ document.Parse<0>(json.c_str());
+
+ if (document.HasParseError()) {
+ std::stringstream message;
+ message << document.GetErrorOffset() << " - " << rapidjson::GetParseError_En(document.GetParseError());
+ throw std::runtime_error(message.str());
+ }
+
+ std::unique_ptr<SourceInfo> result = StyleParser::parseTileJSON(document);
+
+ // TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with.
+ if (util::mapbox::isMapboxURL(sourceURL)) {
+ std::transform(result->tiles.begin(),
+ result->tiles.end(),
+ result->tiles.begin(),
+ util::mapbox::normalizeRasterTileURL);
+ }
+
+ return result;
+}
+
std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const JSValue& value) {
auto info = std::make_unique<SourceInfo>();
parseTileJSONMember(value, info->tiles, "tiles");