--- trunk/src/map-tool.c 2009/08/06 20:23:12 47 +++ trunk/src/map-tool.c 2009/08/07 07:57:33 48 @@ -24,6 +24,8 @@ #include "osm-gps-map.h" #endif +#define GPS_DEFAULT_ZOOM 13 + /* equatorial radius in meters */ #define EQ_RADIUS (6378137.0) @@ -80,7 +82,7 @@ } static void map_zoom(map_context_t *context, int step) { - int zoom; + gint zoom; OsmGpsMap *map = OSM_GPS_MAP(context->widget); g_object_get(map, "zoom", &zoom, NULL); zoom = osm_gps_map_set_zoom(map, zoom+step); @@ -88,6 +90,9 @@ /* enable/disable zoom buttons as required */ gtk_widget_set_sensitive(context->zoomin, zoom<17); gtk_widget_set_sensitive(context->zoomout, zoom>1); + + /* save new zoom */ + context->appdata->map.zoom = zoom; } static gboolean @@ -107,7 +112,7 @@ pos_t *refpos = get_pos(context->appdata); if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), - refpos->lat, refpos->lon, 14); + refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); } else { /* no coordinates given: display the entire world */ osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), @@ -146,8 +151,31 @@ GdkEventConfigure *event, map_context_t *context) { - cb_map_gps(NULL, context); + /* set default values if they are invalid */ + if(!context->appdata->map.zoom || + isnan(context->appdata->map.pos.lat) || + isnan(context->appdata->map.pos.lon)) { + printf("no valid map position found\n"); + + pos_t *refpos = get_pos(context->appdata); + if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { + /* use gps position if present */ + context->appdata->map.pos = *refpos; + context->appdata->map.zoom = GPS_DEFAULT_ZOOM; + } else { + /* use world map otherwise */ + context->appdata->map.pos.lat = 0.0; + context->appdata->map.pos.lon = 0.0; + context->appdata->map.zoom = 1; + } + } + /* jump to initial position */ + osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), + context->appdata->map.pos.lat, + context->appdata->map.pos.lon, + context->appdata->map.zoom); + return FALSE; } @@ -522,7 +550,7 @@ } static int dist2pixel(map_context_t *context, float km, float lat) { - int zoom; + gint zoom; g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); /* world at zoom 1 == 512 pixels */ @@ -561,9 +589,9 @@ static gboolean on_map_button_release_event(GtkWidget *widget, GdkEventButton *event, map_context_t *context) { - if(context->press_on) { - OsmGpsMap *map = OSM_GPS_MAP(context->widget); + OsmGpsMap *map = OSM_GPS_MAP(context->widget); + if(context->press_on) { pos_t pos = coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); @@ -574,16 +602,36 @@ cache_popup(context, nearest); } context->press_on = NULL; + } else { + /* save new map position */ + gfloat lat, lon; + g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); + context->appdata->map.pos.lat = lat; + context->appdata->map.pos.lon = lon; } return FALSE; } +static void save_map_state(map_context_t *context) { + /* save map parameters */ + OsmGpsMap *map = OSM_GPS_MAP(context->widget); + gint zoom; + g_object_get(map, "zoom", &zoom, NULL); + context->appdata->map.zoom = zoom; + + gfloat lat, lon; + g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); + context->appdata->map.pos.lat = lat; + context->appdata->map.pos.lon = lon; +} #if MAEMO_VERSION_MAJOR == 5 static void on_window_destroy(GtkWidget *widget, map_context_t *context) { printf("destroy map view\n"); + save_map_state(context); + /* restore cur_view */ context->appdata->cur_view = context->old_view; @@ -698,6 +746,7 @@ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); gtk_widget_show_all(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); + save_map_state(context); gtk_timeout_remove(context->handler_id); gtk_widget_destroy(dialog); g_free(context);