diff --git a/src/vector_tile_processor.ipp b/src/vector_tile_processor.ipp index 5d677d53..92498b8a 100644 --- a/src/vector_tile_processor.ipp +++ b/src/vector_tile_processor.ipp @@ -50,6 +50,7 @@ #include #include +#include "vector_tile_strategy.hpp" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -1249,19 +1250,13 @@ unsigned processor::handle_geometry(mapnik::feature_impl const& feature, mapnik::proj_transform const& prj_trans, mapnik::box2d const& buffered_query_ext) { - mapnik::proj_backward_strategy proj_strat(prj_trans); - mapnik::view_strategy view_strat(t_); - mapnik::geometry::scale_rounding_strategy scale_strat(backend_.get_path_multiplier()); - using sg_type = mapnik::geometry::strategy_group; - sg_type sg(proj_strat, view_strat, scale_strat); + vector_tile_strategy vs(prj_trans, t_, backend_.get_path_multiplier()); mapnik::geometry::point p1_min(buffered_query_ext.minx(), buffered_query_ext.miny()); mapnik::geometry::point p1_max(buffered_query_ext.maxx(), buffered_query_ext.maxy()); - mapnik::geometry::point p2_min = mapnik::geometry::transform(p1_min, sg); - mapnik::geometry::point p2_max = mapnik::geometry::transform(p1_max, sg); + mapnik::geometry::point p2_min = mapnik::geometry::transform(p1_min, vs); + mapnik::geometry::point p2_max = mapnik::geometry::transform(p1_max, vs); box2d bbox(p2_min.x, p2_min.y, p2_max.x, p2_max.y); - mapnik::geometry::geometry new_geom = mapnik::geometry::transform(geom, sg); + mapnik::geometry::geometry new_geom = mapnik::geometry::transform(geom, vs); encoder_visitor encoder(backend_,feature,bbox, area_threshold_); if (simplify_distance_ > 0) { diff --git a/src/vector_tile_strategy.hpp b/src/vector_tile_strategy.hpp new file mode 100644 index 00000000..f88a8366 --- /dev/null +++ b/src/vector_tile_strategy.hpp @@ -0,0 +1,88 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_VECTOR_TILE_STRATEGY_HPP +#define MAPNIK_VECTOR_TILE_STRATEGY_HPP + +// mapnik +#include +#include +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-local-typedef" +#include +#include +#include +#pragma GCC diagnostic pop + + +namespace mapnik { + +namespace vector_tile_impl { + +struct vector_tile_strategy +{ + vector_tile_strategy(proj_transform const& prj_trans, + view_transform const& tr, + double scaling) + : prj_trans_(prj_trans), + tr_(tr), + scaling_(scaling) {} + + template + inline bool apply(P1 const& p1, P2 & p2) const + { + using p2_type = typename boost::geometry::coordinate_type::type; + double x = boost::geometry::get<0>(p1); + double y = boost::geometry::get<1>(p1); + double z = 0.0; + if (!prj_trans_.backward(x, y, z)) return false; + tr_.forward(&x,&y); + x = x * scaling_; + y = y * scaling_; + x = std::floor(x + 0.5); + y = std::floor(y + 0.5); + boost::geometry::set<0>(p2, static_cast(x)); + boost::geometry::set<1>(p2, static_cast(y)); + return true; + } + + template + inline P2 execute(P1 const& p1, bool & status) const + { + P2 p2; + status = apply(p1, p2); + return p2; + } + + proj_transform const& prj_trans_; + view_transform const& tr_; + double const scaling_; +}; + +} +} + +#endif // MAPNIK_VECTOR_TILE_STRATEGY_HPP