add direction property for markers

This commit is contained in:
Jiri Drbalek 2015-01-19 13:47:46 +00:00
parent 87cc1347c7
commit 1cd5e69b3a
13 changed files with 91 additions and 2 deletions

View file

@ -90,7 +90,8 @@ struct vector_markers_dispatch : util::noncopyable
coord2d center = src_->bounding_box().center();
agg::trans_affine_translation recenter(-center.x, -center.y);
agg::trans_affine tr = recenter * marker_trans_;
markers_placement_params params { src_->bounding_box(), tr, spacing * scale_factor_, max_error, allow_overlap, avoid_edges };
direction_enum direction = get<direction_enum, keys::direction>(sym_, feature_, vars_);
markers_placement_params params { src_->bounding_box(), tr, spacing * scale_factor_, max_error, allow_overlap, avoid_edges, direction };
markers_placement_finder<T, Detector> placement_finder(
placement_method, path, detector_, params);
double x, y, angle = .0;
@ -147,7 +148,8 @@ struct raster_markers_dispatch : util::noncopyable
value_double spacing = get<value_double, keys::spacing>(sym_, feature_, vars_);
value_double max_error = get<value_double, keys::max_error>(sym_, feature_, vars_);
box2d<double> bbox(0,0, src_.width(),src_.height());
markers_placement_params params { bbox, marker_trans_, spacing * scale_factor_, max_error, allow_overlap, avoid_edges };
direction_enum direction = get<direction_enum, keys::direction>(sym_, feature_, vars_);
markers_placement_params params { bbox, marker_trans_, spacing * scale_factor_, max_error, allow_overlap, avoid_edges, direction };
markers_placement_finder<T, label_collision_detector4> placement_finder(
placement_method, path, detector_, params);
double x, y, angle = .0;

View file

@ -97,6 +97,10 @@ public:
x = pos.x;
y = pos.y;
angle = path_.current_segment_angle();
if (!this->set_direction(angle))
{
continue;
}
box2d<double> box = this->perform_transform(angle, x, y);
if ((this->params_.avoid_edges && !this->detector_.extent().contains(box))
|| (!this->params_.allow_overlap && !this->detector_.has_placement(box)))

View file

@ -24,6 +24,7 @@
#define MAPNIK_MARKERS_PLACEMENTS_POINT_HPP
#include <mapnik/geom_util.hpp>
#include <mapnik/util/math.hpp>
#include "agg_basics.h"
#include "agg_trans_affine.h"
@ -38,6 +39,7 @@ struct markers_placement_params
double max_error;
bool allow_overlap;
bool avoid_edges;
direction_enum direction;
};
template <typename Locator, typename Detector>
@ -141,6 +143,36 @@ protected:
result.expand_to_include(xD, yD);
return result;
}
bool set_direction(double & angle)
{
switch (params_.direction)
{
case DIRECTION_UP:
angle = .0;
return true;
case DIRECTION_DOWN:
angle = M_PI;
return true;
case DIRECTION_AUTO:
angle = (std::fabs(util::normalize_angle(angle)) > 0.5 * M_PI) ? (angle + M_PI) : angle;
return true;
case DIRECTION_AUTO_DOWN:
angle = (std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI) ? (angle + M_PI) : angle;
return true;
case DIRECTION_LEFT:
angle += M_PI;
return true;
case DIRECTION_LEFT_ONLY:
angle += M_PI;
return std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI;
case DIRECTION_RIGHT_ONLY:
return std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI;
case DIRECTION_RIGHT:
default:
return true;
}
}
};
}

View file

@ -69,6 +69,10 @@ public:
if (agg::is_line_to(this->locator_.vertex(&x1, &y1)))
{
angle = std::atan2(y1 - y0, x1 - x0);
if (!this->set_direction(angle))
{
return false;
}
}
box2d<double> box = this->perform_transform(angle, x, y);

View file

@ -74,6 +74,10 @@ public:
if (agg::is_line_to(command1))
{
angle = std::atan2(y0 - y1, x0 - x1);
if (!this->set_direction(angle))
{
return false;
}
}
box2d<double> box = this->perform_transform(angle, x, y);

View file

@ -91,6 +91,7 @@ enum class property_types : std::uint8_t
target_justify_alignment,
target_vertical_alignment,
target_upright,
target_direction,
target_font_feature_settings
};
@ -184,6 +185,7 @@ ENUM_FROM_STRING( horizontal_alignment_enum )
ENUM_FROM_STRING( justify_alignment_enum )
ENUM_FROM_STRING( text_transform_enum )
ENUM_FROM_STRING( text_upright_enum )
ENUM_FROM_STRING( direction_enum )
ENUM_FROM_STRING( gamma_method_enum )
// enum

View file

@ -329,6 +329,13 @@ struct symbolizer_default<marker_multi_policy_enum, keys::markers_multipolicy>
static marker_multi_policy_enum value() { return MARKER_EACH_MULTI; }
};
// direction
template <>
struct symbolizer_default<direction_enum, keys::direction>
{
static direction_enum value() { return DIRECTION_RIGHT; }
};
// placement
// colorizer

View file

@ -189,6 +189,21 @@ enum text_upright_enum : std::uint8_t
DEFINE_ENUM(text_upright_e, text_upright_enum);
enum direction_enum : std::uint8_t
{
DIRECTION_LEFT,
DIRECTION_RIGHT,
DIRECTION_LEFT_ONLY,
DIRECTION_RIGHT_ONLY,
DIRECTION_AUTO,
DIRECTION_AUTO_DOWN,
DIRECTION_UP,
DIRECTION_DOWN,
direction_enum_MAX
};
DEFINE_ENUM(direction_e, direction_enum);
enum gamma_method_enum : std::uint8_t
{
GAMMA_POWER, //agg::gamma_power

View file

@ -89,6 +89,7 @@ enum class keys : std::uint8_t
justify_alignment,
vertical_alignment,
upright,
direction,
avoid_edges,
ff_settings,
MAX_SYMBOLIZER_KEY

View file

@ -996,6 +996,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node)
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::image_transform, node);
set_symbolizer_property<symbolizer_base,marker_placement_enum>(sym, keys::markers_placement_type, node);
set_symbolizer_property<symbolizer_base,marker_multi_policy_enum>(sym, keys::markers_multipolicy, node);
set_symbolizer_property<symbolizer_base,direction_enum>(sym, keys::direction, node);
parse_stroke(sym,node);
rule.append(std::move(sym));
}

View file

@ -177,6 +177,19 @@ static const char * text_upright_strings[] = {
};
IMPLEMENT_ENUM(text_upright_e, text_upright_strings)
static const char * direction_strings[] = {
"left",
"right",
"left-only",
"right-only",
"auto",
"auto-down",
"up",
"down",
""
};
IMPLEMENT_ENUM(direction_e, direction_strings)
static const char * gamma_method_strings[] = {
"power", //agg::gamma_power
"linear", //agg::gamma_linear

View file

@ -157,6 +157,9 @@ static const property_meta_type key_meta[const_max_key] =
property_meta_type{ "upright", [](enumeration_wrapper e)
{return enumeration<text_upright_enum,text_upright_enum_MAX>(text_upright_enum(e.value)).as_string();},
property_types::target_upright},
property_meta_type{ "direction", [](enumeration_wrapper e)
{return enumeration<direction_enum,direction_enum_MAX>(direction_enum(e.value)).as_string();},
property_types::target_direction},
property_meta_type{ "avoid-edges",nullptr, property_types::target_bool },
property_meta_type{ "font-feature-settings", nullptr, property_types::target_font_feature_settings },

View file

@ -427,6 +427,7 @@ compile_get_opt_attr(vertical_alignment_e);
compile_get_opt_attr(horizontal_alignment_e);
compile_get_opt_attr(justify_alignment_e);
compile_get_opt_attr(text_upright_e);
compile_get_opt_attr(direction_e);
compile_get_opt_attr(halo_rasterizer_e);
compile_get_opt_attr(expression_ptr);
compile_get_opt_attr(font_feature_settings);