From: Pierre-Luc Beaudoin Date: Sat, 23 Aug 2008 22:54:35 +0000 (-0400) Subject: map-source property X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db5ddbc5f0f2c9641794489325def324afd3536;p=libchamplain map-source property and hot switching of it --- diff --git a/champlain/champlainview.c b/champlain/champlainview.c index cd201d4..d8a48d5 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -66,6 +66,8 @@ static guint champlain_view_signals[LAST_SIGNAL] = { 0, }; struct _ChamplainViewPrivate { GtkWidget *clutterEmbed; + + ChamplainMapSource mapSource; ClutterActor *viewport; ClutterActor *fingerScroll; GdkRectangle viewportSize; @@ -102,10 +104,10 @@ champlain_view_get_property(GObject* object, guint prop_id, GValue* value, GPara g_value_set_double(value, viewport_get_current_latitude(priv)); break; case PROP_ZOOM_LEVEL: - g_value_set_int(value, priv->map->current_level->level); + //g_value_set_int(value, priv->map->current_level->level); break; case PROP_MAP_SOURCE: - //FIXME + g_value_set_int(value, priv->mapSource); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -135,10 +137,28 @@ champlain_view_set_property(GObject* object, guint prop_id, const GValue* value, break; } case PROP_ZOOM_LEVEL: - //FIXME - break; + { + //FIXME + break; + } case PROP_MAP_SOURCE: - //FIXME + { + ChamplainMapSource source = g_value_get_int(value); + if (priv->mapSource != source) + { + priv->mapSource = source; + if (priv->map) { + gint currentLevel = priv->map->current_level->level; + map_free(priv->map); + priv->map = map_new(priv->mapSource); + map_load_level(priv->map, currentLevel); + map_load_visible_tiles (priv->map, priv->viewportSize); + clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group); + } + g_print("mapsource: %d", source); + } + break; + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -171,7 +191,7 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) * * Since: 0.1 */ - g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL, + g_object_class_install_property(objectClass, PROP_LONGITUDE, g_param_spec_float("longitude", "Longitude", "The longitude coordonate of the map", @@ -187,7 +207,7 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) * * Since: 0.1 */ - g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL, + g_object_class_install_property(objectClass, PROP_LATITUDE, g_param_spec_float("latitude", "Latitude", "The latitude coordonate of the map", @@ -220,20 +240,21 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) * * Since: 0.1 */ - /* g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL, + g_object_class_install_property(objectClass, PROP_MAP_SOURCE, g_param_spec_int("map-source", "Map source", "The map source being displayed", 0, - 10, - 1.0f, - CHAMPLAIN_PARAM_READWRITE)); */ + CHAMPLAIN_MAP_SOURCE_COUNT, + CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, + CHAMPLAIN_PARAM_READWRITE)); } static void champlain_view_init (ChamplainView *champlainView) { ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + priv->mapSource = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP; } static void @@ -269,6 +290,13 @@ resize_viewport(ChamplainView *champlainView) ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + if(priv->map == NULL) + { + priv->map = map_new(priv->mapSource); + map_load_level(priv->map, 0); + clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group); + } + clutter_actor_set_size (priv->fingerScroll, priv->viewportSize.width, priv->viewportSize.height); g_object_set (G_OBJECT (priv->viewport), "sync-adjustments", FALSE, NULL); @@ -287,7 +315,7 @@ resize_viewport(ChamplainView *champlainView) g_object_set (vadjust, "lower", lower, "upper", upper, "step-increment", 1.0, "elastic", TRUE, NULL); - g_print("%d, %d, %d\n", zoom_level_get_width(priv->map->current_level), zoom_level_get_height(priv->map->current_level), sizeof(guint)); + //g_print("%d, %d, %d\n", zoom_level_get_width(priv->map->current_level), zoom_level_get_height(priv->map->current_level), sizeof(guint)); } static void @@ -345,9 +373,7 @@ champlain_view_new () clutter_container_add_actor (CLUTTER_CONTAINER (priv->fingerScroll), priv->viewport); clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->fingerScroll); - priv->map = map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP);//OPENSTREETMAP - map_load_level(priv->map, 2); - clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group); + return GTK_WIDGET (view); } @@ -423,7 +449,7 @@ champlain_view_zoom_out (ChamplainView *champlainView) { ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); ClutterActor * group = priv->map->current_level->group; - if(map_zoom_out(priv->map)) + if(map_zoom_out(priv->map)) { gint level = priv->map->current_level->level; g_print("Zoom: %d\n", level); diff --git a/champlain/champlainview.h b/champlain/champlainview.h index 1680d2a..2abb279 100644 --- a/champlain/champlainview.h +++ b/champlain/champlainview.h @@ -61,7 +61,7 @@ struct _ChamplainViewClass CHAMPLAIN_API GType champlain_view_get_type (void); -CHAMPLAIN_API GtkWidget *champlain_view_new (void); +CHAMPLAIN_API GtkWidget *champlain_view_new (); CHAMPLAIN_API void champlain_view_center_on (ChamplainView *view, gdouble longitude, gdouble latitude); diff --git a/champlain/launcher.c b/champlain/launcher.c index 8d890e1..d85c5d0 100644 --- a/champlain/launcher.c +++ b/champlain/launcher.c @@ -39,9 +39,9 @@ go_to_montreal (GtkWidget * widget, ChamplainView* view) } static void -go_to_cambridge (GtkWidget * widget, ChamplainView* view) +switch_to_openstreetmap (GtkWidget * widget, ChamplainView* view) { - champlain_view_center_on(view, 0.1258, 52.2048); + g_object_set(G_OBJECT(view), "map-source", CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, NULL); } static void @@ -87,6 +87,8 @@ main (int argc, char *argv[]) vbox = gtk_vbox_new(FALSE, 10); widget = champlain_view_new (); + g_object_set(G_OBJECT(widget), "map-source", CHAMPLAIN_MAP_SOURCE_OPENARIALMAP, NULL); + gtk_widget_set_size_request(widget, 640, 480); bbox = gtk_hbutton_box_new (); @@ -110,10 +112,10 @@ main (int argc, char *argv[]) G_CALLBACK (go_to_montreal), widget); gtk_container_add (GTK_CONTAINER (bbox), button); - button = gtk_button_new_with_label ("Cambridge"); + button = gtk_button_new_with_label ("Openstreetmap"); g_signal_connect (button, "clicked", - G_CALLBACK (go_to_cambridge), + G_CALLBACK (switch_to_openstreetmap), widget); gtk_container_add (GTK_CONTAINER (bbox), button); diff --git a/champlain/map.c b/champlain/map.c index e273412..371fd69 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -55,8 +55,6 @@ map_new (ChamplainMapSource source) void map_load_level(Map* map, gint zoom_level) { - //if(map->current_level) - guint row_count = map->get_row_count(map, zoom_level); guint column_count = map->get_column_count(map, zoom_level); @@ -156,4 +154,12 @@ map_zoom_out (Map* map) return FALSE; } - +void map_free (Map* map) +{ + int i; + for (i = 0; i < map->levels->len; i++) + { + ZoomLevel* level = g_ptr_array_index(map->levels, i); + zoom_level_free(level); + } +} diff --git a/champlain/map.h b/champlain/map.h index 24fe399..b017ee7 100644 --- a/champlain/map.h +++ b/champlain/map.h @@ -51,10 +51,11 @@ struct _Map }; -CHAMPLAIN_API Map* champlain_map_new (ChamplainMapSource source); + +Map* map_new (ChamplainMapSource source); void map_load_visible_tiles (Map* map, GdkRectangle viewport); -gboolean map_zoom_in (Map* map); +void map_free (Map* map); #endif diff --git a/champlain/tile.c b/champlain/tile.c index 53940d0..2e43208 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -181,3 +181,9 @@ tile_load (Map* map, guint zoom_level, guint x, guint y) return tile; } + +void +tile_free(Tile* tile) +{ + clutter_actor_destroy(tile->actor); +} diff --git a/champlain/tile.h b/champlain/tile.h index d880696..1fc321a 100644 --- a/champlain/tile.h +++ b/champlain/tile.h @@ -33,4 +33,6 @@ typedef struct } Tile; +void tile_free(Tile* tile); + #endif diff --git a/champlain/zoomlevel.c b/champlain/zoomlevel.c index cdec98c..4ec0c22 100644 --- a/champlain/zoomlevel.c +++ b/champlain/zoomlevel.c @@ -39,6 +39,17 @@ zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) return level; } +void +zoom_level_free(ZoomLevel* level) +{ + int i; + for (i = 0; i < level->tiles->len; i++) + { + Tile* tile = g_ptr_array_index(level->tiles, i); + tile_free(tile); + } +} + guint zoom_level_get_width(ZoomLevel* level) { diff --git a/champlain/zoomlevel.h b/champlain/zoomlevel.h index 1aa5482..806375b 100644 --- a/champlain/zoomlevel.h +++ b/champlain/zoomlevel.h @@ -41,4 +41,6 @@ guint zoom_level_get_height(ZoomLevel* level); ZoomLevel* zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size); +void zoom_level_free(ZoomLevel* level); + #endif