+
+void map_load_styles(void)
+{
+ clist style_cache;
+ clist_init(&style_cache);
+
+ CLIST_FOR_EACH(struct data_source *, ds, map_sources)
+ {
+ CLIST_FOR_EACH(struct data_source_style *, ss, ds->styles)
+ {
+ CLIST_FOR_EACH(struct simp_node *, n, style_cache)
+ {
+ struct data_source_style *x = n->p;
+ if (!strcmp(x->name, ss->name))
+ {
+ ss->css = x->css;
+ break;
+ }
+ }
+ if (!ss->css)
+ {
+ msg(L_DEBUG, "Loading style sheet %s", ss->name);
+ ss->css = css_load(ss->name);
+
+ if (debug_dump_css)
+ {
+ printf("=== Stylesheet %s ===", ss->name);
+ css_dump(ss->css);
+ }
+
+ simp_append(cf_get_pool(), &style_cache)->p = ss;
+ }
+ }
+ }
+}
+
+static void map_load_source(struct data_source *ds)
+{
+ ds->osm = osm_init();
+
+ bool need_mp = 0;
+ bool need_proj = 0;
+
+ switch (ds->format)
+ {
+ case DATA_SOURCE_OSMXML:
+ msg(L_INFO, "Parsing %s as OSM XML", ds->file);
+ if (!ds->file)
+ die("OSM XML data sources must have a file name");
+ osm_xml_parse(ds->file);
+ need_mp = 1;
+ need_proj = 1;
+ break;
+ case DATA_SOURCE_FIXED:
+ msg(L_INFO, "Adding fixed objects");
+ if (!ds->file)
+ ds->file = "fixed";
+ fixed_add();
+ break;
+ case DATA_SOURCE_SHAPE:
+ msg(L_INFO, "Parsing %s as shape file", ds->file);
+ if (!ds->file)
+ die("Shape data sources must have a file name");
+ shp_parse(ds->file);
+ need_proj = 1;
+ break;
+ default:
+ die("Invalid data source format");
+ }
+
+ osm_stats();
+ if (debug_dump_source)
+ {
+ puts("=== Source data ===");
+ osm_dump();
+ }
+ if (need_mp)
+ osm_make_multipolygons();
+
+ if (need_proj)
+ {
+ msg(L_INFO, "Projecting");
+ osm_project(map_projection);
+ if (debug_dump_after_proj)
+ {
+ puts("=== Map after projection ===");
+ osm_dump();
+ }
+ }
+}
+
+void map_load_sources(void)
+{
+ CLIST_FOR_EACH(struct data_source *, ds, map_sources)
+ map_load_source(ds);
+}
+
+void map_apply_styles(struct svg *svg)
+{
+ struct style_results r;
+ style_init(&r);
+
+ CLIST_FOR_EACH(struct data_source *, ds, map_sources)
+ {
+ msg(L_INFO, "Applying stylesheet on %s", ds->file);
+ for (uns i = OSM_TYPE_NODE; i <= OSM_TYPE_MULTIPOLYGON; i++)
+ CLIST_FOR_EACH(struct osm_object *, o, ds->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);
+ CLIST_FOR_EACH(struct data_source_style *, ss, ds->styles)
+ css_apply(ss->css, &r);
+ if (debug_dump_styling)
+ style_dump(&r);
+ sym_from_style(o, &r, svg);
+ style_end(&r);
+ }
+ }
+
+ // FIXME: Ought to destroy the style_results
+}