completely ignore layers with status=off - closes #153

This commit is contained in:
Dane Springmeyer 2014-09-06 10:08:40 -07:00
parent 8b059b0d42
commit e26570dfdb
3 changed files with 46 additions and 21 deletions

View file

@ -92,6 +92,9 @@ public:
void add_attribute(const char * name, const char * value);
attribute_map const& get_attributes() const;
bool ignore() const;
void set_ignore(bool ignore) const;
bool processed() const;
void set_processed(bool processed) const;
@ -130,6 +133,7 @@ private:
bool is_text_;
unsigned line_;
mutable bool processed_;
mutable bool ignore_;
static std::string xml_text;
};

View file

@ -540,6 +540,14 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
std::string name;
try
{
optional<mapnik::boolean_type> status = node.get_opt_attr<mapnik::boolean_type>("status");
// return early is status is off
if (status && !(*status)){
node.set_ignore(true);
return;
}
name = node.get_attr("name", std::string("Unnamed"));
// If no projection is given inherit from map
@ -555,7 +563,7 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
}
layer lyr(name, srs);
optional<mapnik::boolean_type> status = node.get_opt_attr<mapnik::boolean_type>("status");
if (status)
{
lyr.set_active(* status);
@ -1656,33 +1664,35 @@ void map_parser::find_unused_nodes(xml_node const& root)
void map_parser::find_unused_nodes_recursive(xml_node const& node, std::string & error_message)
{
if (!node.processed())
if (!node.ignore())
{
if (node.is_text())
if (!node.processed())
{
error_message += "\n* text '" + node.text() + "'";
if (node.is_text())
{
error_message += "\n* text '" + node.text() + "'";
}
else
{
error_message += "\n* node '" + node.name() + "' at line " + node.line_to_string();
}
return; //All attributes and children are automatically unprocessed, too.
}
else
xml_node::attribute_map const& attrs = node.get_attributes();
for (auto const& attr : attrs)
{
error_message += "\n* node '" + node.name() + "' at line " + node.line_to_string();
if (!attr.second.processed)
{
error_message += "\n* attribute '" + attr.first +
"' with value '" + attr.second.value +
"' at line " + node.line_to_string();
}
}
return; //All attributes and children are automatically unprocessed, too.
}
xml_node::attribute_map const& attrs = node.get_attributes();
for (auto const& attr : attrs)
{
if (!attr.second.processed)
for (auto const& child_node : node)
{
error_message += "\n* attribute '" + attr.first +
"' with value '" + attr.second.value +
"' at line " + node.line_to_string();
find_unused_nodes_recursive(child_node, error_message);
}
}
for (auto const& child_node : node)
{
find_unused_nodes_recursive(child_node, error_message);
}
}
} // end of namespace mapnik

View file

@ -169,7 +169,8 @@ xml_node::xml_node(xml_tree &tree, std::string && name, unsigned line, bool is_t
name_(std::move(name)),
is_text_(is_text),
line_(line),
processed_(false) {}
processed_(false),
ignore_(false) {}
std::string xml_node::xml_text = "<xmltext>";
@ -244,6 +245,16 @@ bool xml_node::processed() const
return processed_;
}
void xml_node::set_ignore(bool ignore) const
{
ignore_ = ignore;
}
bool xml_node::ignore() const
{
return ignore_;
}
std::size_t xml_node::size() const
{
return children_.size();