/*
* Hic Est Leo -- Main Program
*
- * (c) 2014 Martin Mares <mj@ucw.cz>
+ * (c) 2014--2015 Martin Mares <mj@ucw.cz>
*/
#include <ucw/lib.h>
}
};
-// FIXME: Make generic
-static void draw_scale(struct svg *svg)
-{
- double dist = 1000;
- double width = dist * map_scale;
- double x = page_width - 10 - width;
- double y = 50;
-
- svg_push_element(svg, "g");
- svg_set_attr(svg, "id", "scale");
- svg_set_attr_format(svg, "transform", "translate(%.6g,%.6g)", x * svg->scale, y * svg->scale);
-
- for (int outline=1; outline>=0; outline--)
- {
- svg_push_element(svg, "g");
- svg_set_attr(svg, "stroke-linecap", "square");
- if (outline)
- {
- svg_set_attr_dimen(svg, "stroke-width", 1.5);
- svg_set_attr_color(svg, "stroke", 0xffffff);
- }
- else
- {
- svg_set_attr_dimen(svg, "stroke-width", 0.5);
- svg_set_attr_color(svg, "stroke", 0);
- }
-
- svg_push_element(svg, "line");
- svg_set_attr_dimen(svg, "x1", 0);
- svg_set_attr_dimen(svg, "y1", 0);
- svg_set_attr_dimen(svg, "x2", width);
- svg_set_attr_dimen(svg, "y2", 0);
- svg_pop(svg);
-
- for (int i=0; i<=10; i++)
- {
- double tick;
- switch (i)
- {
- case 0:
- case 10:
- tick = 3;
- break;
- case 5:
- tick = 2;
- break;
- default:
- tick = 1;
- }
- svg_push_element(svg, "line");
- svg_set_attr_dimen(svg, "x1", width * i/10);
- svg_set_attr_dimen(svg, "y1", 0);
- svg_set_attr_dimen(svg, "x2", width * i/10);
- svg_set_attr_dimen(svg, "y1", -tick);
- svg_pop(svg);
- }
-
- svg_pop(svg);
- }
-
- scale_text(svg, 0, 5, osm_val_encode("0"));
- scale_text(svg, width, 5, osm_val_encode("1 km"));
- svg_pop(svg);
-}
-
int main(int argc UNUSED, char **argv)
{
cf_def_file = "map.cf";
osm_init();
styles_init();
-
- msg(L_INFO, "Parsing OSM");
- osm_xml_parse(map_xml_input);
- if (debug_dump_source)
- {
- puts("=== Source data ===");
- osm_dump();
- }
- osm_make_multipolygons();
-
- msg(L_INFO, "Projecting");
- osm_project(map_projection);
- if (debug_dump_after_proj)
- {
- puts("=== Map after projection ===");
- osm_dump();
- }
-
+ map_load_styles();
+ map_load_sources();
map_set_scale();
- if (debug_dump_after_scaling)
- {
- puts("=== Map after scaling ===");
- osm_dump();
- }
-
- struct css_sheet *ss = css_load(map_style_sheet);
- if (debug_dump_css)
- {
- puts("=== Stylesheet ===");
- css_dump(ss);
- }
struct svg *svg = svg_open(map_svg_output);
if (!map_rotate)
svg_set_attr_dimen(svg, "height", page_width);
}
- struct style_results r;
- style_init(&r);
sym_init();
- msg(L_INFO, "Applying stylesheet");
- for (uns i = OSM_TYPE_NODE; i <= OSM_TYPE_MULTIPOLYGON; i++)
- CLIST_FOR_EACH(struct osm_object *, o, osm_obj_list[i])
- {
- if (debug_dump_styling)
- {
- puts("===============================");
- osm_obj_dump(o);
- }
- if (!map_object_visible_p(o))
- {
- if (debug_dump_styling)
- printf("--> invisible\n");
- continue;
- }
- style_begin(&r, o);
- css_apply(ss, &r);
- if (debug_dump_styling)
- style_dump(&r);
- sym_from_style(o, &r, svg);
- style_end(&r);
- }
+ map_apply_styles(svg);
if (map_clip)
{
svg_set_attr_format(svg, "transform", "translate(%.6g,0) rotate(90)", page_height * svg->scale);
}
- // FIXME: Replace by generic logo drawing facility
-#if 0
- struct svg_icon *logo = svg_icon_load(svg, "../logo/kocka-s-okrajem.svg");
-#endif
-
sym_draw_all(svg);
- // Draw logo
-#if 0
- double logo_width = 36.12;
- double logo_height = 36.12 / logo->width * logo->height;
- struct svg_icon_request sir = {
- .icon = logo,
- .x = page_width - 12 - logo_width / 2,
- .y = 10 + logo_height / 2,
- .width = logo_width,
- .height = logo_height,
- };
- svg_icon_put(svg, &sir);
-#endif
-
- draw_scale(svg);
-
if (map_clip)
svg_pop(svg);