summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-12-10 17:46:13 -0800
committerKonstantin Käfer <mail@kkaefer.com>2015-12-11 16:23:43 -0800
commit8d711e9c80f92b165ef3cfff14be132f70039b97 (patch)
tree0a53b6ba1a3a1e827546d34bc2791916b24043ac /src
parentc4a01d51ea755089401f767ad258126969615c46 (diff)
downloadqtlocation-mapboxgl-8d711e9c80f92b165ef3cfff14be132f70039b97.tar.gz
[test] update test suite to include more comprehensive GeoJSON tests
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/source.cpp8
-rw-r--r--src/mbgl/map/source_info.cpp15
-rw-r--r--src/mbgl/map/source_info.hpp1
-rw-r--r--src/mbgl/style/style_parser.cpp13
4 files changed, 24 insertions, 13 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 28ea69f007..7dd5709c43 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -61,6 +61,7 @@ void Source::load() {
return;
}
+ // URL may either be a TileJSON file, or a GeoJSON file.
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Source, info.url }, [this](Response res) {
if (res.stale) {
@@ -86,7 +87,12 @@ void Source::load() {
return;
}
- info.parseTileJSONProperties(d);
+ if (info.type == SourceType::Vector || info.type == SourceType::Raster) {
+ info.parseTileJSONProperties(d);
+ } else if (info.type == SourceType::GeoJSON) {
+ info.parseGeoJSON(d);
+ }
+
loaded = true;
emitSourceLoaded();
diff --git a/src/mbgl/map/source_info.cpp b/src/mbgl/map/source_info.cpp
index 3a79cb9dff..8f1b42ea93 100644
--- a/src/mbgl/map/source_info.cpp
+++ b/src/mbgl/map/source_info.cpp
@@ -1,9 +1,11 @@
+#include <mbgl/platform/log.hpp>
#include <mbgl/map/source_info.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/token.hpp>
#include <mapbox/geojsonvt.hpp>
+#include <mapbox/geojsonvt/convert.hpp>
namespace mbgl {
@@ -97,6 +99,19 @@ void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) {
parse(value, bounds, "bounds");
}
+void SourceInfo::parseGeoJSON(const rapidjson::Value& value) {
+ using namespace mapbox::geojsonvt;
+
+ try {
+ geojsonvt = std::make_unique<GeoJSONVT>(Convert::convert(value, 0));
+ } 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.
+ geojsonvt = std::make_unique<GeoJSONVT>(std::vector<ProjectedFeature>{});
+ }
+}
+
std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const {
std::string result = tiles.at(0);
result = util::mapbox::normalizeTileURL(result, url, type);
diff --git a/src/mbgl/map/source_info.hpp b/src/mbgl/map/source_info.hpp
index 5b4e4e2e15..81c79bd823 100644
--- a/src/mbgl/map/source_info.hpp
+++ b/src/mbgl/map/source_info.hpp
@@ -39,6 +39,7 @@ public:
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt;
void parseTileJSONProperties(const rapidjson::Value&);
+ void parseGeoJSON(const rapidjson::Value&);
std::string tileURL(const TileID& id, float pixelRatio) const;
};
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index dd89b84e69..06f81a8ab2 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -8,9 +8,6 @@
#include <mbgl/platform/log.hpp>
-#include <mapbox/geojsonvt.hpp>
-#include <mapbox/geojsonvt/convert.hpp>
-
#include <algorithm>
namespace mbgl {
@@ -170,15 +167,7 @@ bool StyleParser::parseGeoJSONSource(Source& source, const JSVal& sourceVal) {
source.info.url = { dataVal.GetString(), dataVal.GetStringLength() };
} else if (dataVal.IsObject()) {
// We need to parse dataVal as a GeoJSON object
- using namespace mapbox::geojsonvt;
- try {
- source.info.geojsonvt = std::make_unique<GeoJSONVT>(Convert::convert(dataVal, 0));
- } 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.
- source.info.geojsonvt = std::make_unique<GeoJSONVT>(std::vector<ProjectedFeature>{});
- }
+ source.info.parseGeoJSON(dataVal);
} else {
Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object");
return false;