Plans [was: Re: Gconf or GSettings? - leading to a wider question]

Dirk Hohndel dirk at hohndel.org
Sun Jan 27 15:59:56 PST 2013


I still have not been able to figure out what causes the odd scrolling
issue where it sometimes suddenly jumps to location 0,0.

I pushed this out in the hope that someone else sees what's wrong while
playing with this, especially now that the code is there to edit GPS
locations.

/D

Dirk Hohndel <dirk at hohndel.org> writes:

>> Hi,
>>
>> here is an alternative patch that does it with a bit of algebra instead of the binary search.
>>
>> There is just one awkward problem: It should do nothing when trying to scroll out from minimal zoom or scroll in from maximal zoom. My understanding of http://nzjrs.github.com/osm-gps-map/docs/reference/html/OsmGpsMap.html#OsmGpsMap.properties
>> is that there are "properties" zoom, max-zoom, min-zoom of the map widget that should allow to test these cases. Unfortunately, my gtk knowledge is not existent and I have not managed to obtain these. This needs to be looked at by someone else.
>>
>> But the "zoom fixes position under mouse pointer" works.
>>
>
> Well, sort of. If you keep the mouse still and zoom out a few steps and
> back in and out and in the position drifts. So there still is some error
> in the math.
>
> Also, occasionally (and I haven't figured out what triggers it) zooming
> out suddenly resets your position to 0,0.
>
> I have done some MASSIVE whitespace cleanup. Changed it to using the
> correct g_object interface. And I was almost ready to push it - but
> there's no Signed-off-by line :-(
>
> Here's the latest patch with all my changes. Please test, maybe figure
> out the 'drift' issue and send it back with a good commit message and an
> SOB line.
>
> Thanks
>
> /D
>
> From 5a23e7ec511376bbf393385971f9afe087fec09b Mon Sep 17 00:00:00 2001
> From: "Robert C. Helling" <helling at atdotde.de>
> Date: Wed, 23 Jan 2013 00:03:55 +0100
> Subject: [PATCH] Modify map zoom to keep the point under the mouse cursor
>  constant
>
> This version uses some algebra to figure out the correct new parameters
> for the mercator projection used in osm-gps-map.
>
> It still seems "slightly off", but pretty close. There is also an
> occasional bug when zooming out.
>
> [Dirk Hohndel: switched this to using the correct interface to get the
>                object properties and did some serious whitespace cleanup]
>
> Signed-off-by: Robert C. Helling <helling at atdotde.de>
> Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
> ---
>  gps.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/gps.c b/gps.c
> index f68da03..6d71f85 100644
> --- a/gps.c
> +++ b/gps.c
> @@ -30,10 +30,53 @@ static void on_close(GtkWidget *widget, gpointer user_data)
>  static gboolean scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer data)
>  {
>  	OsmGpsMap *map = (OsmGpsMap *)widget;
> -	if (event->direction == GDK_SCROLL_UP)
> +	OsmGpsMapPoint *pt, *lt, *rb, *target;
> +	float target_lat, target_lon;
> +	gint ltx, lty, rbx, rby, target_x, target_y;
> +	gint zoom, max_zoom, min_zoom;
> +
> +	g_object_get(widget, "max-zoom", &max_zoom, "zoom", &zoom, "min-zoom", &min_zoom, NULL);
> +
> +	pt = osm_gps_map_point_new_degrees(0.0, 0.0);
> +	lt = osm_gps_map_point_new_degrees(0.0, 0.0);
> +	rb = osm_gps_map_point_new_degrees(0.0, 0.0);
> +	target = osm_gps_map_point_new_degrees(0.0, 0.0);
> +
> +	osm_gps_map_convert_screen_to_geographic(map, event->x, event->y, pt);
> +
> +	osm_gps_map_get_bbox(map, lt, rb);
> +	osm_gps_map_convert_geographic_to_screen(map, lt, &ltx, &lty);
> +	osm_gps_map_convert_geographic_to_screen(map, rb, &rbx, &rby);
> +
> +	if (event->direction == GDK_SCROLL_UP) {
> +	        if (zoom == max_zoom)
> +		      return TRUE;
> +
> +		target_x = event->x + ((ltx + rbx) / 2.0 - (gint)(event->x)) / 2;
> +		target_y = event->y + ((lty + rby) / 2.0 - (gint)(event->y)) / 2;
> +
> +		osm_gps_map_convert_screen_to_geographic(map, target_x, target_y, target);
> +		osm_gps_map_point_get_degrees(target, &target_lat, &target_lon);
> +
>  		osm_gps_map_zoom_in(map);
> -	else if (event->direction == GDK_SCROLL_DOWN)
> +	} else if (event->direction == GDK_SCROLL_DOWN) {
> +	        if(zoom == min_zoom)
> +		      return TRUE;
> +
> +		target_x = event->x + ((ltx + rbx) / 2.0 - (gint)(event->x)) * 2;
> +		target_y = event->y + ((lty + rby) / 2.0 - (gint)(event->y)) * 2;
> +
> +		osm_gps_map_convert_screen_to_geographic(map, target_x, target_y, target);
> +		osm_gps_map_point_get_degrees(target, &target_lat, &target_lon);
> +
>  		osm_gps_map_zoom_out(map);
> +	}
> +
> +	/* There is no OSM interface to do this afaik. Hack something together */
> +	/* set_map_pt_at_xy(map, pt, event->x, event->y); */
> +
> +	osm_gps_map_set_center(map, target_lat, target_lon);
> +
>  	/* don't allow the insane default handler to get its hands on this event */
>  	return TRUE;
>  }
> -- 
> 1.8.0.rc0.18.gf84667d


More information about the subsurface mailing list