<!ELEMENT group (layer*)>
-<!ELEMENT layer (source)>
+<!ELEMENT layer (source, style?)>
<!ATTLIST layer
name CDATA #REQUIRED
visible (y | n) "y"
<!ATTLIST
filename CDATA #REQUIRED
>
+
+<!ELEMENT style (width?, stroke-color?, fill-color?)>
+
+<!ELEMENT width (#PCDATA)>
+<!ELEMENT stroke-color (#PCDATA)>
+<!ELEMENT fill-color (#PCDATA)>
gtk_gis_layer_get_extent
gtk_gis_layer_get_editable
gtk_gis_layer_set_editable
+gtk_gis_layer_get_style
+gtk_gis_layer_set_style
gtk_gis_layer_draw
</SECTION>
GtkGisLayer *layer,gboolean editable
</FUNCTION>
<FUNCTION>
+<NAME>gtk_gis_layer_get_style</NAME>
+<RETURNS>GtkGisLayerStyle *</RETURNS>
+GtkGisLayer *layer
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_gis_layer_set_style</NAME>
+<RETURNS>void </RETURNS>
+GtkGisLayer *layer, GtkGisLayerStyle style
+</FUNCTION>
+<FUNCTION>
<NAME>gtk_gis_layer_draw</NAME>
<RETURNS>void </RETURNS>
GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale
{
GObjectClass parent_class;
- GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale);
+ GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
};
</STRUCT>
<FUNCTION>
<FUNCTION>
<NAME>gtk_gis_geometry_draw</NAME>
<RETURNS>GooCanvasItem *</RETURNS>
-GtkGisGeometry *geometry, GtkGisScale *scale
+GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle style
</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_GIS_LAYER_SOURCE_POSTGIS</NAME>
11% symbol docs coverage.
-21 symbols documented.
+22 symbols documented.
7 symbols incomplete.
-169 not documented.
+170 not documented.
GTK_GIS
gtk_gis_layer_get_extent
gtk_gis_layer_get_name
gtk_gis_layer_get_source
+gtk_gis_layer_get_style
gtk_gis_layer_get_type
gtk_gis_layer_get_xml
gtk_gis_layer_new (geometrytype, geometry_type)
GtkGisLayerSourceRasterClass
GtkGisLayerSourceShpClass
GtkGisLayersGroupClass
+gtk_gis_layer_get_style
+gtk_gis_layer_set_style
@geometry:
@scale:
+@style:
@Returns:
gdouble xy;
} GtkGisScale;
-typedef enum
- {
- LAYER_GEOMETRY_TYPE_POINT,
- LAYER_GEOMETRY_TYPE_LINE,
- LAYER_GEOMETRY_TYPE_POLYGON,
- LAYER_GEOMETRY_TYPE_RASTER
- } GtkGisLayerGeometryType;
-
typedef struct
{
gdouble min_x;
gdouble max_y;
} GtkGisLayerExtent;
+typedef struct
+ {
+ gdouble width;
+ gchar *stroke_color;
+ gchar *fill_color;
+ } GtkGisLayerStyle;
+
+typedef enum
+ {
+ LAYER_GEOMETRY_TYPE_POINT,
+ LAYER_GEOMETRY_TYPE_LINE,
+ LAYER_GEOMETRY_TYPE_POLYGON,
+ LAYER_GEOMETRY_TYPE_RASTER
+ } GtkGisLayerGeometryType;
+
G_END_DECLS
*
*/
GooCanvasItem
-*gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale)
+*gtk_gis_geometry_draw (GtkGisGeometry *geometry,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style)
{
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, scale);
+ item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry, scale, style);
}
return item;
{
GObjectClass parent_class;
- GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale);
+ GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
};
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, GtkGisScale *scale);
+GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
G_END_DECLS
static gchar *convert_comma_to_dot (gchar *str);
-static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
static void gtk_gis_geometry_line_set_property (GObject *object,
guint property_id,
}
static GooCanvasItem
-*gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale)
+*gtk_gis_geometry_line_draw (GtkGisGeometry *line,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style)
{
GtkGisGeometryLinePrivate *priv;
GooCanvasItem *item = NULL;
path = convert_comma_to_dot (path);
item = goo_canvas_path_new (NULL,
path,
- "line-width", 0.5 / scale->xy,
+ "line-width", style.width / scale->xy,
+ "stroke-color", style.stroke_color,
NULL);
}
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, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
static void gtk_gis_geometry_point_set_property (GObject *object,
guint property_id,
}
static
-GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale)
+GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style)
{
GooCanvasItem *item = NULL;
item = goo_canvas_ellipse_new (NULL,
priv->point->x, priv->point->y,
0.5 / scale->x, 0.5 / scale->y,
- "line-width", 0.5 / scale->xy,
- "fill-color", "black",
+ "line-width", style.width / scale->xy,
+ "stroke-color", style.stroke_color,
+ "fill-color", style.fill_color,
NULL);
}
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, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
static void gtk_gis_geometry_polygon_set_property (GObject *object,
guint property_id,
}
static GooCanvasItem
-*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale)
+*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style)
{
GtkGisGeometryPolygonPrivate *priv;
GooCanvasItem *polygon_item = NULL;
while (cur != NULL)
{
line = (GtkGisGeometry *)cur->data;
- item = gtk_gis_geometry_draw (line, scale);
+ item = gtk_gis_geometry_draw (line, scale, style);
if (item != NULL)
{
static void gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry_raster);
static
-GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale);
+GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style);
static void gtk_gis_geometry_raster_set_property (GObject *object,
guint property_id,
}
static GooCanvasItem
-*gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale)
+*gtk_gis_geometry_raster_draw (GtkGisGeometry *raster,
+ GtkGisScale *scale,
+ GtkGisLayerStyle style)
{
GooCanvasItem *item = NULL;
{
xmlNode *xml_layer;
gchar *layer_name;
+ GtkGisLayer *layer;
xml_layer = cur;
layer_name = g_strdup_printf ("layer");
}
+ /* TO DO
+ * don't use a cycle: first find source and then style
+ */
cur = cur->children;
while (cur != NULL)
{
|| xmlStrcmp (cur->name, "raster") == 0))
{
xmlNode *xml_source_spec;
- GtkGisLayer *layer = NULL;
GtkGisLayerSource *layer_source = NULL;
xml_source_spec = cur;
}
else if (xmlStrcmp (cur->name, "raster") == 0)
{
- layer_source = gtk_gis_layer_source_raster_new_from_xml (cur);
+ layer_source = gtk_gis_layer_source_raster_new_from_xml (cur);
}
if (layer_source != NULL)
}
cur = xml_source;
}
+ else if (cur->type == XML_ELEMENT_NODE
+ && xmlStrcmp (cur->name, "style") == 0)
+ {
+ xmlNode *xml_style;
+ GtkGisLayerStyle style;
+
+ xml_style = cur;
+
+ cur = cur->children;
+ while (cur != NULL)
+ {
+ if (cur->type == XML_ELEMENT_NODE
+ && (xmlStrcmp (cur->name, "width") == 0))
+ {
+ style.width = g_strtod ((gchar *)xmlNodeGetContent (cur), NULL);
+ }
+ else if (cur->type == XML_ELEMENT_NODE
+ && (xmlStrcmp (cur->name, "stroke-color") == 0))
+ {
+ style.stroke_color = g_strdup ((gchar *)xmlNodeGetContent (cur));
+ }
+ else if (cur->type == XML_ELEMENT_NODE
+ && (xmlStrcmp (cur->name, "fill-color") == 0))
+ {
+ style.fill_color = g_strdup ((gchar *)xmlNodeGetContent (cur));
+ }
+ cur = cur->next;
+ }
+
+ gtk_gis_layer_set_style (layer, style);
+
+ cur = xml_style;
+ }
+
cur = cur->next;
}
cur = xml_layer;
GList *geometries;
gboolean editable;
+
+ GtkGisLayerStyle *style;
};
G_DEFINE_TYPE (GtkGisLayer, gtk_gis_layer, G_TYPE_OBJECT)
gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer)
{
GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (gtk_gis_layer);
+
+ priv->style = g_malloc (sizeof (GtkGisLayerStyle));
+ priv->style->width = 0.5;
+ priv->style->stroke_color = g_strdup ("black");
+ priv->style->fill_color = g_strdup ("white");
}
/**
priv->editable = editable;
}
+/**
+ * gtk_gis_layer_get_style:
+ * @layer: a #GtkGisLayer object.
+ *
+ * Returns: a pointer to a #GtkGisLayerStyle struct. This is a copy of the struct
+ * inside the object, so it must be free after use.
+ */
+GtkGisLayerStyle
+*gtk_gis_layer_get_style (GtkGisLayer *layer)
+{
+ GtkGisLayerPrivate *priv;
+ GtkGisLayerStyle *style;
+
+ g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL);
+
+ priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+ style = g_malloc (sizeof (GtkGisLayerStyle));
+ style = g_memdup (priv->style, sizeof (GtkGisLayerStyle));
+
+ return style;
+}
+
+/**
+ * gtk_gis_layer_set_stroke_color:
+ * @layer: a #GtkGisLayer object.
+ * @style: a #GtkGisLayerStyle struct.
+ *
+ * Valid only for layers that aren't rasters.
+ */
+void
+gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style)
+{
+ GtkGisLayerPrivate *priv;
+ GtkGisLayerStyle new_style;
+
+ g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+ priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+ if (style.width != 0)
+ {
+ new_style.width = style.width;
+ }
+ else
+ {
+ new_style.width = priv->style->width;
+ }
+ if (style.stroke_color != NULL)
+ {
+ new_style.stroke_color = g_strdup (style.stroke_color);
+ }
+ else
+ {
+ new_style.stroke_color = g_strdup (priv->style->stroke_color);
+ }
+ if (style.fill_color != NULL)
+ {
+ new_style.fill_color = g_strdup (style.fill_color);
+ }
+ else
+ {
+ new_style.fill_color = g_strdup (priv->style->fill_color);
+ }
+
+ g_free (priv->style);
+ priv->style = g_memdup (&new_style, sizeof (GtkGisLayerStyle));
+}
+
/**
* gtk_gis_layer_draw:
* @layer: a #GtkGisLayer object.
gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
{
GtkGisLayerPrivate *priv;
-
GList *cur;
-
GooCanvasItem *item;
+ g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+ g_return_if_fail (GOO_IS_CANVAS_ITEM (root));
+
priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
gtk_gis_layer_fill_from_source (layer);
cur = g_list_first (priv->geometries);
while (cur != NULL)
{
- item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale);
+ item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, *priv->style);
if (item != NULL)
{
void gtk_gis_layer_set_editable (GtkGisLayer *layer,
gboolean editable);
+GtkGisLayerStyle *gtk_gis_layer_get_style (GtkGisLayer *layer);
+void gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style);
+
void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale);
<source>
<shape filename="tests/samples/railroads.shp" />
</source>
+ <style>
+ <stroke-color>red</stroke-color>
+ </style>
</layer>
<layer name="rivers">
<source>
<shape filename="tests/samples/rivers.shp" />
</source>
+ <style>
+ <stroke-color>blue</stroke-color>
+ </style>
</layer>
</gtkgis>