From: Pierre-Luc Beaudoin Date: Wed, 11 Mar 2009 08:41:46 +0000 (+0200) Subject: Add support for OSM Cycle Map and Osmarender tiles X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=362ebe56628741e799abd5ba0985ecea6d1001b5;p=libchamplain Add support for OSM Cycle Map and Osmarender tiles Aslo fix a bug where tiles were assumed to have 3 bytes per pixel. --- diff --git a/champlain/champlain-network-map-source.c b/champlain/champlain-network-map-source.c index efd89d2..04788e5 100644 --- a/champlain/champlain-network-map-source.c +++ b/champlain/champlain-network-map-source.c @@ -277,6 +277,26 @@ champlain_network_map_source_set_tile_uri (ChamplainNetworkMapSource *network_ma priv->uri_format = g_strdup (uri_format); } +ChamplainMapSource * +champlain_map_source_new_osm_cyclemap (void) +{ + return CHAMPLAIN_MAP_SOURCE (champlain_network_map_source_new_full ("OpenStreetMap Cycle Map", + "(CC) BY 2.0 OpenStreetMap contributors", + "http://creativecommons.org/licenses/by/2.0/", 0, 18, 256, + CHAMPLAIN_MAP_PROJECTION_MERCATOR, + "http://andy.sandbox.cloudmade.com/tiles/cycle/#Z#/#X#/#Y#.png")); +} + +ChamplainMapSource * +champlain_map_source_new_osm_osmarender (void) +{ + return CHAMPLAIN_MAP_SOURCE (champlain_network_map_source_new_full ("OpenStreetMap Osmarender", + "(CC) BY 2.0 OpenStreetMap contributors", + "http://creativecommons.org/licenses/by/2.0/", 0, 18, 256, + CHAMPLAIN_MAP_PROJECTION_MERCATOR, + "http://tah.openstreetmap.org/Tiles/tile/#Z#/#X#/#Y#.png")); +} + ChamplainMapSource * champlain_map_source_new_osm_mapnik (void) { @@ -415,15 +435,29 @@ file_loaded_cb (SoupSession *session, */ GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); ClutterActor *actor = clutter_texture_new(); - clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (actor), + gboolean ret = FALSE; + if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (actor), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), - 3, 0, NULL); + gdk_pixbuf_get_bits_per_sample (pixbuf) * + gdk_pixbuf_get_n_channels (pixbuf) / 8, + 0, &error)) + { + g_print("BPP: %d", gdk_pixbuf_get_bits_per_sample (pixbuf)); + if (error) + { + g_warning ("Unable to transfer to clutter: %s", error->message); + g_error_free (error); + create_error_tile (ctx->tile); + goto cleanup; + } + } + champlain_tile_set_actor (ctx->tile, actor); - DEBUG ("Tile loaded from network"); + DEBUG ("Tile loaded from network %d", ret); cleanup: g_object_unref (loader); diff --git a/champlain/champlain-network-map-source.h b/champlain/champlain-network-map-source.h index 7893614..1eb31f6 100644 --- a/champlain/champlain-network-map-source.h +++ b/champlain/champlain-network-map-source.h @@ -57,6 +57,8 @@ ChamplainNetworkMapSource* champlain_network_map_source_new_full (gchar *name, guint tile_size, ChamplainMapProjection projection, gchar *uri_format); ChamplainMapSource * champlain_map_source_new_osm_mapnik (void); +ChamplainMapSource * champlain_map_source_new_osm_cyclemap (void); +ChamplainMapSource * champlain_map_source_new_osm_osmarender (void); ChamplainMapSource * champlain_map_source_new_oam (void); ChamplainMapSource * champlain_map_source_new_mff_relief (void); diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c index a3a3779..4b21944 100644 --- a/demos/launcher-gtk.c +++ b/demos/launcher-gtk.c @@ -27,6 +27,8 @@ #define OSM_MAP "Open Street Map" #define OAM_MAP "Open Arial Map" #define MFF_MAP "Maps for free - Relief" +#define OSM_CYCLE "OSM Cycle Map" +#define OSM_OSMA "OSM Osmarender" /* * Terminate the main loop. @@ -90,6 +92,14 @@ map_source_changed (GtkWidget *widget, { g_object_set (G_OBJECT (view), "map-source", champlain_map_source_new_mff_relief (), NULL); } + else if (g_strcmp0 (selection, OSM_CYCLE) == 0) + { + g_object_set (G_OBJECT (view), "map-source", champlain_map_source_new_osm_cyclemap (), NULL); + } + else if (g_strcmp0 (selection, OSM_OSMA) == 0) + { + g_object_set (G_OBJECT (view), "map-source", champlain_map_source_new_osm_osmarender (), NULL); + } } static void @@ -200,6 +210,8 @@ main (int argc, gtk_combo_box_append_text(GTK_COMBO_BOX(button), OSM_MAP); gtk_combo_box_append_text(GTK_COMBO_BOX(button), OAM_MAP); gtk_combo_box_append_text(GTK_COMBO_BOX(button), MFF_MAP); + gtk_combo_box_append_text(GTK_COMBO_BOX(button), OSM_CYCLE); + gtk_combo_box_append_text(GTK_COMBO_BOX(button), OSM_OSMA); gtk_combo_box_set_active(GTK_COMBO_BOX(button), 0); g_signal_connect (button, "changed", G_CALLBACK (map_source_changed), view); gtk_container_add (GTK_CONTAINER (bbox), button);