summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-17 18:50:21 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-17 18:50:21 -0700
commitd61c6697d212c75462e297411bb99b942a433610 (patch)
treecae8035494ed08910ffd103a9bc52907d3f33e8e
parentde1422518562d219600ddacfce9647e7c5db401b (diff)
downloadqtlocation-mapboxgl-d61c6697d212c75462e297411bb99b942a433610.tar.gz
[core] API Render test for CustomVectorSource
-rw-r--r--cmake/test-files.cmake1
-rw-r--r--src/mbgl/style/custom_tile_loader.cpp7
-rw-r--r--test/api/custom_vector_source.test.cpp72
-rw-r--r--test/fixtures/custom_vector_source/grid/expected.pngbin0 -> 8302 bytes
4 files changed, 77 insertions, 3 deletions
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake
index 8d3e8bd346..3e1dbb8fd0 100644
--- a/cmake/test-files.cmake
+++ b/cmake/test-files.cmake
@@ -16,6 +16,7 @@ set(MBGL_TEST_FILES
test/api/annotations.test.cpp
test/api/api_misuse.test.cpp
test/api/custom_layer.test.cpp
+ test/api/custom_vector_source.test.cpp
test/api/query.test.cpp
test/api/recycle_map.cpp
test/api/zoom_history.cpp
diff --git a/src/mbgl/style/custom_tile_loader.cpp b/src/mbgl/style/custom_tile_loader.cpp
index b7120a2a5c..09d43373d6 100644
--- a/src/mbgl/style/custom_tile_loader.cpp
+++ b/src/mbgl/style/custom_tile_loader.cpp
@@ -10,9 +10,7 @@ CustomTileLoader::CustomTileLoader(const TileFunction& fetchTileFn, const TileFu
void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
auto cachedTileData = dataCache.find(tileID.canonical);
- if (cachedTileData == dataCache.end()) {
- invokeTileFetch(tileID.canonical);
- } else {
+ if (cachedTileData != dataCache.end()) {
callbackRef.invoke(&SetTileDataFunction::operator(), *(cachedTileData->second));
}
auto tileCallbacks = tileCallbackMap.find(tileID.canonical);
@@ -28,6 +26,9 @@ void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTil
}
tileCallbacks->second.emplace_back(std::make_tuple(tileID.overscaledZ, tileID.wrap, callbackRef));
}
+ if (cachedTileData == dataCache.end()) {
+ invokeTileFetch(tileID.canonical);
+ }
}
void CustomTileLoader::cancelTile(const OverscaledTileID& tileID) {
diff --git a/test/api/custom_vector_source.test.cpp b/test/api/custom_vector_source.test.cpp
new file mode 100644
index 0000000000..76445c1500
--- /dev/null
+++ b/test/api/custom_vector_source.test.cpp
@@ -0,0 +1,72 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/gl/gl.hpp>
+#include <mbgl/map/map.hpp>
+#include <mbgl/util/default_thread_pool.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/gl/headless_frontend.hpp>
+#include <mbgl/style/style.hpp>
+#include <mbgl/style/sources/custom_vector_source.hpp>
+#include <mbgl/style/layers/fill_layer.hpp>
+#include <mbgl/style/layers/line_layer.hpp>
+#include <mbgl/util/geojson.hpp>
+#include <mbgl/util/io.hpp>
+#include <mbgl/util/mat4.hpp>
+#include <mbgl/util/run_loop.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+
+TEST(CustomVectorSource, Grid) {
+ util::RunLoop loop;
+
+ DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
+ ThreadPool threadPool(4);
+ float pixelRatio { 1 };
+ HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
+ threadPool, MapMode::Still);
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ map.setLatLngZoom({ 37.8, -122.5 }, 10);
+
+ CustomVectorSource::Options options;
+ options.fetchTileFunction = [&map](const mbgl::CanonicalTileID& tileID) {
+ double gridSpacing = 0.1;
+ FeatureCollection features;
+ const LatLngBounds bounds(tileID);
+ for (double y = ceil(bounds.north() / gridSpacing) * gridSpacing; y >= floor(bounds.south() / gridSpacing) * gridSpacing; y -= gridSpacing) {
+
+ mapbox::geojson::line_string gridLine;
+ gridLine.emplace_back(bounds.west(), y);
+ gridLine.emplace_back(bounds.east(), y);
+
+ features.emplace_back(gridLine);
+ }
+
+ for (double x = floor(bounds.west() / gridSpacing) * gridSpacing; x <= ceil(bounds.east() / gridSpacing) * gridSpacing; x += gridSpacing) {
+ mapbox::geojson::line_string gridLine;
+ gridLine.emplace_back(x, bounds.south());
+ gridLine.emplace_back(x, bounds.north());
+
+ features.emplace_back(gridLine);
+ }
+ auto source = static_cast<CustomVectorSource *>(map.getStyle().getSource("custom"));
+ if (source) {
+ source->setTileData(tileID, features);
+ }
+ };
+
+ map.getStyle().addSource(std::make_unique<CustomVectorSource>("custom", options));
+
+ auto fillLayer = std::make_unique<FillLayer>("landcover", "mapbox");
+ fillLayer->setSourceLayer("landcover");
+ fillLayer->setFillColor(Color{ 1.0, 1.0, 0.0, 1.0 });
+ map.getStyle().addLayer(std::move(fillLayer));
+
+ auto layer = std::make_unique<LineLayer>("grid", "custom");
+ layer->setLineColor(Color{ 1.0, 1.0, 1.0, 1.0 });
+ map.getStyle().addLayer(std::move(layer));
+
+ test::checkImage("test/fixtures/custom_vector_source/grid", frontend.render(map), 0.0006, 0.1);
+}
diff --git a/test/fixtures/custom_vector_source/grid/expected.png b/test/fixtures/custom_vector_source/grid/expected.png
new file mode 100644
index 0000000000..628a3b11fb
--- /dev/null
+++ b/test/fixtures/custom_vector_source/grid/expected.png
Binary files differ