2 * Hic Est Leo -- Map Scale Symbolizer
4 * (c) 2014--2015 Martin Mares <mj@ucw.cz>
14 static void sym_scale_draw(struct symbol *sym, struct svg *svg)
16 struct sym_scale *sc = (struct sym_scale *) sym;
18 double width = dist * map_scale;
19 struct osm_node *n = (struct osm_node *) sym->o;
21 svg_push_element(svg, "g");
22 // svg_set_attr(svg, "id", "scale");
23 svg_set_attr_format(svg, "transform", "translate(%s,%s)", svg_format_dimen(svg, n->x), svg_format_dimen(svg, n->y));
25 for (int outline=1; outline>=0; outline--)
27 svg_push_element(svg, "g");
28 svg_set_attr(svg, "stroke-linecap", "square");
31 svg_set_attr_dimen(svg, "stroke-width", sc->width + sc->casing_width);
32 svg_set_attr_color(svg, "stroke", sc->casing_color);
36 svg_set_attr_dimen(svg, "stroke-width", sc->width);
37 svg_set_attr_color(svg, "stroke", sc->color);
40 svg_push_element(svg, "line");
41 svg_set_attr_dimen(svg, "x1", 0);
42 svg_set_attr_dimen(svg, "y1", 0);
43 svg_set_attr_dimen(svg, "x2", width);
44 svg_set_attr_dimen(svg, "y2", 0);
47 for (int i=0; i<=10; i++)
62 tick *= sc->tick_length;
63 svg_push_element(svg, "line");
64 svg_set_attr_dimen(svg, "x1", width * i/10);
65 svg_set_attr_dimen(svg, "y1", 0);
66 svg_set_attr_dimen(svg, "x2", width * i/10);
67 svg_set_attr_dimen(svg, "y1", -tick);
74 scale_text(svg, 0, 5, osm_val_encode("0"));
75 scale_text(svg, width, 5, osm_val_encode("1 km"));
79 static void sym_scale_gen(struct osm_object *o, struct style_info *si, struct svg *svg UNUSED)
81 if (o->type != OSM_TYPE_NODE)
82 die("Map scale must be a node");
84 struct sym_scale *sc = sym_scale_new(o);
87 style_get_number(si, PROP_WIDTH, &sc->width);
90 style_get_color(si, PROP_COLOR, &sc->color);
92 sc->casing_width = 0.5;
93 style_get_number(si, PROP_CASING_WIDTH, &sc->casing_width);
95 sc->casing_color = 0xffffff;
96 style_get_color(si, PROP_CASING_COLOR, &sc->casing_color);
99 style_get_number(si, PROP_TICK_LENGTH, &sc->tick_length);
101 sym_plan(&sc->s, sym_zindex(o, si, 4));
104 struct symbolizer symbolizer_scale = {
106 .draw = sym_scale_draw,
107 .gen = sym_scale_gen,
108 .special = VALUE_SCALE,
111 struct sym_scale *sym_scale_new(struct osm_object *o)
113 return sym_new(SYMBOLIZER_SCALE, o, sizeof(struct sym_scale));