From 2461f62440ea74536d7b31f2cc20cf4426dc1e37 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 18 Aug 2015 23:34:55 +0200 Subject: [PATCH] Added function ::get_extent. --- src/gtkmapserver.c | 56 +++++++++++++++++++++++++++++++++++++++++++- src/gtkmapserver.h | 10 ++++++++ tests/gtkmapserver.c | 7 ++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/gtkmapserver.c b/src/gtkmapserver.c index a9b54c8..ec33bf4 100644 --- a/src/gtkmapserver.c +++ b/src/gtkmapserver.c @@ -116,6 +116,11 @@ gtk_mapserver_init (GtkMapserver *gtk_mapserver) priv->sel_y_start = 0.0; } +/** + * gtk_mapserver_new: + * + * Returns: the new created #GtkMapserver object. + */ GtkWidget *gtk_mapserver_new () { @@ -188,6 +193,13 @@ GtkWidget return gtk_mapserver; } +/** + * gtk_mapserver_get_soup_message: + * @gtkm: + * @url: + * + * Returns: + */ SoupMessage *gtk_mapserver_get_soup_message (GtkMapserver *gtkm, const gchar *url) @@ -214,6 +226,11 @@ SoupMessage return msg; } +/** + * gtk_mapserver_set_home: + * @gtkm: + * @url: + */ void gtk_mapserver_set_home (GtkMapserver *gtkm, const gchar *url) @@ -249,8 +266,9 @@ gtk_mapserver_set_home (GtkMapserver *gtkm, { gdk_pixbuf_loader_close (pxb_loader, NULL); } + + g_object_unref (msg); } - g_object_unref (msg); if (pxb_loader != NULL) { g_object_set (G_OBJECT (priv->img), @@ -268,6 +286,42 @@ gtk_mapserver_set_home (GtkMapserver *gtkm, } } +/** + * gtk_mapserver_get_extent: + * @gtkm: + * @url: + * + * Returns: a #GtkMapserverExtent. Mapserver must returns an html page in the form "minx miny maxx maxy". + */ +GtkMapserverExtent +*gtk_mapserver_get_extent (GtkMapserver *gtkm, const gchar *url) +{ + GtkMapserverExtent *ext; + SoupMessage *msg; + + ext = NULL; + + msg = gtk_mapserver_get_soup_message (gtkm, url); + if (msg != NULL) + { + gchar **coords; + + ext = (GtkMapserverExtent *)g_new0 (GtkMapserverExtent, 1); + + coords = g_strsplit (msg->response_body->data, " ", -1); + ext->minx = g_strtod (coords[0], NULL); + ext->miny = g_strtod (coords[1], NULL); + ext->maxx = g_strtod (coords[2], NULL); + ext->maxy = g_strtod (coords[3], NULL); + + g_strfreev (coords); + + g_object_unref (msg); + } + + return ext; +} + /* PRIVATE */ static void gtk_mapserver_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) diff --git a/src/gtkmapserver.h b/src/gtkmapserver.h index 4d73727..f5aa7db 100644 --- a/src/gtkmapserver.h +++ b/src/gtkmapserver.h @@ -66,6 +66,16 @@ SoupMessage *gtk_mapserver_get_soup_message (GtkMapserver *gtkm, void gtk_mapserver_set_home (GtkMapserver *gtkm, const gchar *url); +typedef struct + { + gdouble minx; + gdouble miny; + gdouble maxx; + gdouble maxy; + } GtkMapserverExtent; + +GtkMapserverExtent *gtk_mapserver_get_extent (GtkMapserver *gtkm, const gchar *url); + G_END_DECLS diff --git a/tests/gtkmapserver.c b/tests/gtkmapserver.c index b661d70..3ef61df 100644 --- a/tests/gtkmapserver.c +++ b/tests/gtkmapserver.c @@ -35,6 +35,7 @@ main (int argc, char **argv) { GtkWidget *window; GtkWidget *gtkmap; + GtkMapserverExtent *ext; /* Initialize GTK+. */ gtk_init (&argc, &argv); @@ -53,6 +54,12 @@ main (int argc, char **argv) gtk_mapserver_set_home (GTK_MAPSERVER (gtkmap), "http://atlante/cgi-bin/mapserv?map=/var/www_mapper/www_pm4/config/cdu/RU_cdu.map&mode=map&layers=catasto"); + ext = gtk_mapserver_get_extent (GTK_MAPSERVER (gtkmap), "http://atlante/cgi-bin/mapserv?map=/var/www_mapper/www_pm4/config/cdu/RU_cdu.map&mode=itemquery&qlayer=catasto&qstring=\"foglio\"='2' and \"part\"='22'&map.layer[catasto]=TEMPLATE \"shpext.html\""); + if (ext != NULL) + { + g_message ("Extent: %f %f %f %f", ext->minx, ext->miny, ext->maxx, ext->maxy); + } + /* Pass control to the GTK+ main event loop. */ gtk_main (); -- 2.49.0