Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 47 by harbaum, Thu Aug 6 20:23:12 2009 UTC revision 48 by harbaum, Fri Aug 7 07:57:33 2009 UTC
# Line 24  Line 24 
24  #include "osm-gps-map.h"  #include "osm-gps-map.h"
25  #endif  #endif
26    
27    #define GPS_DEFAULT_ZOOM 13
28    
29  /* equatorial radius in meters */  /* equatorial radius in meters */
30  #define EQ_RADIUS     (6378137.0)  #define EQ_RADIUS     (6378137.0)
31    
# Line 80  static const char *get_proxy_uri(appdata Line 82  static const char *get_proxy_uri(appdata
82  }  }
83    
84  static void map_zoom(map_context_t *context, int step) {  static void map_zoom(map_context_t *context, int step) {
85    int zoom;    gint zoom;
86    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
87    g_object_get(map, "zoom", &zoom, NULL);    g_object_get(map, "zoom", &zoom, NULL);
88    zoom = osm_gps_map_set_zoom(map, zoom+step);    zoom = osm_gps_map_set_zoom(map, zoom+step);
# Line 88  static void map_zoom(map_context_t *cont Line 90  static void map_zoom(map_context_t *cont
90    /* enable/disable zoom buttons as required */    /* enable/disable zoom buttons as required */
91    gtk_widget_set_sensitive(context->zoomin, zoom<17);    gtk_widget_set_sensitive(context->zoomin, zoom<17);
92    gtk_widget_set_sensitive(context->zoomout, zoom>1);    gtk_widget_set_sensitive(context->zoomout, zoom>1);
93    
94      /* save new zoom */
95      context->appdata->map.zoom = zoom;
96  }  }
97    
98  static gboolean  static gboolean
# Line 107  cb_map_gps(GtkButton *button, map_contex Line 112  cb_map_gps(GtkButton *button, map_contex
112    pos_t *refpos = get_pos(context->appdata);    pos_t *refpos = get_pos(context->appdata);
113    if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {    if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
114      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
115                                refpos->lat, refpos->lon, 14);                        refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM);
116    } else {    } else {
117      /* no coordinates given: display the entire world */      /* no coordinates given: display the entire world */
118      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
# Line 146  static gboolean on_map_configure(GtkWidg Line 151  static gboolean on_map_configure(GtkWidg
151                                   GdkEventConfigure *event,                                   GdkEventConfigure *event,
152                                   map_context_t *context) {                                   map_context_t *context) {
153    
154    cb_map_gps(NULL, context);    /* set default values if they are invalid */
155      if(!context->appdata->map.zoom ||
156         isnan(context->appdata->map.pos.lat) ||
157         isnan(context->appdata->map.pos.lon)) {
158        printf("no valid map position found\n");
159    
160        pos_t *refpos = get_pos(context->appdata);
161        if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
162          /* use gps position if present */
163          context->appdata->map.pos = *refpos;
164          context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
165        } else {
166          /* use world map otherwise */
167          context->appdata->map.pos.lat = 0.0;
168          context->appdata->map.pos.lon = 0.0;
169          context->appdata->map.zoom = 1;
170        }
171      }
172    
173      /* jump to initial position */
174      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
175                                context->appdata->map.pos.lat,
176                                context->appdata->map.pos.lon,
177                                context->appdata->map.zoom);
178    
179    return FALSE;    return FALSE;
180  }  }
181    
# Line 522  pos_t coord2pos(coord_t coo) { Line 550  pos_t coord2pos(coord_t coo) {
550  }  }
551    
552  static int dist2pixel(map_context_t *context, float km, float lat) {  static int dist2pixel(map_context_t *context, float km, float lat) {
553    int zoom;    gint zoom;
554    g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL);    g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL);
555    
556    /* world at zoom 1 == 512 pixels */    /* world at zoom 1 == 512 pixels */
# Line 561  on_map_button_press_event(GtkWidget *wid Line 589  on_map_button_press_event(GtkWidget *wid
589  static gboolean  static gboolean
590  on_map_button_release_event(GtkWidget *widget,  on_map_button_release_event(GtkWidget *widget,
591                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
592    if(context->press_on) {    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
     OsmGpsMap *map = OSM_GPS_MAP(context->widget);  
593    
594      if(context->press_on) {
595      pos_t pos =      pos_t pos =
596        coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));        coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));
597    
# Line 574  on_map_button_release_event(GtkWidget *w Line 602  on_map_button_release_event(GtkWidget *w
602          cache_popup(context, nearest);          cache_popup(context, nearest);
603      }      }
604      context->press_on = NULL;      context->press_on = NULL;
605      } else {
606        /* save new map position */
607        gfloat lat, lon;
608        g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
609        context->appdata->map.pos.lat = lat;
610        context->appdata->map.pos.lon = lon;
611    }    }
612    
613    return FALSE;    return FALSE;
614  }  }
615    
616    static void save_map_state(map_context_t *context) {
617      /* save map parameters */
618      OsmGpsMap *map = OSM_GPS_MAP(context->widget);
619      gint zoom;
620      g_object_get(map, "zoom", &zoom, NULL);
621      context->appdata->map.zoom = zoom;
622    
623      gfloat lat, lon;
624      g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
625      context->appdata->map.pos.lat = lat;
626      context->appdata->map.pos.lon = lon;
627    }
628    
629  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
630  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {
631    printf("destroy map view\n");    printf("destroy map view\n");
632    
633      save_map_state(context);
634    
635    /* restore cur_view */    /* restore cur_view */
636    context->appdata->cur_view = context->old_view;    context->appdata->cur_view = context->old_view;
637    
# Line 698  void map(appdata_t *appdata) { Line 746  void map(appdata_t *appdata) {
746    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
747    gtk_widget_show_all(dialog);    gtk_widget_show_all(dialog);
748    gtk_dialog_run(GTK_DIALOG(dialog));    gtk_dialog_run(GTK_DIALOG(dialog));
749      save_map_state(context);
750    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
751    gtk_widget_destroy(dialog);    gtk_widget_destroy(dialog);
752    g_free(context);    g_free(context);

Legend:
Removed from v.47  
changed lines
  Added in v.48