Skip to content

Commit

Permalink
Pass variables to replace tokens in query
Browse files Browse the repository at this point in the history
This fixes mapbox#218
  • Loading branch information
Rafa de la Torre committed Jul 17, 2017
1 parent 4e29fec commit caa85ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/vector_tile_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class tile_layer
double scale_factor,
double scale_denom,
int offset_x,
int offset_y)
int offset_y,
mapnik::attributes const& vars)
: valid_(true),
ds_(lay.datasource()),
target_proj_(map.srs(), true),
Expand All @@ -106,7 +107,7 @@ class tile_layer
layer_extent_(calc_extent(tile_size)),
target_buffered_extent_(calc_target_buffered_extent(tile_extent_bbox, buffer_size, lay, map)),
source_buffered_extent_(calc_source_buffered_extent()),
query_(calc_query(scale_factor, scale_denom, tile_extent_bbox, lay)),
query_(calc_query(scale_factor, scale_denom, tile_extent_bbox, lay, vars)),
view_trans_(layer_extent_, layer_extent_, tile_extent_bbox, offset_x, offset_y),
empty_(true),
painted_(false)
Expand Down Expand Up @@ -221,7 +222,8 @@ class tile_layer
mapnik::query calc_query(double scale_factor,
double scale_denom,
mapnik::box2d<double> const& tile_extent_bbox,
mapnik::layer const& lay)
mapnik::layer const& lay,
mapnik::attributes const& vars)
{
// Adjust the scale denominator if required
if (scale_denom <= 0.0)
Expand Down Expand Up @@ -285,6 +287,7 @@ class tile_layer
q.add_property_name(desc.get_name());
}
}
q.set_variables(vars);
return q;
}

Expand Down
7 changes: 5 additions & 2 deletions src/vector_tile_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mapnik/image_scaling.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/request.hpp>
#include <mapnik/util/noncopyable.hpp>

Expand Down Expand Up @@ -46,9 +47,10 @@ class processor : private mapnik::util::noncopyable
bool multi_polygon_union_;
bool process_all_rings_;
std::launch threading_mode_;
mapnik::attributes vars_;

public:
processor(mapnik::Map const& map)
processor(mapnik::Map const& map, mapnik::attributes const& vars = mapnik::attributes())
: m_(map),
image_format_("webp"),
scale_factor_(1.0),
Expand All @@ -59,7 +61,8 @@ class processor : private mapnik::util::noncopyable
strictly_simple_(true),
multi_polygon_union_(false),
process_all_rings_(false),
threading_mode_(std::launch::deferred) {}
threading_mode_(std::launch::deferred),
vars_(vars) {}

MAPNIK_VECTOR_INLINE void update_tile(tile & t,
double scale_denom = 0.0,
Expand Down
4 changes: 3 additions & 1 deletion src/vector_tile_processor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <mapnik/image_scaling.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/geometry_transform.hpp>

// boost
Expand Down Expand Up @@ -283,7 +284,8 @@ MAPNIK_VECTOR_INLINE void processor::update_tile(tile & t,
scale_factor_,
scale_denom,
offset_x,
offset_y);
offset_y,
vars_);
if (!tile_layers.back().is_valid())
{
t.add_empty_layer(lay.name());
Expand Down

0 comments on commit caa85ce

Please sign in to comment.