libchamplain Documentation

Back to libchamplain's wiki

It is easy to use. Look at the following example. With this code you get a fully functional application with the map widget covering the whole window. You can zoom in and out with your mouse wheel and scroll the view by dragging it. The tiles are downloaded automatically from the network and cached on your disk so they will be available next time even if you are offline.

Notice that only two lines of the code below are specific to libchamplain - the include header and then the call of the constructor of the widget - the rest is just the ordinary boilerplate code you would write for any clutter-based application.

#include <clutter-gtk/clutter-gtk.h>

main (int argc, char *argv[])
  GtkWidget *window, *widget;

  /* initialize clutter */
  if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  /* create the top-level window and quit the main loop when it's closed */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

  /* create the libchamplain widget and set its size */
  widget = gtk_champlain_embed_new ();
  gtk_widget_set_size_request (widget, 640, 480);

  /* insert it into the widget you wish */
  gtk_container_add (GTK_CONTAINER (window), widget);

  /* show everything */
  gtk_widget_show_all (window);

  /* start the main loop */
  gtk_main ();

  return 0;

If you save the above code to a file, say champlain.c, you can compile the application (after installing libchamplain first of course) by running:

gcc -o champlain champlain.c `pkg-config --cflags --libs champlain-gtk-0.12` 

Until further examples and tutorials are written, please have a look at the API documentation and the examples shipped with the source code.

Projects/libchamplain/documentation (last edited 2013-12-18 11:24:50 by WilliamJonMcCann)