]> saetta.ns0.it Git - libgtkgis/commitdiff
Fixed bug on proportions on GtkGis::zoom_to_max (the problem persists
authorAndrea Zagli <azagli@libero.it>
Mon, 13 Jul 2009 20:02:12 +0000 (22:02 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 13 Jul 2009 20:02:12 +0000 (22:02 +0200)
when there are raster layers).

src/geometryraster.c
src/gtkgis.c
src/layersource.c

index bcfd576147ea640d87e85b616bcb8902d7133b7e..0be8dd7fe5b0fe59e5949a2090782ca491015b0e 100644 (file)
@@ -113,7 +113,7 @@ static GooCanvasItem
        GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (GTK_GIS_GEOMETRY_RASTER (raster));
 
        if (priv->pixbuf != NULL)
-               {
+               {g_fprintf(stderr,"geometry %f %f\n",priv->x,priv->y);
                        item = goo_canvas_image_new (NULL,
                                                     priv->pixbuf,
                                                     priv->x, priv->y,
index 519030880e6fecd425c46e43c72bb791af32e6d6..27ceafeb2c795ce8b7ff9463951d7066901e4902 100644 (file)
@@ -260,7 +260,6 @@ GtkWidget
                                                                                                                                                {
                                                                                                                                                        layer = gtk_gis_layer_new_from_source (layer_source, layer_name);
                                                                                                                                                        gtk_gis_add_layer (GTK_GIS (gtkgis), layer);
-                                                                                                                                                       gtk_gis_layer_source_set_max_extent (layer_source, priv->extent);
                                                                                                                                                }
 
                                                                                                                                        cur = xml_source_spec;
@@ -376,7 +375,8 @@ gtk_gis_add_layer (GtkGis *gtkgis, GtkGisLayer *layer)
                                                        priv->extent->max_y = extent->max_y;
                                                }
                                }
-
+g_fprintf(stderr,"geometry extent %f %f %f %f\n",extent->min_x,extent->min_y,extent->max_x,extent->max_y);
+g_fprintf(stderr,"max extent %f %f %f %f\n",priv->extent->min_x,priv->extent->min_y,priv->extent->max_x,priv->extent->max_y);
                        goo_canvas_set_bounds (GOO_CANVAS (priv->canvas),
                                                           priv->extent->min_x,
                                                           priv->extent->min_y,
@@ -408,12 +408,16 @@ gtk_gis_draw (GtkGis *gtkgis)
 {
        GtkGisPrivate *priv;
        GSList *cur;
+       GtkGisLayerSource *layer_source;
 
        priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
        cur = priv->layers;
        while (cur != NULL)
                {
+                       layer_source = gtk_gis_layer_get_source ((GtkGisLayer *)cur->data);
+                       gtk_gis_layer_source_set_max_extent (layer_source, priv->extent);
+
                        gtk_gis_layer_draw ((GtkGisLayer *)cur->data, priv->canvas_root, priv->scale);
 
                        cur = g_slist_next (cur);
@@ -481,20 +485,59 @@ gtk_gis_zoom_to_max (GtkGis *gtkgis)
        gdouble extx = 1.0;
        gdouble exty = 1.0;
 
+       gdouble widget_width;
+       gdouble widget_height;
+
        priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
+       widget_width = GTK_WIDGET (gtkgis)->allocation.width;
+       widget_height = GTK_WIDGET (gtkgis)->allocation.height;
+
        scale = g_malloc0 (sizeof (GtkGisScale));
 
        if (priv->extent != NULL)
                {
+                       /* must add width or height to make the max extent
+                        * the same proportion of the canvas */
+
+                       gdouble extent_width;
+                       gdouble extent_height;
+
+                       gdouble plus;
+
+                       extent_width = priv->extent->max_x - priv->extent->min_x;
+                       extent_height = priv->extent->max_y - priv->extent->min_y;
+g_fprintf(stderr,"extent_width %f extent_height %f\n",extent_width,extent_height);
+
+                       if (extent_width > extent_height)
+                               {
+                                       plus = (((widget_height * extent_width) / widget_width) - extent_height) / 2;
+                                       priv->extent->min_y -= plus;
+                                       priv->extent->max_y += plus;
+                               }
+                       else
+                               {
+                                       plus = (((widget_width * extent_height) / widget_height) - extent_width) / 2;
+                                       priv->extent->min_x -= plus;
+                                       priv->extent->max_x += plus;
+                               }
+g_fprintf(stderr,"plus %f\n",plus);
+
+                       goo_canvas_set_bounds (GOO_CANVAS (priv->canvas),
+                                                          priv->extent->min_x,
+                                                          priv->extent->min_y,
+                                                          priv->extent->max_x,
+                                                          priv->extent->max_y);
+
                        extx = priv->extent->max_x - priv->extent->min_x;
                        exty = priv->extent->max_y - priv->extent->min_y;
+g_fprintf(stderr,"extx %f exty %f\n",extx,exty);
                }
 
-       scale->x = GTK_WIDGET (gtkgis)->allocation.width / extx;
-       scale->y = GTK_WIDGET (gtkgis)->allocation.height / exty;
+       scale->x = widget_width / extx;
+       scale->y = widget_height / exty;
        scale->xy = (scale->x + scale->y) / 2;
-
+g_fprintf(stderr,"scale_x %f scale_y %f scale_xy %f\n",scale->x,scale->y,scale->xy);
        gtk_gis_set_scale (gtkgis, scale);
 }
 
index ee12930c8fb1f93e843e3a6fcfa01220543940a3..8847b02c0ab8103e1efa3617bd6508a716d445c5 100644 (file)
@@ -213,9 +213,15 @@ GtkGisLayerExtent
                                        extent = g_malloc0 (sizeof (GtkGisLayerExtent));
 
                                        extent->min_x = adfGeoTransform[0];
-                                       extent->min_y = adfGeoTransform[3];
                                        extent->max_x = extent->min_x + GDALGetRasterXSize (priv->dataset);
-                                       extent->max_y = extent->min_y + GDALGetRasterYSize (priv->dataset);
+                                       extent->max_y = adfGeoTransform[3];
+                                       extent->min_y = extent->max_y + GDALGetRasterYSize (priv->dataset);
+
+                                       /*GDALApplyGeoTransform (adfGeoTransform,
+                                                              GDALGetRasterXSize (priv->dataset),
+                                                              GDALGetRasterYSize (priv->dataset),
+                                                              &extent->max_x,
+                                                              &extent->min_y);*/
                                }
                }
 
@@ -228,6 +234,8 @@ gtk_gis_layer_source_set_max_extent (GtkGisLayerSource *source,
 {
        GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
 
+       g_return_if_fail (extent != NULL);
+
        if (priv->max_extent == NULL)
                {
                        priv->max_extent = g_malloc0 (sizeof (GtkGisLayerExtent));
@@ -460,7 +468,7 @@ static GList
                                }
 
                        x = adfGeoTransform[0];
-                       y = /*fixy -*/ adfGeoTransform[3];
+                       y = fixy - adfGeoTransform[3];
                        width = GDALGetRasterXSize (priv->dataset);
                        height = GDALGetRasterYSize (priv->dataset);