]> saetta.ns0.it Git - libgtkmapserver/commitdiff
Added function ::get_extent.
authorAndrea Zagli <andrea.zagli@email.it>
Tue, 18 Aug 2015 21:34:55 +0000 (23:34 +0200)
committerAndrea Zagli <andrea.zagli@email.it>
Tue, 18 Aug 2015 21:34:55 +0000 (23:34 +0200)
src/gtkmapserver.c
src/gtkmapserver.h
tests/gtkmapserver.c

index a9b54c85014714663e0177cbf52ce6fd11245183..ec33bf47b2681690bcf93b041f26138e3d13e8d4 100644 (file)
@@ -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)
index 4d73727a7fe27e843d197a1ca0aa753660f82b40..f5aa7dbad9f03caa8e7915204684e9b9d2a4f536 100644 (file)
@@ -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
 
index b661d7038b4faa104ccb4b83db60a2d4c85edf59..3ef61dfdbd684529e96c1d6b306db3ce673e7962 100644 (file)
@@ -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 ();