From: Andrea Zagli Date: Mon, 13 Jul 2009 20:02:12 +0000 (+0200) Subject: Fixed bug on proportions on GtkGis::zoom_to_max (the problem persists X-Git-Tag: GTKGIS_0_0_2~7 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b8685e535083cb18a1527bced351d11c848001f0;p=libgtkgis Fixed bug on proportions on GtkGis::zoom_to_max (the problem persists when there are raster layers). --- diff --git a/src/geometryraster.c b/src/geometryraster.c index bcfd576..0be8dd7 100644 --- a/src/geometryraster.c +++ b/src/geometryraster.c @@ -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, diff --git a/src/gtkgis.c b/src/gtkgis.c index 5190308..27ceafe 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -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); } diff --git a/src/layersource.c b/src/layersource.c index ee12930..8847b02 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -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);