From 6320b4cda3f9510f3e3bcba7eef22ce499af1b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 10 Dec 2015 17:46:13 -0800 Subject: [PATCH] [test] update test suite to include more comprehensive GeoJSON tests --- package.json | 2 +- scripts/android/configure.sh | 2 +- scripts/ios/configure.sh | 2 +- scripts/linux/configure.sh | 2 +- scripts/osx/configure.sh | 2 +- src/mbgl/map/source.cpp | 8 +++++++- src/mbgl/map/source_info.cpp | 15 +++++++++++++++ src/mbgl/map/source_info.hpp | 1 + src/mbgl/style/style_parser.cpp | 13 +------------ 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 1be43627326..7ebe666fa04 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "devDependencies": { "aws-sdk": "^2.2.21", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#6e2b48155ca651b37826942f2ca082be687b7a42", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#78bde0077848b4af0efd490d124bde3ea9f56ec9", "node-gyp": "^3.2.1", "request": "^2.67.0", "tape": "^4.2.2" diff --git a/scripts/android/configure.sh b/scripts/android/configure.sh index bc19d546a1a..7c5e3e926a2 100644 --- a/scripts/android/configure.sh +++ b/scripts/android/configure.sh @@ -8,7 +8,7 @@ LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 LIBZIP_VERSION=0.11.2 -GEOJSONVT_VERSION=3.0.0 +GEOJSONVT_VERSION=3.0.1 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 diff --git a/scripts/ios/configure.sh b/scripts/ios/configure.sh index 06d66c5850a..3826d935713 100644 --- a/scripts/ios/configure.sh +++ b/scripts/ios/configure.sh @@ -4,6 +4,6 @@ BOOST_VERSION=1.59.0 SQLITE_VERSION=system LIBUV_VERSION=1.7.5 ZLIB_VERSION=system -GEOJSONVT_VERSION=3.0.0 +GEOJSONVT_VERSION=3.0.1 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 diff --git a/scripts/linux/configure.sh b/scripts/linux/configure.sh index 0f7e6d167e6..0da9f8c3cd9 100644 --- a/scripts/linux/configure.sh +++ b/scripts/linux/configure.sh @@ -10,7 +10,7 @@ SQLITE_VERSION=3.9.1 LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 -GEOJSONVT_VERSION=3.0.0 +GEOJSONVT_VERSION=3.0.1 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 GTEST_VERSION=1.7.0 diff --git a/scripts/osx/configure.sh b/scripts/osx/configure.sh index d2eee364791..871b09c9413 100644 --- a/scripts/osx/configure.sh +++ b/scripts/osx/configure.sh @@ -10,7 +10,7 @@ SQLITE_VERSION=3.9.1 LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 -GEOJSONVT_VERSION=3.0.0 +GEOJSONVT_VERSION=3.0.1 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 GTEST_VERSION=1.7.0 diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 28ea69f0072..7dd5709c43f 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 3a79cb9dffb..8f1b42ea934 100644 --- a/src/mbgl/map/source_info.cpp +++ b/src/mbgl/map/source_info.cpp @@ -1,9 +1,11 @@ +#include #include #include #include #include #include +#include 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(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(std::vector{}); + } +} + 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 5b4e4e2e152..81c79bd8236 100644 --- a/src/mbgl/map/source_info.hpp +++ b/src/mbgl/map/source_info.hpp @@ -39,6 +39,7 @@ class SourceInfo : private util::noncopyable { std::unique_ptr 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 dd89b84e699..06f81a8ab2a 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -8,9 +8,6 @@ #include -#include -#include - #include 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(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(std::vector{}); - } + source.info.parseGeoJSON(dataVal); } else { Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object"); return false;