]> saetta.ns0.it Git - libgtkgis/commitdiff
Added GtkGis::zoom_to_extent (not complete).
authorAndrea Zagli <azagli@libero.it>
Thu, 6 Aug 2009 20:47:06 +0000 (22:47 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 6 Aug 2009 20:47:06 +0000 (22:47 +0200)
Added GtkGis::move_to.
Implemented layer's visibility (yes or not).

14 files changed:
docs/reference/libgtkgis-decl-list.txt
docs/reference/libgtkgis-decl.txt
docs/reference/libgtkgis-undocumented.txt
docs/reference/libgtkgis-unused.txt
docs/reference/tmpl/commons.sgml
src/commons.h
src/gtkgis.c
src/gtkgis.h
src/layer.c
src/layer.h
src/layersource.c
src/layersource.h
tests/from_xml.c
tests/test1.gtkgis

index 3d4d57a1362bfa2fbf91c0271afe4ee34a50cd17..4297a6051a2e5236fad2b4b70b0ddf03fb500177 100644 (file)
@@ -74,8 +74,10 @@ gtk_gis_get_layer_by_name
 gtk_gis_draw
 gtk_gis_get_scale
 gtk_gis_set_scale
+gtk_gis_zoom_to_extent
 gtk_gis_zoom_to_max
 gtk_gis_zoom_to_layer
+gtk_gis_move_to
 gtk_gis_get_legend
 </SECTION>
 
@@ -118,6 +120,8 @@ gtk_gis_layer_save
 gtk_gis_layer_add_geometry
 gtk_gis_layer_remove_geometry
 gtk_gis_layer_get_extent
+gtk_gis_layer_get_visible
+gtk_gis_layer_set_visible
 gtk_gis_layer_get_editable
 gtk_gis_layer_set_editable
 gtk_gis_layer_get_style
index f93f13516650c732efd5c0c451640185e9f63414..099171ab4b97c58be8cff1493eca22166a1b7a11 100644 (file)
@@ -325,6 +325,11 @@ GtkGis *gtkgis
 GtkGis *gtkgis, GtkGisScale *scale
 </FUNCTION>
 <FUNCTION>
+<NAME>gtk_gis_zoom_to_extent</NAME>
+<RETURNS>void </RETURNS>
+GtkGis *gtkgis, GtkGisLayerExtent extent
+</FUNCTION>
+<FUNCTION>
 <NAME>gtk_gis_zoom_to_max</NAME>
 <RETURNS>void </RETURNS>
 GtkGis *gtkgis
@@ -335,6 +340,11 @@ GtkGis *gtkgis
 GtkGis *gtkgis, GtkGisLayer *layer
 </FUNCTION>
 <FUNCTION>
+<NAME>gtk_gis_move_to</NAME>
+<RETURNS>void </RETURNS>
+GtkGis *gtkgis, gdouble x, gdouble y
+</FUNCTION>
+<FUNCTION>
 <NAME>gtk_gis_get_legend</NAME>
 <RETURNS>GtkWidget *</RETURNS>
 GtkGis *gtkgis
@@ -513,6 +523,16 @@ GtkGisLayer *layer,GtkGisGeometry *geometry
 GtkGisLayer *layer
 </FUNCTION>
 <FUNCTION>
+<NAME>gtk_gis_layer_get_visible</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkGisLayer *layer
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_gis_layer_set_visible</NAME>
+<RETURNS>void </RETURNS>
+GtkGisLayer *layer,gboolean visible
+</FUNCTION>
+<FUNCTION>
 <NAME>gtk_gis_layer_get_editable</NAME>
 <RETURNS>gboolean </RETURNS>
 GtkGisLayer *layer
@@ -865,7 +885,7 @@ GtkGisLayerSource *source
 </FUNCTION>
 <FUNCTION>
 <NAME>gtk_gis_layer_source_get_geometries</NAME>
-<RETURNS>GList *</RETURNS>
+<RETURNS>GSList *</RETURNS>
 GtkGisLayerSource *source,const gchar *name
 </FUNCTION>
 <FUNCTION>
@@ -887,6 +907,7 @@ GtkGisLayerSource *source,GtkGisLayerExtent *extent
 <NAME>GtkGisLayerGeometryType</NAME>
 typedef enum
        {
+               LAYER_GEOMETRY_TYPE_UNKNOWN,
                LAYER_GEOMETRY_TYPE_POINT,
                LAYER_GEOMETRY_TYPE_LINE,
                LAYER_GEOMETRY_TYPE_POLYGON,
index d61db35f670c4897813fd707308e66866ae371b2..9e381acfd052fdc344f579c92077f19198462280 100644 (file)
@@ -1,7 +1,7 @@
 11% symbol docs coverage.
 22 symbols documented.
 7 symbols incomplete.
-171 not documented.
+175 not documented.
 
 
 GTK_GIS
@@ -123,10 +123,12 @@ gtk_gis_layer_get_name
 gtk_gis_layer_get_source
 gtk_gis_layer_get_style
 gtk_gis_layer_get_type
+gtk_gis_layer_get_visible
 gtk_gis_layer_get_xml
 gtk_gis_layer_new (geometrytype, geometry_type)
 gtk_gis_layer_remove_geometry
 gtk_gis_layer_set_editable
+gtk_gis_layer_set_visible
 gtk_gis_layer_source_get_geometries (name, name)
 gtk_gis_layer_source_get_layer_extent
 gtk_gis_layer_source_get_layer_geometry_type
@@ -147,12 +149,14 @@ gtk_gis_layers_group_get_type
 gtk_gis_layers_group_new (source, name, geometrytype, name)
 gtk_gis_layers_group_remove_layer
 gtk_gis_layers_group_set_name
+gtk_gis_move_to
 gtk_gis_new_from_file
 gtk_gis_new_from_xml
 gtk_gis_remove_group
 gtk_gis_remove_layer
 gtk_gis_save_to_xml
 gtk_gis_set_scale
+gtk_gis_zoom_to_extent
 gtk_gis_zoom_to_layer
 gtk_gis_zoom_to_max
 
index 36fa92aed04049abcb59c74be155ab3ca05e013f..65ad8c0592d3950503d34fd59484fdf1cb8d538f 100644 (file)
@@ -12,4 +12,8 @@ GtkGisLayerSourceShpClass
 GtkGisLayersGroupClass
 gtk_gis_geometry_line_get_svg_path
 gtk_gis_layer_get_style
+gtk_gis_layer_get_visible
 gtk_gis_layer_set_style
+gtk_gis_layer_set_visible
+gtk_gis_move_to
+gtk_gis_zoom_to_extent
index a0a520d583942520630d1117df5a539553924841..607de02f350d023ea945448c1728d71024b5f734 100644 (file)
@@ -22,6 +22,7 @@ commons
 
 </para>
 
+@LAYER_GEOMETRY_TYPE_UNKNOWN: 
 @LAYER_GEOMETRY_TYPE_POINT: 
 @LAYER_GEOMETRY_TYPE_LINE: 
 @LAYER_GEOMETRY_TYPE_POLYGON: 
index 5dcd2eed9ca5b8a244123d65b28057bd03159d2a..e71b9c630eb689f4f5ab0defad4629cfb28ddc95 100644 (file)
@@ -56,6 +56,7 @@ typedef struct
 
 typedef enum
        {
+               LAYER_GEOMETRY_TYPE_UNKNOWN,
                LAYER_GEOMETRY_TYPE_POINT,
                LAYER_GEOMETRY_TYPE_LINE,
                LAYER_GEOMETRY_TYPE_POLYGON,
index d176a07f6794a72bab87d62abf38852f6b3ab239..210d3493b508611ff05e355b295fc22f1ccc9077 100644 (file)
@@ -192,7 +192,7 @@ GtkWidget
        cur = xmlDocGetRootElement (xdoc);
        if (cur != NULL)
                {
-                       if (strcmp (cur->name, "gtkgis") == 0)
+                       if (xmlStrcmp (cur->name, "gtkgis") == 0)
                                {
                                        GtkGisPrivate *priv;
 
@@ -208,6 +208,8 @@ GtkWidget
                                                                {
                                                                        xmlNode *xml_layer;
                                                                        gchar *layer_name;
+                                                                       gchar *visible;
+                                                                       gboolean is_visible;
                                                                        GtkGisLayer *layer;
 
                                                                        xml_layer = cur;
@@ -217,9 +219,17 @@ GtkWidget
                                                                                {
                                                                                        /* TO DO */
                                                                                        /* get layer source name */
-                                                                                       layer_name = g_strdup_printf ("layer");
+                                                                                       layer_name = g_strdup ("layer");
                                                                                }
 
+                                                                       visible = xmlGetProp (cur, (const xmlChar *)"visible");
+                                                                       if (visible == NULL ||
+                                                                           g_strcmp0 (g_strstrip (visible), "") == 0)
+                                                                               {
+                                                                                       visible = g_strdup ("y");
+                                                                               }
+                                                                       is_visible = (g_strcmp0 (visible, "y") == 0);
+
                                                                        /* TO DO
                                                                         * don't use a cycle: first find source and then style
                                                                         */
@@ -262,6 +272,10 @@ GtkWidget
                                                                                                                                        if (layer_source != NULL)
                                                                                                                                                {
                                                                                                                                                        layer = gtk_gis_layer_new_from_source (layer_source, layer_name);
+                                                                                                                                                       if (!is_visible)
+                                                                                                                                                               {
+                                                                                                                                                                       gtk_gis_layer_set_visible (layer, is_visible);
+                                                                                                                                                               }
                                                                                                                                                        gtk_gis_add_layer (GTK_GIS (gtkgis), layer);
                                                                                                                                                }
 
@@ -632,6 +646,75 @@ gtk_gis_set_scale (GtkGis *gtkgis, GtkGisScale *scale)
        gdk_window_set_cursor (GTK_WIDGET (gtkgis)->window, NULL);
 }
 
+/**
+ * gtk_gis_zoom_to_extent:
+ * @gtkgis: a #GtkGis object.
+ * @extent: a #GtkGisLayerExtent struct.
+ *
+ */
+void
+gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisLayerExtent extent)
+{
+       GtkGisPrivate *priv;
+       GtkGisScale *scale;
+
+       gdouble extx;
+       gdouble exty;
+
+       gdouble widget_width;
+       gdouble widget_height;
+
+       gdouble extent_width;
+       gdouble extent_height;
+
+       gdouble ratio;
+       gdouble plus;
+
+       g_return_if_fail (IS_GTK_GIS (gtkgis));
+
+       priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+       extx = 1.0;
+       exty = 1.0;
+
+       widget_width = GTK_WIDGET (gtkgis)->allocation.width;
+       widget_height = GTK_WIDGET (gtkgis)->allocation.height;
+
+       scale = g_malloc0 (sizeof (GtkGisScale));
+
+       /* must add width or height to make the max extent
+        * the same proportion of the canvas */
+       extent_width = extent.max_x - extent.min_x;
+       extent_height = extent.max_y - extent.min_y;
+
+       ratio = widget_width / widget_height;
+
+       plus = extent_width / ratio;
+
+       if (plus > extent_height)
+               {
+                       plus = (plus - extent_height) / 2;
+                       extent.min_y -= plus;
+                       extent.max_y += plus;
+               }
+       else
+               {
+                       plus = extent_height * ratio;
+                       plus = (plus - extent_width) / 2;
+                       extent.min_x -= plus;
+                       extent.max_x += plus;
+               }
+
+       extx = extent.max_x - extent.min_x;
+       exty = extent.max_y - extent.min_y;
+
+       scale->x = widget_width / extx;
+       scale->y = widget_height / exty;
+       scale->xy = (scale->x + scale->y) / 2;
+
+       gtk_gis_set_scale (gtkgis, scale);
+}
+
 /**
  * gtk_gis_zoom_to_max:
  * @gtkgis: a #GtkGis object.
@@ -716,13 +799,42 @@ gtk_gis_zoom_to_max (GtkGis *gtkgis)
  */
 void
 gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer)
+{
+       GtkGisLayerExtent *extent;
+
+       g_return_if_fail (IS_GTK_GIS (gtkgis));
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+       extent = gtk_gis_layer_get_extent (layer);
+       gtk_gis_zoom_to_extent (gtkgis, *extent);
+
+       gtk_gis_move_to (gtkgis, extent->min_x, extent->min_y);
+}
+
+/**
+ * gtk_gis_move_to:
+ * @gtkgis:
+ * @x:
+ * @y:
+ *
+ */
+void
+gtk_gis_move_to (GtkGis *gtkgis, gdouble x, gdouble y)
 {
        GtkGisPrivate *priv;
+       gdouble new_x;
+       gdouble new_y;
 
        g_return_if_fail (IS_GTK_GIS (gtkgis));
 
        priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
+       new_x = x;
+       new_y = y;
+       goo_canvas_convert_to_pixels (GOO_CANVAS (priv->canvas), &new_x, &new_y);
+
+       gtk_layout_move (GTK_LAYOUT (priv->scroll_win), priv->canvas,
+                        -new_x, -new_y);
 }
 
 static void
index 2626b283a6d532da91ecbf63cbfaa494b53d0f18..5db9e2797837082e9fe597eeee26af54639a5460 100644 (file)
@@ -75,9 +75,12 @@ void gtk_gis_draw (GtkGis *gtkgis);
 GtkGisScale *gtk_gis_get_scale (GtkGis *gtkgis);
 void gtk_gis_set_scale (GtkGis *gtkgis, GtkGisScale *scale);
 
+void gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisLayerExtent extent);
 void gtk_gis_zoom_to_max (GtkGis *gtkgis);
 void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer);
 
+void gtk_gis_move_to (GtkGis *gtkgis, gdouble x, gdouble y);
+
 GtkWidget *gtk_gis_get_legend (GtkGis *gtkgis);
 
 
index a7c86c748adb78a8cebf6e668b2540dfb0e4ab67..c0d40f55fe88bf5ae1bf4debcc6e625ba5898e2b 100644 (file)
@@ -52,8 +52,9 @@ struct _GtkGisLayerPrivate
                GtkGisLayerSource *source;
 
                GooCanvasItem *layer_item;
-               GList *geometries;
+               GSList *geometries;
 
+               gboolean visible;
                gboolean editable;
 
                GtkGisLayerStyle *style;
@@ -77,6 +78,9 @@ gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer)
 {
        GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (gtk_gis_layer);
 
+       priv->visible = TRUE;
+       priv->editable = FALSE;
+
        priv->style = g_malloc (sizeof (GtkGisLayerStyle));
        priv->style->width = 0.5;
        priv->style->stroke_color = g_strdup ("black");
@@ -196,7 +200,11 @@ gchar
 GtkGisLayerSource
 *gtk_gis_layer_get_source (GtkGisLayer *layer)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL);
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
        return priv->source;
 }
@@ -211,7 +219,11 @@ GtkGisLayerSource
 void
 gtk_gis_layer_fill_from_source (GtkGisLayer *layer)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
+
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
        priv->geometries = gtk_gis_layer_source_get_geometries (priv->source, priv->name);
 }
@@ -238,9 +250,14 @@ gtk_gis_layer_save (GtkGisLayer *layer,
 void
 gtk_gis_layer_add_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
+
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+       g_return_if_fail (IS_GTK_GIS_GEOMETRY (geometry));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
-       priv->geometries = g_list_append (priv->geometries, geometry);
+       priv->geometries = g_slist_append (priv->geometries, geometry);
 }
 
 /**
@@ -251,9 +268,14 @@ gtk_gis_layer_add_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry)
 void
 gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
 
-       priv->geometries = g_list_remove (priv->geometries, geometry);
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+       g_return_if_fail (IS_GTK_GIS_GEOMETRY (geometry));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       priv->geometries = g_slist_remove (priv->geometries, geometry);
 }
 
 /**
@@ -264,15 +286,54 @@ gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry)
 GtkGisLayerExtent
 *gtk_gis_layer_get_extent (GtkGisLayer *layer)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
-
+       GtkGisLayerPrivate *priv;
        GtkGisLayerExtent *extent;
 
+       g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL);
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
        extent = gtk_gis_layer_source_get_layer_extent (priv->source, priv->name);
 
        return extent;
 }
 
+/**
+ * gtk_gis_layer_get_visible:
+ * @layer: a #GtkGisLayer object.
+ *
+ * Returns: whether the layer is visible.
+ */
+gboolean
+gtk_gis_layer_get_visible (GtkGisLayer *layer)
+{
+       GtkGisLayerPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), FALSE);
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       return priv->visible;
+}
+
+/**
+ * gtk_gis_layer_set_visible:
+ * @layer: a #GtkGisLayer object.
+ * @visible:
+ */
+void
+gtk_gis_layer_set_visible (GtkGisLayer *layer,
+                           gboolean visible)
+{
+       GtkGisLayerPrivate *priv;
+
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       priv->visible = visible;
+}
+
 /**
  * gtk_gis_layer_get_editable:
  * @layer: a #GtkGisLayer object.
@@ -282,7 +343,11 @@ GtkGisLayerExtent
 gboolean
 gtk_gis_layer_get_editable (GtkGisLayer *layer)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), FALSE);
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
        return priv->editable;
 }
@@ -296,7 +361,11 @@ void
 gtk_gis_layer_set_editable (GtkGisLayer *layer,
                             gboolean editable)
 {
-       GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+       GtkGisLayerPrivate *priv;
+
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
        priv->editable = editable;
 }
@@ -336,6 +405,7 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style)
 {
        GtkGisLayerPrivate *priv;
        GtkGisLayerStyle new_style;
+       gchar *prop;
 
        g_return_if_fail (IS_GTK_GIS_LAYER (layer));
 
@@ -349,7 +419,10 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style)
                {
                        new_style.width = priv->style->width;
                }
-       if (style.stroke_color != NULL)
+
+       prop = g_strdup (style.stroke_color);
+       if (style.stroke_color != NULL &&
+           g_strcmp0 (g_strstrip (prop), "") != 0)
                {
                        new_style.stroke_color = g_strdup (style.stroke_color);
                }
@@ -357,7 +430,10 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style)
                {
                        new_style.stroke_color = g_strdup (priv->style->stroke_color);
                }
-       if (style.fill_color != NULL)
+
+       prop = g_strdup (style.fill_color);
+       if (style.fill_color != NULL &&
+           g_strcmp0 (g_strstrip (prop), "") != 0)
                {
                        new_style.fill_color = g_strdup (style.fill_color);
                }
@@ -381,7 +457,7 @@ void
 gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
 {
        GtkGisLayerPrivate *priv;
-       GList *cur;
+       GSList *cur;
        GooCanvasItem *item;
 
        g_return_if_fail (IS_GTK_GIS_LAYER (layer));
@@ -389,11 +465,21 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
 
        priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
+       if (!priv->visible)
+               {
+                       /* TO DO
+                        * free each geometry before
+                        */
+                       g_free (priv->geometries);
+                       priv->geometries = NULL;
+                       return;
+               }
+
        gtk_gis_layer_fill_from_source (layer);
 
        priv->layer_item = goo_canvas_group_new (root, NULL);
 
-       cur = g_list_first (priv->geometries);
+       cur = priv->geometries;
        while (cur != NULL)
                {
                        item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, *priv->style);
@@ -403,7 +489,7 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
                                        goo_canvas_item_add_child (priv->layer_item, item, -1);
                                }
 
-                       cur = g_list_next (cur);
+                       cur = g_slist_next (cur);
                }
 }
 
index 13d42f3ff8c1a534093c93828e072863c0524e43..da1c17321b86444eadef43dceb9341ad0cef5df5 100644 (file)
@@ -83,6 +83,10 @@ void gtk_gis_layer_remove_geometry (GtkGisLayer *layer,
 
 GtkGisLayerExtent *gtk_gis_layer_get_extent (GtkGisLayer *layer);
 
+gboolean gtk_gis_layer_get_visible (GtkGisLayer *layer);
+void gtk_gis_layer_set_visible (GtkGisLayer *layer,
+                                gboolean visible);
+
 gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer);
 void gtk_gis_layer_set_editable (GtkGisLayer *layer,
                                  gboolean editable);
index b9548f378c3fd0d7e8ef465180945b4405baabe6..ff83156facc47f045710a4bf770f3ce41cd32b48 100644 (file)
 static void gtk_gis_layer_source_class_init (GtkGisLayerSourceClass *klass);
 static void gtk_gis_layer_source_init (GtkGisLayerSource *gtk_gis_layer_source);
 
-static GList
+static GSList
 *gtk_gis_layer_source_get_geometries_from_ogr (GtkGisLayerSource *source,
                                                const gchar *name);
-static GList
+static GSList
 *gtk_gis_layer_source_get_geometries_from_gdal (GtkGisLayerSource *source,
                                                 const gchar *name);
 
@@ -119,13 +119,13 @@ xmlNode
  *
  * Loads the #GtkGisLayerSource from the disk.
  *
- * Returns: a #GList of #GtkGeometry objects.
+ * Returns: a #GSList of #GtkGeometry objects.
  */
-GList
+GSList
 *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source,
                                       const gchar *name)
 {
-       GList *geometries = NULL;
+       GSList *geometries = NULL;
 
        GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
 
@@ -152,38 +152,46 @@ GtkGisLayerGeometryType
 gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source,
                                               const gchar *name)
 {
-       GtkGisLayerGeometryType type = -1;
+       GtkGisLayerGeometryType type;
 
        OGRLayerH layer;
        OGRFeatureH feature;
 
-       GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+       GtkGisLayerSourcePrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_GIS_LAYER_SOURCE (source), LAYER_GEOMETRY_TYPE_UNKNOWN);
 
+       priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+
+       type = LAYER_GEOMETRY_TYPE_UNKNOWN;
        if (priv->datasource != NULL)
                {
                        layer = OGR_DS_GetLayerByName (priv->datasource, name);
 
-                       feature = OGR_L_GetNextFeature (layer);
-
-                       if (feature != NULL)
+                       if (layer != NULL)
                                {
-                                       OGRGeometryH poGeometry;
+                                       feature = OGR_L_GetNextFeature (layer);
 
-                                       poGeometry = OGR_F_GetGeometryRef (feature);
-                                       if (poGeometry != NULL
-                                               && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
-                                               {
-                                                       type = LAYER_GEOMETRY_TYPE_POINT;
-                                               }
-                                       else if (poGeometry != NULL
-                                                        && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
-                                               {
-                                                       type = LAYER_GEOMETRY_TYPE_LINE;
-                                               }
-                                       else if (poGeometry != NULL
-                                                        && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
+                                       if (feature != NULL)
                                                {
-                                                       type = LAYER_GEOMETRY_TYPE_POLYGON;
+                                                       OGRGeometryH poGeometry;
+
+                                                       poGeometry = OGR_F_GetGeometryRef (feature);
+                                                       if (poGeometry != NULL
+                                                               && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
+                                                               {
+                                                                       type = LAYER_GEOMETRY_TYPE_POINT;
+                                                               }
+                                                       else if (poGeometry != NULL
+                                                                        && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
+                                                               {
+                                                                       type = LAYER_GEOMETRY_TYPE_LINE;
+                                                               }
+                                                       else if (poGeometry != NULL
+                                                                        && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
+                                                               {
+                                                                       type = LAYER_GEOMETRY_TYPE_POLYGON;
+                                                               }
                                                }
                                }
                }
@@ -302,11 +310,11 @@ gtk_gis_layer_source_set_gdal_dataset (GtkGisLayerSource *source,
        priv->max_extent = NULL;
 }
 
-static GList
+static GSList
 *gtk_gis_layer_source_get_geometries_from_ogr (GtkGisLayerSource *source,
                                                const gchar *name)
 {
-       GList *geometries = NULL;
+       GSList *geometries = NULL;
 
        OGRLayerH layer;
        OGRFeatureH feature;
@@ -416,17 +424,17 @@ static GList
                                                }
                                }
 
-                       geometries = g_list_append (geometries, geometry);
+                       geometries = g_slist_append (geometries, geometry);
                }
 
        return geometries;
 }
 
-static GList
+static GSList
 *gtk_gis_layer_source_get_geometries_from_gdal (GtkGisLayerSource *source,
                                                 const gchar *name)
 {
-       GList *geometries = NULL;
+       GSList *geometries = NULL;
        GtkGisGeometry *geometry;
 
        gdouble adfGeoTransform[6];
@@ -543,7 +551,7 @@ static GList
 
                        if (geometry != NULL)
                                {
-                                       geometries = g_list_append (geometries, geometry);
+                                       geometries = g_slist_append (geometries, geometry);
                                }
                }
 
index c1508a6816336cf51d28d0670b2341a41ab637f3..50108c3351c994718d3580ef6591171e16deb52f 100644 (file)
@@ -68,8 +68,8 @@ GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST;
 
 xmlNode *gtk_gis_layer_source_get_xml (GtkGisLayerSource *source);
 
-GList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source,
-                                            const gchar *name);
+GSList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source,
+                                             const gchar *name);
 
 GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source,
                                                                       const gchar *name);
index 2182bd0fa6fed1b0c0fe28628dbfb35426112f9d..fb7d49a59fbd34ae5e92a454c154e3da7d6cb85b 100644 (file)
@@ -16,22 +16,29 @@ main (int argc, char *argv[])
                       NULL);
 
        gtkgis = gtk_gis_new_from_file (argv[1]);
+       if (gtkgis == NULL)
+               {
+                       g_fprintf (stderr, "Error loading GtkGis definition file.\n");
+                       return 0;
+               }
 
-    gtk_container_add (GTK_CONTAINER (window), gtkgis);
+       gtk_container_add (GTK_CONTAINER (window), gtkgis);
 
        gtk_widget_show_all (window);
 
-       gtk_gis_zoom_to_max (GTK_GIS (gtkgis));
+       /*gtk_gis_zoom_to_max (GTK_GIS (gtkgis));*/
+       gtk_gis_zoom_to_layer (GTK_GIS (gtkgis),
+                              gtk_gis_get_layer_by_name (GTK_GIS (gtkgis), "railroads"));
        gtk_gis_draw (GTK_GIS (gtkgis));
 
-       scale = gtk_gis_get_scale (GTK_GIS (gtkgis));
+       /*scale = gtk_gis_get_scale (GTK_GIS (gtkgis));
        if (scale != NULL)
                {
                        scale->x = (scale->x * 80) / 100;
                        scale->y = (scale->y * 80) / 100;
                        scale->xy = (scale->xy * 80) / 100;
                        gtk_gis_set_scale (GTK_GIS (gtkgis), scale);
-               }
+               }*/
 
        gtk_gis_save_to_xml (GTK_GIS (gtkgis), "test_saved.gtkgis");
 
index 3910e0408e3f37ace6f7f5f2224a65f1a298bde6..33d044e4df2383b0814208ce5e3edd687eda16e4 100644 (file)
@@ -24,7 +24,7 @@
                </style>
        </layer>
 
-       <layer name="rivers">
+       <layer name="rivers" visible="n">
                <source>
                        <shape filename="tests/samples/rivers.shp" />
                </source>