]> err.no Git - libchamplain/commitdiff
map-source property
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 23 Aug 2008 22:54:35 +0000 (18:54 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 23 Aug 2008 22:54:35 +0000 (18:54 -0400)
and hot switching of it

champlain/champlainview.c
champlain/champlainview.h
champlain/launcher.c
champlain/map.c
champlain/map.h
champlain/tile.c
champlain/tile.h
champlain/zoomlevel.c
champlain/zoomlevel.h

index cd201d4647fd98d8a07e2ea956636f07b6308f05..d8a48d5e3223aa078c1df594ae116fc5047a437c 100644 (file)
@@ -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);
index 1680d2a06de9d801d6cbcda35b13cfc9c0e51433..2abb279e7f836ca774b331d328d4fe0f745c2997 100644 (file)
@@ -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);
 
index 8d890e1eeefd2fad622c05019fb50cef02b9ea85..d85c5d0adf62c4f6908254e6372104d9e3b7de71 100644 (file)
@@ -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);
   
index e2734120e7bdea10dc252e54e42e44ff6736340c..371fd69d3c5145836285948a3bff83acda1add90 100644 (file)
@@ -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);
+    }
+}
index 24fe399a982fa6071a39c168e6c5de98ec9ac9ed..b017ee76bd8b1036b40d57811b70f2543dc1bb21 100644 (file)
@@ -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
index 53940d0d4e16651e201948cb61a27e91356eaef1..2e4320887c67876a41463bba94a89bd401e72c94 100644 (file)
@@ -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);
+}
index d880696c136c921130e622dac09fa3d3d8ecf777..1fc321a13cf14c99218ff2e71718a3345be6ace9 100644 (file)
@@ -33,4 +33,6 @@ typedef struct
   
 } Tile;
 
+void tile_free(Tile* tile);
+
 #endif
index cdec98cc19f48dbbccfd2d8151a5e224dc992c6d..4ec0c22506cb48d56d0f87e812cf9569465dd683 100644 (file)
@@ -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)
 {
index 1aa5482ab90c8d3c262bc18632557e1da9723016..806375bea1ec4c45a275af36c28239408625c8c7 100644 (file)
@@ -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