diff --git a/src/load_map.cpp b/src/load_map.cpp index 7b43b1c3e..5f14268f6 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -851,6 +851,25 @@ void map_parser::parse_rule(feature_type_style & style, xml_node const& r) } } +// helper method +template +void set_symbolizer_property(Symbolizer & sym, keys key, xml_node const & node) +{ + typedef T value_type; + std::string const& name = std::get<0>(get_meta(key)); + try + { + optional val = node.get_opt_attr(name); + if (val) put(sym, key, *val); + } + catch (config_error const&) + { + // try parser as an expression + optional val = node.get_opt_attr(name); + if (val) put(sym, key, *val); + } +} + void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt) { optional comp_op_name = pt.get_opt_attr("comp-op"); @@ -880,8 +899,9 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt) put(sym, keys::geometry_transform, tl); } - optional clip = pt.get_opt_attr("clip"); - if (clip) put(sym, keys::clip, *clip); + // clip + set_symbolizer_property(sym, keys::clip, pt); + // simplify algorithm optional simplify_algorithm_name = pt.get_opt_attr("simplify-algorithm"); if (simplify_algorithm_name) @@ -898,12 +918,9 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt) } // simplify value - optional simplify_tolerance = pt.get_opt_attr("simplify"); - if (simplify_tolerance) put(sym, keys::simplify_tolerance,*simplify_tolerance); - + set_symbolizer_property(sym, keys::simplify_tolerance, pt); // smooth value - optional smooth = pt.get_opt_attr("smooth"); - if (smooth) put(sym, keys::smooth, *smooth); + set_symbolizer_property(sym, keys::smooth, pt); } void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym) @@ -1289,24 +1306,12 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym) void map_parser::parse_stroke(symbolizer_base & symbol, xml_node const & sym) { - // stroke color - optional stroke = sym.get_opt_attr("stroke"); - if (stroke) put(symbol, keys::stroke, *stroke); - + // stroke + set_symbolizer_property(symbol, keys::stroke, sym); // stroke-width - try - { - optional width = sym.get_opt_attr("stroke-width"); - if (width) put(symbol, keys::stroke_width, *width); - } - catch (...) - { - optional width = sym.get_opt_attr("stroke-width"); - if (width) put(symbol, keys::stroke_width, *width); - } + set_symbolizer_property(symbol, keys::stroke_width, sym); // stroke-opacity - optional opacity = sym.get_opt_attr("stroke-opacity"); - if (opacity) put(symbol, keys::stroke_opacity, *opacity); + set_symbolizer_property(symbol, keys::stroke_opacity, sym); // stroke-linejoin optional line_join = sym.get_opt_attr("stroke-linejoin"); @@ -1368,64 +1373,49 @@ void map_parser::parse_stroke(symbolizer_base & symbol, xml_node const & sym) if (miterlimit) put(symbol, keys::stroke_miterlimit, *miterlimit); } -void map_parser::parse_line_symbolizer(rule & rule, xml_node const & sym) +void map_parser::parse_line_symbolizer(rule & rule, xml_node const & node) { try { - line_symbolizer symbol; - parse_stroke(symbol, sym); - - // offset value - optional offset = sym.get_opt_attr("offset"); - if (offset) put(symbol, keys::offset, *offset); - - optional rasterizer = sym.get_opt_attr("rasterizer"); - if (rasterizer) put(symbol, keys::line_rasterizer, line_rasterizer_enum(*rasterizer)); - - parse_symbolizer_base(symbol, sym); - rule.append(std::move(symbol)); + line_symbolizer sym; + parse_symbolizer_base(sym, node); + // stroke parameters + parse_stroke(sym, node); + // offset + set_symbolizer_property(sym, keys::offset, node); + // rasterizer + optional rasterizer = node.get_opt_attr("rasterizer"); + if (rasterizer) put(sym, keys::line_rasterizer, line_rasterizer_enum(*rasterizer)); + rule.append(std::move(sym)); } catch (config_error const& ex) { - ex.append_context(sym); + ex.append_context(node); throw; } } - -void map_parser::parse_polygon_symbolizer(rule & rule, xml_node const & sym) +void map_parser::parse_polygon_symbolizer(rule & rule, xml_node const & node) { try { - polygon_symbolizer poly_sym; + polygon_symbolizer sym; + parse_symbolizer_base(sym, node); // fill - try - { - optional fill = sym.get_opt_attr("fill"); - if (fill) put(poly_sym, keys::fill, *fill); - } - catch (...) - { - optional fill = sym.get_opt_attr("fill"); - if (fill) put(poly_sym, keys::fill, *fill); - } - + set_symbolizer_property(sym, keys::fill, node); // fill-opacity - optional opacity = sym.get_opt_attr("fill-opacity"); - if (opacity) put(poly_sym, keys::fill_opacity, *opacity); + set_symbolizer_property(sym, keys::fill_opacity, node); // gamma - optional gamma = sym.get_opt_attr("gamma"); - if (gamma) put(poly_sym, keys::gamma, *gamma); + set_symbolizer_property(sym, keys::gamma, node); // gamma method - optional gamma_method = sym.get_opt_attr("gamma-method"); - if (gamma_method) put(poly_sym, keys::gamma_method, gamma_method_enum(*gamma_method)); - - parse_symbolizer_base(poly_sym, sym); - rule.append(std::move(poly_sym)); + optional gamma_method = node.get_opt_attr("gamma-method"); + if (gamma_method) put(sym, keys::gamma_method, gamma_method_enum(*gamma_method)); + // + rule.append(std::move(sym)); } catch (config_error const& ex) { - ex.append_context(sym); + ex.append_context(node); throw; } }