#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace mbgl; using namespace mbgl::style; TEST(CustomGeometrySource, Grid) { util::RunLoop loop; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); auto threadPool = sharedThreadPool(); float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, *threadPool }; Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, *threadPool, MapOptions().withMapMode(MapMode::Static)); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0)); CustomGeometrySource::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(map.getStyle().getSource("custom")); if (source) { source->setTileData(tileID, features); } }; map.getStyle().addSource(std::make_unique("custom", options)); auto fillLayer = std::make_unique("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("grid", "custom"); layer->setLineColor(Color{ 1.0, 1.0, 1.0, 1.0 }); map.getStyle().addLayer(std::move(layer)); test::checkImage("test/fixtures/custom_geometry_source/grid", frontend.render(map), 0.0006, 0.1); }