Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[test] update test suite to include more comprehensive GeoJSON tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Dec 11, 2015
1 parent 35a83ae commit 6320b4c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/android/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scripts/ios/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/linux/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/osx/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/mbgl/map/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/mbgl/map/source_info.cpp
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/map/source_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SourceInfo : private util::noncopyable {
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;
};

Expand Down
13 changes: 1 addition & 12 deletions src/mbgl/style/style_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#include <mbgl/platform/log.hpp>

#include <mapbox/geojsonvt.hpp>
#include <mapbox/geojsonvt/convert.hpp>

#include <algorithm>

namespace mbgl {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6320b4c

Please sign in to comment.