-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from CartoDB/pass-query-variables
Pass variables to replace tokens in query
- Loading branch information
Showing
6 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "catch.hpp" | ||
|
||
// mapnik | ||
#include <mapnik/map.hpp> | ||
#include <mapnik/attribute.hpp> | ||
#include <mapnik/memory_datasource.hpp> | ||
|
||
// mapnik vector tile layer class | ||
#include "vector_tile_layer.hpp" | ||
|
||
TEST_CASE("Vector tile layer class") | ||
{ | ||
SECTION("The constructor can produce a valid tile_layer with empty vars") | ||
{ | ||
mapnik::Map map(256, 256); | ||
|
||
// Create memory datasource | ||
mapnik::parameters params; | ||
params["type"] = "memory"; | ||
auto ds = std::make_shared<mapnik::memory_datasource>(params); | ||
|
||
mapnik::layer layer("layer", "+init=epsg:3857"); | ||
layer.set_datasource(ds); | ||
mapnik::box2d<double> extent(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789); | ||
const mapnik::attributes empty_vars; | ||
|
||
mapnik::vector_tile_impl::tile_layer some_layer(map, | ||
layer, | ||
extent, | ||
256, // tile_size | ||
10, // buffer_size | ||
1.0, // scale_factor | ||
0, // scale_denom | ||
0, // offset_x | ||
0, // offset_y | ||
empty_vars); | ||
CHECK(some_layer.is_valid()); | ||
} | ||
|
||
SECTION("The query has the variables passed to the constructor") | ||
{ | ||
mapnik::Map map(256, 256); | ||
|
||
// Create memory datasource | ||
mapnik::parameters params; | ||
params["type"] = "memory"; | ||
auto ds = std::make_shared<mapnik::memory_datasource>(params); | ||
|
||
mapnik::layer layer("layer", "+init=epsg:3857"); | ||
layer.set_datasource(ds); | ||
mapnik::box2d<double> extent(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789); | ||
const mapnik::attributes vars { {"zoom_level", 20} }; | ||
|
||
mapnik::vector_tile_impl::tile_layer some_layer(map, | ||
layer, | ||
extent, | ||
256, // tile_size | ||
10, // buffer_size | ||
1.0, // scale_factor | ||
0, // scale_denom | ||
0, // offset_x | ||
0, // offset_y | ||
vars); | ||
CHECK(some_layer.is_valid()); | ||
CHECK( ( vars == some_layer.get_query().variables() ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "catch.hpp" | ||
|
||
// mapnik | ||
#include <mapnik/map.hpp> | ||
#include <mapnik/attribute.hpp> | ||
#include <mapnik/memory_datasource.hpp> | ||
#include <mapnik/feature_factory.hpp> | ||
|
||
// mapnik-vector-tile | ||
#include "vector_tile_processor.hpp" | ||
#include "vector_tile_tile.hpp" | ||
|
||
|
||
TEST_CASE("feature processor - can pass variables down to layers") | ||
{ | ||
SECTION("variables are optional") | ||
{ | ||
mapnik::Map map(256, 256); | ||
mapnik::attributes empty_vars; | ||
|
||
mapnik::vector_tile_impl::processor some_processor(map); | ||
CHECK( ( empty_vars == some_processor.get_variables() ) ); | ||
} | ||
|
||
SECTION("variables can be passed down to the processor") | ||
{ | ||
mapnik::Map map(256, 256); | ||
const mapnik::attributes vars { {"zoom_level", 20} }; | ||
|
||
mapnik::vector_tile_impl::processor some_processor(map, vars); | ||
CHECK( ( vars == some_processor.get_variables() ) ); | ||
} | ||
} |