Merge branch 'Algunenano-master_overlap'

This commit is contained in:
Artem Pavlenko 2018-04-30 09:52:04 +02:00
commit d8dbe11fd0

View file

@ -150,6 +150,76 @@ private:
}; };
struct allow_overlap_visitor
{
bool operator()(point_symbolizer const&) { return true; }
bool operator()(line_symbolizer const&) { return false; }
bool operator()(line_pattern_symbolizer const&) { return false; }
bool operator()(polygon_symbolizer const&) { return false; }
bool operator()(polygon_pattern_symbolizer const&) { return false; }
bool operator()(raster_symbolizer const&) { return false; }
bool operator()(shield_symbolizer const&) { return false; }
bool operator()(text_symbolizer const&) { return true; }
bool operator()(building_symbolizer const&) { return false; }
bool operator()(markers_symbolizer const&) { return true; }
bool operator()(group_symbolizer const&) { return false; }
bool operator()(debug_symbolizer const&) { return true; } //Requires the quadtree
bool operator()(dot_symbolizer const&) { return false; }
};
// If all symbolizers declare 'allow_overlap: true' (their placement is independent
// from already placed symbols), there is no need to check collisions with subsequent
// symbolizers. To avoid building the quadtree unnecessarily we set
// the 'ignore_placement' flag
void map_apply_overlap_optimization(Map &map)
{
bool ignore_placement = true;
for (auto const & style : map.styles())
{
for (auto const & rule : style.second.get_rules())
{
for (auto const & sym : rule)
{
struct allow_overlap_visitor visitor;
if (util::apply_visitor(visitor, sym))
{
symbolizer_base const & sb = sym.get_unchecked<markers_symbolizer>();
auto prop_it = sb.properties.find(keys::allow_overlap);
if (prop_it != sb.properties.end())
{
if (prop_it->second == true)
{
continue;
}
}
ignore_placement = false;
break;
}
}
}
}
if (ignore_placement)
{
for (auto & style : map.styles())
{
for (auto & rule : style.second.get_rules_nonconst())
{
for (auto & sym : rule)
{
struct allow_overlap_visitor visitor;
if (util::apply_visitor(visitor, sym))
{
symbolizer_base & sb = sym.get_unchecked<markers_symbolizer>();
sb.properties[keys::ignore_placement] = true;
}
}
}
}
MAPNIK_LOG_DEBUG(load_map) << "setting ignore_placement=true due to all rules having allow_overlap=true";
}
}
void load_map(Map & map, std::string const& filename, bool strict, std::string base_path) void load_map(Map & map, std::string const& filename, bool strict, std::string base_path)
{ {
xml_tree tree; xml_tree tree;
@ -157,6 +227,7 @@ void load_map(Map & map, std::string const& filename, bool strict, std::string b
read_xml(filename, tree.root()); read_xml(filename, tree.root());
map_parser parser(map, strict, filename); map_parser parser(map, strict, filename);
parser.parse_map(map, tree.root(), base_path); parser.parse_map(map, tree.root(), base_path);
map_apply_overlap_optimization(map);
} }
void load_map_string(Map & map, std::string const& str, bool strict, std::string base_path) void load_map_string(Map & map, std::string const& str, bool strict, std::string base_path)
@ -172,6 +243,7 @@ void load_map_string(Map & map, std::string const& str, bool strict, std::string
} }
map_parser parser(map, strict, base_path); map_parser parser(map, strict, base_path);
parser.parse_map(map, tree.root(), base_path); parser.parse_map(map, tree.root(), base_path);
map_apply_overlap_optimization(map);
} }
void map_parser::parse_map(Map & map, xml_node const& node, std::string const& base_path) void map_parser::parse_map(Map & map, xml_node const& node, std::string const& base_path)