Added GtkGis::zoom_to_max.
Fixed some bugs.
Now the widget draws points, lines and poligons.
GParamSpec *pspec);
-/*#define GTK_GIS_GEOMETRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY, GtkGisGeometryPrivate))
+#define GTK_GIS_GEOMETRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY, GtkGisGeometryPrivate))
typedef struct _GtkGisGeometryPrivate GtkGisGeometryPrivate;
struct _GtkGisGeometryPrivate
{
- };*/
+ gboolean editable;
+ };
G_DEFINE_TYPE (GtkGisGeometry, gtk_gis_geometry, G_TYPE_OBJECT)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- /*g_type_class_add_private (object_class, sizeof (GtkGisGeometryPrivate));*/
+ g_type_class_add_private (object_class, sizeof (GtkGisGeometryPrivate));
object_class->set_property = gtk_gis_geometry_set_property;
object_class->get_property = gtk_gis_geometry_get_property;
static void
gtk_gis_geometry_init (GtkGisGeometry *gtk_gis_geometry)
{
- /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+ GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
+
+ priv->editable = FALSE;
+}
+
+/**
+ * gtk_gis_geometry_get_editable:
+ * @geometry:
+ *
+ */
+gboolean
+gtk_gis_geometry_get_editable (GtkGisGeometry *geometry)
+{
+ GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry);
+
+ return priv->editable;
+}
+
+/**
+ * gtk_gis_geometry_set_editable:
+ * @geometry:
+ * @editable:
+ *
+ */
+void
+gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable)
+{
+ GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry);
+
+ priv->editable = editable;
+}
+
+/**
+ * gtk_gis_geometry_draw:
+ * @geometry:
+ *
+ */
+GooCanvasItem
+*gtk_gis_geometry_draw (GtkGisGeometry *geometry)
+{
+ GooCanvasItem *item = NULL;
+
+ if (IS_GTK_GIS_GEOMETRY (geometry) && GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw != NULL)
+ {
+ item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry);
+ }
+
+ return item;
}
static void
{
GtkGisGeometry *gtk_gis_geometry = GTK_GIS_GEOMETRY (object);
- /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+ GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
switch (property_id)
{
{
GtkGisGeometry *gtk_gis_geometry = GTK_GIS_GEOMETRY (object);
- /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+ GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
switch (property_id)
{
#include <glib.h>
#include <glib-object.h>
+#include <goocanvas.h>
+
G_BEGIN_DECLS
struct _GtkGisGeometryClass
{
GObjectClass parent_class;
+
+ GooCanvasItem *(*draw) (GtkGisGeometry *geometry);
};
GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
gboolean gtk_gis_geometry_get_editable (GtkGisGeometry *geometry);
void gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable);
+GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry);
+
G_END_DECLS
static void gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass);
static void gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_line);
+static gchar *convert_comma_to_dot (gchar *str);
+
+static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line);
+
static void gtk_gis_geometry_line_set_property (GObject *object,
guint property_id,
const GValue *value,
typedef struct _GtkGisGeometryLinePrivate GtkGisGeometryLinePrivate;
struct _GtkGisGeometryLinePrivate
{
- GPtrArray *points;
+ GSList *points;
};
G_DEFINE_TYPE (GtkGisGeometryLine, gtk_gis_geometry_line, TYPE_GTK_GIS_GEOMETRY)
gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
g_type_class_add_private (object_class, sizeof (GtkGisGeometryLinePrivate));
object_class->set_property = gtk_gis_geometry_line_set_property;
object_class->get_property = gtk_gis_geometry_line_get_property;
+
+ geometry_class->draw = gtk_gis_geometry_line_draw;
}
static void
{
GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line);
- priv->points = g_ptr_array_new ();
+ priv->points = NULL;
}
/**
}
/**
- * gtk_gis_geometry_line_new_from_array:
+ * gtk_gis_geometry_line_new_from_list:
* @points:
*
* Creates a new #GtkGisGeometryLine object.
* Returns: the newly created #GtkGisGeometryLine object.
*/
GtkGisGeometry
-*gtk_gis_geometry_line_new_from_array (GPtrArray *points)
+*gtk_gis_geometry_line_new_from_list (GSList *points)
{
GtkGisGeometry *line = NULL;
GtkGisGeometryLinePrivate *priv;
priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line));
- priv->points = points;
+ priv->points = g_slist_copy (points);
return line;
}
gpoint->x = point.x;
gpoint->y = point.y;
- g_ptr_array_add (priv->points, gpoint);
+ priv->points = g_slist_append (priv->points, gpoint);
}
/**
gtk_gis_geometry_line_add_point (line, gpoint);
}
+static gchar
+*convert_comma_to_dot (gchar *str)
+{
+ /* convert , in . */
+ gint len;
+ gint i;
+ gchar *ret = NULL;
+
+ len = strlen (str);
+
+ if (len > 0)
+ {
+ ret = g_malloc (len + 1);
+ strcpy (ret, str);
+ }
+
+ for (i = 0; i < len; i++)
+ {
+ if (ret[i] == ',')
+ {
+ ret[i] = '.';
+ }
+ }
+
+ return ret;
+}
+
+static GooCanvasItem
+*gtk_gis_geometry_line_draw (GtkGisGeometry *line)
+{
+ GtkGisGeometryLinePrivate *priv;
+ GooCanvasItem *item = NULL;
+ GtkGisPoint *point;
+
+ gchar *path;
+
+ priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line));
+
+ if (priv->points != NULL)
+ {
+ GSList *cur;
+
+ cur = priv->points;
+
+ point = (GtkGisPoint *)cur->data;
+ path = g_strdup_printf ("M %f %f", point->x, point->y);
+
+ cur = g_slist_next (cur);
+ while (cur != NULL)
+ {
+ point = (GtkGisPoint *)cur->data;
+ path = g_strconcat (path,
+ g_strdup_printf (" L %f %f", point->x, point->y),
+ NULL);
+
+ cur = g_slist_next (cur);
+ }
+
+ path = convert_comma_to_dot (path);
+ item = goo_canvas_path_new (NULL,
+ path,
+ "line-width", 1.0,
+ NULL);
+ }
+
+ return item;
+}
+
static void
gtk_gis_geometry_line_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GtkGisGeometry *gtk_gis_geometry_line_new (void);
-GtkGisGeometry *gtk_gis_geometry_line_new_from_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_line_new_from_list (GSList *points);
void gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point);
void gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
static void gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass);
static void gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point);
+static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point);
+
static void gtk_gis_geometry_point_set_property (GObject *object,
guint property_id,
const GValue *value,
typedef struct _GtkGisGeometryPointPrivate GtkGisGeometryPointPrivate;
struct _GtkGisGeometryPointPrivate
{
- GtkGisPoint point;
+ GtkGisPoint *point;
};
G_DEFINE_TYPE (GtkGisGeometryPoint, gtk_gis_geometry_point, TYPE_GTK_GIS_GEOMETRY)
gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
g_type_class_add_private (object_class, sizeof (GtkGisGeometryPointPrivate));
object_class->set_property = gtk_gis_geometry_point_set_property;
object_class->get_property = gtk_gis_geometry_point_get_property;
+
+ geometry_class->draw = gtk_gis_geometry_point_draw;
}
static void
gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point)
{
GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point);
+
+ priv->point = NULL;
}
/**
priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (GTK_GIS_GEOMETRY_POINT (gpoint));
- priv->point.x = point.x;
- priv->point.y = point.y;
+ priv->point = g_malloc0 (sizeof (GtkGisPoint));
+
+ priv->point->x = point.x;
+ priv->point->y = point.y;
return gpoint;
}
gpoint = g_malloc0 (sizeof (GtkGisPoint));
- gpoint->x = priv->point.x;
- gpoint->y = priv->point.y;
+ gpoint->x = priv->point->x;
+ gpoint->y = priv->point->y;
return gpoint;
}
{
GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
- return priv->point.x;
+ return priv->point->x;
}
/**
{
GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
- return priv->point.y;
+ return priv->point->y;
+}
+
+static
+GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point)
+{
+ GooCanvasItem *item = NULL;
+
+ GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (GTK_GIS_GEOMETRY_POINT (point));
+
+ if (priv->point != NULL)
+ {
+ item = goo_canvas_rect_new (NULL,
+ priv->point->x, priv->point->y,
+ 1, 1,
+ "line-width", 1.0,
+ NULL);
+ }
+
+ return item;
}
static void
static void gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass);
static void gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geometry_polygon);
+static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon);
+
static void gtk_gis_geometry_polygon_set_property (GObject *object,
guint property_id,
const GValue *value,
typedef struct _GtkGisGeometryPolygonPrivate GtkGisGeometryPolygonPrivate;
struct _GtkGisGeometryPolygonPrivate
{
- GList *lines;
+ GSList *lines;
};
G_DEFINE_TYPE (GtkGisGeometryPolygon, gtk_gis_geometry_polygon, TYPE_GTK_GIS_GEOMETRY)
gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
g_type_class_add_private (object_class, sizeof (GtkGisGeometryPolygonPrivate));
object_class->set_property = gtk_gis_geometry_polygon_set_property;
object_class->get_property = gtk_gis_geometry_polygon_get_property;
+
+ geometry_class->draw = gtk_gis_geometry_polygon_draw;
}
static void
}
/**
- * gtk_gis_geometry_polygon_new_from_array:
+ * gtk_gis_geometry_polygon_new_from_list:
* @points:
*
* Creates a new #GtkGisGeometryPolygon object.
* Returns: the newly created #GtkGisGeometryPolygon object.
*/
GtkGisGeometry
-*gtk_gis_geometry_polygon_new_from_array (GPtrArray *points)
+*gtk_gis_geometry_polygon_new_from_list (GSList *points)
{
GtkGisGeometry *polygon = NULL;
GtkGisGeometry *line = NULL;
- line = gtk_gis_geometry_line_new_from_array (points);
+ line = gtk_gis_geometry_line_new_from_list (points);
if (line != NULL)
{
{
GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
- priv->lines = g_list_append (priv->lines, line);
+ priv->lines = g_slist_append (priv->lines, line);
}
/**
{
GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
- priv->lines = g_list_remove (priv->lines, line);
+ priv->lines = g_slist_remove (priv->lines, line);
+}
+
+static GooCanvasItem
+*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon)
+{
+ GtkGisGeometryPolygonPrivate *priv;
+ GooCanvasItem *polygon_item = NULL;
+
+ gchar *path;
+
+ priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (GTK_GIS_GEOMETRY_POLYGON (polygon));
+
+ if (priv->lines != NULL)
+ {
+ GSList *cur;
+ GtkGisGeometryLine *line;
+ GooCanvasItem *item = NULL;
+
+ polygon_item = goo_canvas_group_new (NULL, NULL);
+
+ cur = priv->lines;
+
+ line = (GtkGisGeometryLine *)cur->data;
+
+ while (cur != NULL)
+ {
+ item = gtk_gis_geometry_draw (GTK_GIS_GEOMETRY (line));
+
+ if (item != NULL)
+ {
+ goo_canvas_item_add_child (polygon_item, item, -1);
+ }
+
+ cur = g_slist_next (cur);
+ }
+ }
+
+ return polygon_item;
}
static void
GtkGisGeometry *gtk_gis_geometry_polygon_new (void);
GtkGisGeometry *gtk_gis_geometry_polygon_new_from_line (GtkGisGeometryLine *line);
-GtkGisGeometry *gtk_gis_geometry_polygon_new_from_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_polygon_new_from_list (GSList *points);
void gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
void gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
static void gtk_gis_add (GtkContainer *container,
GtkWidget *widget);
+static void gtk_gis_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
static void gtk_gis_set_property (GObject *object,
guint property_id,
GtkWidget *canvas;
GooCanvasItem *canvas_root;
- GList *layers_groups;
- GList *layers;
+ GSList *layers_groups;
+ GSList *layers;
- GtkGisLayerExtent extent;
+ GtkGisLayerExtent *extent;
+
+ gdouble scale_x;
+ gdouble scale_y;
};
G_DEFINE_TYPE (GtkGis, gtk_gis, GTK_TYPE_BIN)
widget_class->size_allocate = gtk_gis_size_allocate;
container_class->add = gtk_gis_add;
+ container_class->forall = gtk_gis_forall;
}
static void
gtk_container_add (GTK_CONTAINER (priv->scroll_win), priv->canvas);
priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas));
+
+ priv->layers_groups = NULL;
+ priv->layers = NULL;
+
+ priv->extent = NULL;
+
+ priv->scale_x = 0.0;
+ priv->scale_y = 0.0;
}
/**
g_warning ("The file is not a valid gtkgis file.");
}
+ gtk_gis_draw (GTK_GIS (gtkgis));
+
return gtkgis;
}
priv = GTK_GIS_GET_PRIVATE (gtkgis);
- priv->layers = g_list_append (priv->layers, layer);
+ priv->layers = g_slist_append (priv->layers, layer);
extent = gtk_gis_layer_get_extent (layer);
- if (extent.min_x < priv->extent.min_x)
- {
- priv->extent.min_x = extent.min_x;
- }
- if (extent.min_y < priv->extent.min_y)
- {
- priv->extent.min_y = extent.min_y;
- }
- if (extent.max_x > priv->extent.max_x)
+ if (priv->extent == NULL)
{
- priv->extent.max_x = extent.max_x;
+ priv->extent = g_malloc (sizeof (GtkGisLayerExtent));
+ priv->extent->min_x = extent.min_x;
+ priv->extent->max_x = extent.max_x;
+ priv->extent->min_y = extent.min_y;
+ priv->extent->max_y = extent.max_y;
}
- if (extent.max_y > priv->extent.max_y)
+ else
{
- priv->extent.max_y = extent.max_y;
+ if (extent.min_x < priv->extent->min_x)
+ {
+ priv->extent->min_x = extent.min_x;
+ }
+ if (extent.min_y < priv->extent->min_y)
+ {
+ priv->extent->min_y = extent.min_y;
+ }
+ if (extent.max_x > priv->extent->max_x)
+ {
+ priv->extent->max_x = extent.max_x;
+ }
+ if (extent.max_y > priv->extent->max_y)
+ {
+ priv->extent->max_y = extent.max_y;
+ }
}
goo_canvas_set_bounds (GOO_CANVAS (priv->canvas),
- priv->extent.min_x,
- priv->extent.min_y,
- priv->extent.max_x,
- priv->extent.max_y);
+ priv->extent->min_x,
+ priv->extent->min_y,
+ priv->extent->max_x,
+ priv->extent->max_y);
}
/**
{
GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtkgis);
- priv->layers = g_list_remove (priv->layers, layer);
+ priv->layers = g_slist_remove (priv->layers, layer);
+}
+
+/**
+ * gtk_gis_draw:
+ * @gtkgis:
+ *
+ */
+void
+gtk_gis_draw (GtkGis *gtkgis)
+{
+ GtkGisPrivate *priv;
+ GSList *cur;
+
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+ cur = priv->layers;
+ while (cur != NULL)
+ {
+ gtk_gis_layer_draw ((GtkGisLayer *)cur->data, priv->canvas_root);
+
+ cur = g_slist_next (cur);
+ }
+}
+
+/**
+ * gtk_gis_zoom_to_max:
+ * @gtkgis:
+ *
+ */
+void
+gtk_gis_zoom_to_max (GtkGis *gtkgis)
+{
+ GtkGisPrivate *priv;
+ GtkRequisition requisition;
+
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+g_fprintf(stderr,"%f %f %f %f\n", priv->extent->min_x, priv->extent->max_x,
+priv->extent->min_y, priv->extent->max_y);
+
+ gtk_gis_size_request (GTK_WIDGET (gtkgis), &requisition);
+g_fprintf(stderr,"%d %d\n", requisition.width, requisition.height);
+ /*priv->scale_x = requisition.width / (priv->extent->max_x - priv->extent->min_x);
+ priv->scale_y = requisition.height / (priv->extent->max_y - priv->extent->min_y);*/
+ priv->scale_x = 640 / (priv->extent->max_x - priv->extent->min_x);
+ priv->scale_y = 600 / (priv->extent->max_y - priv->extent->min_y);
+g_fprintf(stderr,"%f %f\n", priv->scale_x, priv->scale_y);
+ g_object_set (priv->canvas,
+ "scale-x", priv->scale_x,
+ "scale-y", priv->scale_y,
+ NULL);
+}
+
+/**
+ * gtk_gis_zoom_to_layer:
+ * @gtkgis:
+ * @layer:
+ *
+ */
+void
+gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer)
+{
+ GtkGisPrivate *priv;
+
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
}
static void
/* TO DO */
/* free each layers_groups before */
- g_list_free (priv->layers_groups);
+ g_slist_free (priv->layers_groups);
/* TO DO */
/* free each layers before */
- g_list_free (priv->layers);
+ g_slist_free (priv->layers);
GTK_OBJECT_CLASS (gtk_gis_parent_class)->destroy (object);
}
gtk_widget_set_parent (child, GTK_WIDGET (bin));
}
+static void
+gtk_gis_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ g_return_if_fail (IS_GTK_GIS (container));
+ g_return_if_fail (callback != NULL);
+
+ GTK_CONTAINER_CLASS (gtk_gis_parent_class)->forall (container,
+ include_internals,
+ callback,
+ callback_data);
+}
+
static void
gtk_gis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
child_allocation.y = relative_allocation.y + allocation->y;
child_allocation.width = relative_allocation.width;
child_allocation.height = relative_allocation.height;
-
gtk_widget_size_allocate (bin->child, &child_allocation);
}
}
void gtk_gis_add_layer (GtkGis *gtkgis, GtkGisLayer *layer);
void gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer);
-void gtk_gis_set_legend_visible (GtkGis *gtkgis, gboolean visible);
+void gtk_gis_draw (GtkGis *gtkgis);
+
+void gtk_gis_zoom_to_max (GtkGis *gtkgis);
+void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer);
+void gtk_gis_set_legend_visible (GtkGis *gtkgis, gboolean visible);
GtkWidget *gtk_gis_get_legend (GtkGis *gtkgis);
GtkGisLayerSource *source;
+ GooCanvasItem *layer_item;
GList *geometries;
gboolean editable;
/**
* gtk_gis_layer_draw:
* @layer:
- * @canvas_root:
+ * @root:
*
*/
void
-gtk_gis_layer_draw (GtkGisLayer *layer,
- GooCanvasItem *canvas_root)
+gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root)
{
- /*if (IS_GTK_GIS_LAYER_OBJECT (layer) && GTK_GIS_LAYER_GET_CLASS (layer)->draw != NULL)
+ GtkGisLayerPrivate *priv;
+
+ GList *cur;
+
+ GooCanvasItem *item;
+
+ priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+ g_return_if_fail (priv->geometries != NULL);
+
+ priv->layer_item = goo_canvas_group_new (root, NULL);
+
+ cur = g_list_first (priv->geometries);
+ while (cur != NULL)
{
- GTK_GIS_LAYER_GET_CLASS (layer)->draw (layer, canvas_root);
- }*/
+ item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data);
+
+ if (item != NULL)
+ {
+ goo_canvas_item_add_child (priv->layer_item, item, -1);
+ }
+
+ cur = g_list_next (cur);
+ }
}
static void
void gtk_gis_layer_set_editable (GtkGisLayer *layer,
gboolean editable);
-void gtk_gis_layer_draw (GtkGisLayer *layer,
- GooCanvasItem *canvas_root);
+void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root);
G_END_DECLS
{
GList *geometries = NULL;
+ OGRLayerH layer;
+
+ OGRFeatureH feature;
+ OGRGeometryH poGeometry;
+ GtkGisGeometry *geometry;
+
GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
- if (priv->datasource == NULL)
- {
- /* TO DO */
- }
- else
+ g_return_if_fail (priv->datasource != NULL);
+
+ layer = OGR_DS_GetLayerByName (priv->datasource, name);
+
+ g_return_if_fail (layer != NULL);
+
+ OGR_L_ResetReading (layer);
+
+ while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
{
- OGRLayerH layer;
- OGRFeatureDefnH layerDefn;
- OGRFeatureH feature;
- OGRGeometryH poGeometry;
- GtkGisGeometry *geometry;
+ poGeometry = OGR_F_GetGeometryRef (feature);
- layer = OGR_DS_GetLayerByName (priv->datasource, name);
+ if (poGeometry != NULL
+ && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
+ {
+ GtkGisPoint gpoint;
- layerDefn = OGR_L_GetLayerDefn (layer);
+ gpoint.x = OGR_G_GetX (poGeometry, 0);
+ gpoint.y = OGR_G_GetY (poGeometry, 0);
- while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
+ geometry = gtk_gis_geometry_point_new (gpoint);
+ }
+ else if (poGeometry != NULL
+ && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
{
- poGeometry = OGR_F_GetGeometryRef (feature);
+ gint points;
+ gint point;
+ GSList *gpoints = NULL;
- if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
+ GtkGisPoint *gpoint;
+
+ points = OGR_G_GetPointCount (poGeometry);
+
+ for (point = 0; point < points; point++)
{
- GtkGisPoint gpoint;
+ gpoint = g_malloc0 (sizeof (GtkGisPoint));
- gpoint.x = OGR_G_GetX (poGeometry, 0);
- gpoint.y = OGR_G_GetY (poGeometry, 0);
+ gpoint->x = OGR_G_GetX (poGeometry, point);
+ gpoint->y = OGR_G_GetY (poGeometry, point);
- geometry = gtk_gis_geometry_point_new (gpoint);
+ gpoints = g_slist_append (gpoints, gpoint);
}
- else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
+
+ geometry = gtk_gis_geometry_line_new_from_list (gpoints);
+ }
+ else if (poGeometry != NULL
+ && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
+ {
+ gint num_geometries;
+ gint i_geometry;
+
+ OGRGeometryH poGeometryIns;
+
+ num_geometries = OGR_G_GetGeometryCount (poGeometry);
+
+ for (i_geometry = 0; i_geometry < num_geometries; i_geometry++)
{
gint points;
gint point;
- GPtrArray *gar_points;
+ GSList *gpoints = NULL;
GtkGisPoint *gpoint;
- gar_points = g_ptr_array_new ();
+ poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry);
- points = OGR_G_GetPointCount (poGeometry);
+ points = OGR_G_GetPointCount (poGeometryIns);
for (point = 0; point < points; point++)
{
gpoint = g_malloc0 (sizeof (GtkGisPoint));
- gpoint->x = OGR_G_GetX (poGeometry, point);
- gpoint->y = OGR_G_GetY (poGeometry, point);
+ gpoint->x = OGR_G_GetX (poGeometryIns, point);
+ gpoint->y = OGR_G_GetY (poGeometryIns, point);
- g_ptr_array_add (gar_points, gpoint);
+ gpoints = g_slist_append (gpoints, gpoint);
}
- geometry = gtk_gis_geometry_line_new_from_array (gar_points);
+ geometry = gtk_gis_geometry_polygon_new_from_list (gpoints);
}
- else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
- {
- gint num_geometries;
- gint i_geometry;
-
- OGRGeometryH poGeometryIns;
-
- num_geometries = OGR_G_GetGeometryCount (poGeometry);
-
- for (i_geometry = 0; i_geometry < num_geometries; i_geometry++)
- {
- gint points;
- gint point;
- GPtrArray *gar_points;
-
- GtkGisPoint *gpoint;
-
- poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry);
-
- gar_points = g_ptr_array_new ();
-
- points = OGR_G_GetPointCount (poGeometry);
-
- for (point = 0; point < points; point++)
- {
- gpoint = g_malloc0 (sizeof (GtkGisPoint));
-
- gpoint->x = OGR_G_GetX (poGeometry, point);
- gpoint->y = OGR_G_GetY (poGeometry, point);
-
- g_ptr_array_add (gar_points, gpoint);
- }
-
- geometry = gtk_gis_geometry_polygon_new_from_array (gar_points);
- }
- }
-
- geometries = g_list_append (geometries, geometry);
}
+
+ geometries = g_list_append (geometries, geometry);
}
return geometries;
poGeometry = OGR_F_GetGeometryRef (feature);
if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
+ && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
{
type = LAYER_GEOMETRY_TYPE_POINT;
}
else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
+ && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
{
type = LAYER_GEOMETRY_TYPE_LINE;
}
else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
+ && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
{
type = LAYER_GEOMETRY_TYPE_POLYGON;
}
gtk_widget_show_all (window);
+ gtk_gis_zoom_to_max (GTK_GIS (gtkgis));
+
gtk_main ();
return 0;
<gtkgis>
- <layer name="alaska">
+ <!--<layer name="alaska">
<source>
<shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/alaska.shp" />
</source>
- </layer>
+ </layer>-->
<!--<layer name="airports">
<source>
<shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/airports.shp" />
</source>
- </layer>
+ </layer>-->
<layer name="railroads">
<source>
</source>
</layer>
- <layer name="rivers">
+ <!--<layer name="rivers">
<source>
<shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/rivers.shp" />
</source>