2 * Hic Est Leo -- Map Scale Symbolizer
4 * (c) 2014--2015 Martin Mares <mj@ucw.cz>
12 static void sym_scale_draw(struct symbol *sym, struct svg *svg)
14 struct sym_scale *sc = (struct sym_scale *) sym;
16 double width = dist * map_scale;
17 struct osm_node *n = (struct osm_node *) sym->o;
19 svg_push_element(svg, "g");
20 // svg_set_attr(svg, "id", "scale");
21 svg_set_attr_format(svg, "transform", "translate(%s,%s)", svg_format_dimen(svg, n->x), svg_format_dimen(svg, n->y));
23 for (int outline=1; outline>=0; outline--)
25 svg_push_element(svg, "g");
26 svg_set_attr(svg, "stroke-linecap", "square");
29 svg_set_attr_dimen(svg, "stroke-width", sc->width + sc->casing_width);
30 svg_set_attr_color(svg, "stroke", sc->casing_color);
34 svg_set_attr_dimen(svg, "stroke-width", sc->width);
35 svg_set_attr_color(svg, "stroke", sc->color);
38 svg_push_element(svg, "line");
39 svg_set_attr_dimen(svg, "x1", 0);
40 svg_set_attr_dimen(svg, "y1", 0);
41 svg_set_attr_dimen(svg, "x2", width);
42 svg_set_attr_dimen(svg, "y2", 0);
45 for (int i=0; i<=10; i++)
60 tick *= sc->tick_length;
61 svg_push_element(svg, "line");
62 svg_set_attr_dimen(svg, "x1", width * i/10);
63 svg_set_attr_dimen(svg, "y1", 0);
64 svg_set_attr_dimen(svg, "x2", width * i/10);
65 svg_set_attr_dimen(svg, "y1", -tick);
72 scale_text(svg, 0, 5, osm_val_encode("0"));
73 scale_text(svg, width, 5, osm_val_encode("1 km"));
77 static void sym_scale_gen(struct osm_object *o, struct style_info *si, struct svg *svg UNUSED)
79 if (o->type != OSM_TYPE_NODE)
80 die("Map scale must be a node");
82 struct sym_scale *sc = sym_scale_new(o);
85 style_get_number(si, PROP_WIDTH, &sc->width);
88 style_get_color(si, PROP_COLOR, &sc->color);
90 sc->casing_width = 0.5;
91 style_get_number(si, PROP_CASING_WIDTH, &sc->casing_width);
93 sc->casing_color = 0xffffff;
94 style_get_color(si, PROP_CASING_COLOR, &sc->casing_color);
97 style_get_number(si, PROP_TICK_LENGTH, &sc->tick_length);
99 sym_plan(&sc->s, sym_zindex(o, si, 4));
102 struct symbolizer symbolizer_scale = {
104 .draw = sym_scale_draw,
105 .gen = sym_scale_gen,
106 .special = VALUE_SCALE,
109 struct sym_scale *sym_scale_new(struct osm_object *o)
111 return sym_new(SYMBOLIZER_SCALE, o, sizeof(struct sym_scale));