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

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

revision 84 by harbaum, Fri Aug 28 07:52:01 2009 UTC revision 93 by harbaum, Wed Sep 2 12:25:51 2009 UTC
# Line 17  Line 17 
17   * along with GPXView.  If not, see <http://www.gnu.org/licenses/>.   * along with GPXView.  If not, see <http://www.gnu.org/licenses/>.
18   */   */
19    
20    /*
21     * http://topo.geofabrik.de/relief/${z}/${x}/${y}.png  8-15
22     * http://topo.geofabrik.de/trail/${z}/${x}/${y}.png   8-15
23     */
24    
25  #include "gpxview.h"  #include "gpxview.h"
26  #include "converter.h"  #include "converter.h"
27  #include <math.h>    // for isnan  #include <math.h>    // for isnan
# Line 33  Line 38 
38    
39  // #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENSTREETMAP  // #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENSTREETMAP
40  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENCYCLEMAP  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENCYCLEMAP
41    // #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_GOOGLE_STREET
42  #define GPS_DEFAULT_ZOOM 13  #define GPS_DEFAULT_ZOOM 13
43    
44  #define PROXY_KEY  "/system/http_proxy/"  #define PROXY_KEY  "/system/http_proxy/"
# Line 138  static gboolean on_map_configure(GtkWidg Line 144  static gboolean on_map_configure(GtkWidg
144                                   GdkEventConfigure *event,                                   GdkEventConfigure *event,
145                                   map_context_t *context) {                                   map_context_t *context) {
146    
147    /* set default values if they are invalid */    if(!context->map_complete) {
148    if(!context->appdata->map.zoom ||  
149       isnan(context->appdata->map.pos.lat) ||      /* set default values if they are invalid */
150       isnan(context->appdata->map.pos.lon)) {      if(!context->appdata->map.zoom ||
151      printf("no valid map position found\n");         isnan(context->appdata->map.pos.lat) ||
152           isnan(context->appdata->map.pos.lon)) {
153      pos_t *refpos = get_pos(context->appdata);        printf("no valid map position found\n");
154      if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {  
155        /* use gps position if present */        pos_t *refpos = get_pos(context->appdata);
156        context->appdata->map.pos = *refpos;        if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
157        context->appdata->map.zoom = GPS_DEFAULT_ZOOM;          /* use gps position if present */
158      } else {          context->appdata->map.pos = *refpos;
159        /* use world map otherwise */          context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
160        context->appdata->map.pos.lat = 0.0;        } else {
161        context->appdata->map.pos.lon = 0.0;          /* use world map otherwise */
162        context->appdata->map.zoom = 1;          context->appdata->map.pos.lat = 0.0;
163            context->appdata->map.pos.lon = 0.0;
164            context->appdata->map.zoom = 1;
165          }
166      }      }
167    
168        /* jump to initial position */
169        osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
170                                  context->appdata->map.pos.lat,
171                                  context->appdata->map.pos.lon,
172                                  context->appdata->map.zoom);
173        context->map_complete = TRUE;
174    }    }
175    
   /* 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);  
   
176    return FALSE;    return FALSE;
177  }  }
178    
# Line 232  on_map_button_press_event(GtkWidget *wid Line 242  on_map_button_press_event(GtkWidget *wid
242                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
243    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
244    
245      /* check if we actually clicked parts of the OSD */
246      if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE)
247        return FALSE;
248    
249    /* got a press event without release event? eat it! */    /* got a press event without release event? eat it! */
250    if(context->press_on != NULL) {    if(context->press_on != NULL) {
251      printf("PRESS: already\n");      printf("PRESS: already\n");
252      return TRUE;      return FALSE;
253    }    }
254    
255    pos_t pos =    pos_t pos =
# Line 443  static void on_window_destroy(GtkWidget Line 457  static void on_window_destroy(GtkWidget
457    context->appdata->map.pos.lat = lat;    context->appdata->map.pos.lat = lat;
458    context->appdata->map.pos.lon = lon;    context->appdata->map.pos.lon = lon;
459    
460      gint source;
461      g_object_get(map, "map-source", &source, NULL);
462      context->appdata->map.source = source;
463    
464  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
465    /* restore cur_view */    /* restore cur_view */
466    context->appdata->cur_view = context->old_view;    context->appdata->cur_view = context->old_view;
# Line 484  void map(appdata_t *appdata) { Line 502  void map(appdata_t *appdata) {
502    
503    context = appdata->map.context = g_new0(map_context_t, 1);    context = appdata->map.context = g_new0(map_context_t, 1);
504    context->appdata = appdata;    context->appdata = appdata;
505      context->map_complete = FALSE;
506    
507    /* cleanup old (pre 0.8.7) path if it exists */    /* cleanup old (pre 0.8.7) path if it exists */
508    char *old_path = g_strdup_printf("%s/map/", appdata->image_path);    char *old_path = g_strdup_printf("%s/map/", appdata->image_path);
# Line 511  void map(appdata_t *appdata) { Line 530  void map(appdata_t *appdata) {
530    
531    const char *proxy = get_proxy_uri(appdata);    const char *proxy = get_proxy_uri(appdata);
532    
533      gint source = context->appdata->map.source;
534      if(!source) source = MAP_SOURCE;
535    
536    context->widget = g_object_new(OSM_TYPE_GPS_MAP,    context->widget = g_object_new(OSM_TYPE_GPS_MAP,
537                   "map-source",               MAP_SOURCE,                   "map-source",               source,
538                   "tile-cache",               path,                   "tile-cache",               path,
539                   "auto-center",              FALSE,                   "auto-center",              FALSE,
540                   "record-trip-history",      FALSE,                   "record-trip-history",      FALSE,

Legend:
Removed from v.84  
changed lines
  Added in v.93