From: Pierre-Luc Beaudoin Date: Tue, 3 Mar 2009 20:49:51 +0000 (+0200) Subject: Introduce champlain_view_set_map_source X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5dcfd0d43451e263a4e2f31d007fe034265c878;p=libchamplain Introduce champlain_view_set_map_source --- diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index da932c7..555356b 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -504,42 +504,7 @@ champlain_view_set_property (GObject *object, case PROP_MAP_SOURCE: { ChamplainMapSource *source = g_value_get_object (value); - - if (priv->map_source != source) - { - g_object_unref (priv->map_source); - priv->map_source = g_object_ref (source); - if (priv->map) - { - ClutterActor *group; - - group = champlain_zoom_level_get_actor (priv->map->current_level); - clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), - group); - - map_free (priv->map); - priv->map = map_new (); - - /* Keep same zoom level if the new map supports it */ - if (priv->zoom_level > champlain_map_source_get_max_zoom_level (priv->map_source)) - { - priv->zoom_level = champlain_map_source_get_max_zoom_level (priv->map_source); - g_object_notify (G_OBJECT (view), "zoom-level"); - } - - map_load_level (priv->map, priv->map_source, priv->zoom_level); - group = champlain_zoom_level_get_actor (priv->map->current_level); - - view_load_visible_tiles (view); - clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), - group); - - update_license (view); - g_idle_add (marker_reposition, view); - view_tiles_reposition (view); - champlain_view_center_on (view, priv->latitude, priv->longitude); - } - } + champlain_view_set_map_source (view, source); break; } case PROP_SCROLL_MODE: @@ -1261,3 +1226,58 @@ champlain_view_tile_ready (ChamplainView *view, clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)), actor, NULL); view_position_tile (view, tile); } + +/** + * champlain_view_set_map_source: + * @view: a #ChamplainView + * @source: a #ChamplainMapSource + * + * Changes the currently used map source. #g_object_unref will be called on + * the previous one. + * + * Since: 0.4 + */ +void +champlain_view_set_map_source (ChamplainView *view, + ChamplainMapSource *source) +{ + g_return_if_fail (CHAMPLAIN_IS_VIEW (view) || + CHAMPLAIN_IS_MAP_SOURCE (source)); + + ClutterActor *group; + + ChamplainViewPrivate *priv = GET_PRIVATE (view); + + if (priv->map_source == source) + return; + + g_object_unref (priv->map_source); + priv->map_source = g_object_ref (source); + + if (priv->map == NULL) + return; + + group = champlain_zoom_level_get_actor (priv->map->current_level); + clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); + + map_free (priv->map); + priv->map = map_new (); + + /* Keep same zoom level if the new map supports it */ + if (priv->zoom_level > champlain_map_source_get_max_zoom_level (priv->map_source)) + { + priv->zoom_level = champlain_map_source_get_max_zoom_level (priv->map_source); + g_object_notify (G_OBJECT (view), "zoom-level"); + } + + map_load_level (priv->map, priv->map_source, priv->zoom_level); + group = champlain_zoom_level_get_actor (priv->map->current_level); + + view_load_visible_tiles (view); + clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), group); + + update_license (view); + g_idle_add (marker_reposition, view); + view_tiles_reposition (view); + champlain_view_center_on (view, priv->latitude, priv->longitude); +} diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h index 3a213c7..56a3507 100644 --- a/champlain/champlain-view.h +++ b/champlain/champlain-view.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -76,6 +77,8 @@ void champlain_view_zoom_out (ChamplainView *champlainView); void champlain_view_set_zoom_level (ChamplainView *champlainView, gint zoom_level); +void champlain_view_set_map_source (ChamplainView *champlainView, ChamplainMapSource *map_source); + void champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer); void champlain_view_set_size (ChamplainView *view, guint width, guint height);