source: trunk/demos/tile-renderer.c @ 142

Last change on this file since 142 was 142, checked in by simon, 5 years ago

Add an autotools based build system

  • moved all code to the src directory
  • generates pkg-config files

remove memphis-uninstalled.pc.in

File size: 2.5 KB
Line 
1/*
2 * Memphis - Cairo Rederer for OSM in C
3 * Copyright (C) 2009  Simon Wenner <simon@wenner.ch>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include "src/memphis.h"
21#include <stdlib.h>
22
23#define RESOLUTION 256
24
25int main (int argc, char **argv) {
26  g_type_init ();
27 
28  MemphisRenderer *r;
29  MemphisRuleSet *rules;
30  MemphisMap *map;
31  cairo_surface_t *surface;
32  cairo_t *cr;
33  gint i, j, maxx, maxy;
34  gchar *path, *mapfile;
35  gint zoom_level;
36
37  if (argc > 1)
38    zoom_level = atoi(argv[1]);
39  else
40    zoom_level = 14;
41
42  if (argc > 2)
43    mapfile = argv[2];
44  else
45    mapfile = "map.osm";
46
47  rules = memphis_rule_set_new ();
48  memphis_rule_set_load_from_file (rules, "rule.xml");
49  map = memphis_map_new ();
50  memphis_map_load_from_file (map, mapfile);
51
52  r = memphis_renderer_new_full (rules, map);
53  memphis_renderer_set_resolution (r, RESOLUTION);
54  memphis_renderer_set_debug_level (r, 1);
55  g_print ("Tile resolution: %u\n", memphis_renderer_get_resolution (r));
56
57  maxx = memphis_renderer_get_max_x_tile (r, zoom_level);
58  maxy = memphis_renderer_get_max_y_tile (r, zoom_level);
59  i = memphis_renderer_get_min_x_tile (r, zoom_level);
60 
61  for (; i <= maxx; i++)
62    {
63      j = memphis_renderer_get_min_y_tile (r, zoom_level);
64      for (; j <= maxy; j++)
65        {
66          surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
67              RESOLUTION, RESOLUTION);
68          cr =  cairo_create(surface);
69          path = g_strdup_printf ("tiles/%i_%i.png", i, j);
70
71          g_print ("Drawing tile: %i, %i\n", i, j);
72          memphis_renderer_draw_tile (r, cr, i, j, zoom_level);
73          cairo_surface_write_to_png(surface, path);
74         
75          g_free (path);
76          cairo_destroy(cr);
77          cairo_surface_destroy(surface);
78        }
79    }
80 
81  memphis_renderer_free (r);
82  memphis_map_free (map);
83  memphis_rule_set_free (rules);
84
85  return 0;
86}
Note: See TracBrowser for help on using the repository browser.