2 * Hic Est Leo -- Point and Icon Symbolizer
4 * (c) 2014 Martin Mares <mj@ucw.cz>
18 static void sym_point_draw(struct symbol *sym, struct svg *svg)
20 struct sym_point *p = (struct sym_point *) sym;
21 struct osm_object *o = sym->o;
22 struct osm_node *n = (struct osm_node *) o;
24 if (o->type != OSM_TYPE_NODE)
26 msg(L_ERROR, "Point symbolizer works only on nodes. It's a bug, isn't it?");
33 svg_push_element(svg, "circle");
34 svg_set_attr_dimen(svg, "cx", p->x);
35 svg_set_attr_dimen(svg, "cy", p->y);
36 svg_set_attr_dimen(svg, "r", p->size / 2);
38 // FIXME: Other shapes
40 osm_obj_warn(o, "Unknown symbol-shape %s", osm_val_decode(p->shape));
44 // FIMXE: Use COLOR_NONE instead of do_stroke and do_fill
47 svg_set_attr_color(svg, "stroke", p->stroke_color);
48 svg_set_attr_dimen(svg, "stroke-width", p->stroke_width);
49 if (p->stroke_opacity != 1)
50 svg_set_attr_float(svg, "stroke-opacity", p->stroke_opacity);
54 svg_set_attr_color(svg, "fill", p->fill_color);
55 if (p->fill_opacity != 1)
56 svg_set_attr_float(svg, "fill-opacity", p->fill_opacity);
59 svg_set_attr(svg, "fill", "none");
63 static void sym_point_gen(struct osm_object *o, struct style_info *si, struct svg *svg UNUSED)
65 if (o->type != OSM_TYPE_NODE)
68 osm_val_t shape = style_get_ident(si, PROP_SYMBOL_SHAPE);
72 struct sym_point *sp = sym_point_new(o);
76 style_get_number(si, PROP_SYMBOL_SIZE, &sp->size);
78 sp->stroke_width = 0.1;
79 sp->stroke_color = 0xffc800;
80 sp->stroke_opacity = 1;
81 if (style_get_color(si, PROP_SYMBOL_STROKE_COLOR, &sp->stroke_color) |
82 style_get_number(si, PROP_SYMBOL_STROKE_WIDTH, &sp->stroke_width))
85 style_get_number(si, PROP_SYMBOL_STROKE_OPACITY, &sp->stroke_opacity);
88 sp->fill_color = 0x0000ff;
90 if (style_get_color(si, PROP_SYMBOL_FILL_COLOR, &sp->fill_color) || !sp->do_stroke)
93 style_get_number(si, PROP_SYMBOL_FILL_OPACITY, &sp->fill_opacity);
96 labeller_add_point(&sp->s, o, sym_zindex(o, si, 4));
99 struct symbolizer symbolizer_point = {
101 .draw = sym_point_draw,
102 .gen = sym_point_gen,
105 struct sym_point *sym_point_new(struct osm_object *o)
107 return sym_new(SYMBOLIZER_POINT, o, sizeof(struct sym_point));
112 static void sym_icon_draw(struct symbol *sym, struct svg *svg)
114 struct sym_icon *i = (struct sym_icon *) sym;
115 svg_icon_put(svg, &i->sir);
118 static void sym_icon_gen(struct osm_object *o, struct style_info *si, struct svg *svg)
120 if (o->type != OSM_TYPE_NODE && o->type != OSM_TYPE_WAY && o->type != OSM_TYPE_MULTIPOLYGON)
123 osm_val_t image = style_get_string(si, PROP_ICON_IMAGE);
127 struct sym_icon *sic = sym_icon_new(o);
128 struct svg_icon *icon = svg_icon_load(svg, osm_val_decode(image));
129 struct svg_icon_request *sir = &sic->sir;
132 if (!osm_obj_center(o, &sir->x, &sir->y))
135 sir->width = icon->width;
136 sir->height = icon->height;
137 style_scale(si, &sir->width, &sir->height, PROP_ICON_WIDTH, PROP_ICON_HEIGHT);
141 // style_get_number(si, PROP_ICON_OPACITY, &sir->opacity);
146 labeller_add_point(&sic->s, o, sym_zindex(o, si, 4));
149 if (!osm_way_cyclic_p((struct osm_way *) o))
151 labeller_add_linelabel(&sic->s, o, sym_zindex(o, si, 4));
154 case OSM_TYPE_MULTIPOLYGON:
155 labeller_add_arealabel(&sic->s, o, sym_zindex(o, si, 4));
160 struct symbolizer symbolizer_icon = {
162 .draw = sym_icon_draw,
166 struct sym_icon *sym_icon_new(struct osm_object *o)
168 return sym_new(SYMBOLIZER_ICON, o, sizeof(struct sym_icon));