1 |
/* |
/* |
2 |
* Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
* Copyright (C) 2008-2009 Till Harbaum <till@harbaum.org>. |
3 |
* |
* |
4 |
* This file is part of GPXView. |
* This file is part of GPXView. |
5 |
* |
* |
24 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
25 |
#endif |
#endif |
26 |
|
|
27 |
|
#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP |
28 |
|
#define GPS_DEFAULT_ZOOM 13 |
29 |
|
|
30 |
/* equatorial radius in meters */ |
/* equatorial radius in meters */ |
31 |
#define EQ_RADIUS (6378137.0) |
#define EQ_RADIUS (6378137.0) |
32 |
|
|
83 |
} |
} |
84 |
|
|
85 |
static void map_zoom(map_context_t *context, int step) { |
static void map_zoom(map_context_t *context, int step) { |
86 |
int zoom; |
gint zoom; |
87 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
88 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
89 |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
90 |
|
|
91 |
/* enable/disable zoom buttons as required */ |
/* enable/disable zoom buttons as required */ |
92 |
gtk_widget_set_sensitive(context->zoomin, zoom<17); |
gtk_widget_set_sensitive(context->zoomin, |
93 |
gtk_widget_set_sensitive(context->zoomout, zoom>1); |
zoom < osm_gps_map_source_get_max_zoom(MAP_SOURCE)); |
94 |
|
gtk_widget_set_sensitive(context->zoomout, |
95 |
|
zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE)); |
96 |
|
|
97 |
|
/* save new zoom */ |
98 |
|
context->appdata->map.zoom = zoom; |
99 |
} |
} |
100 |
|
|
101 |
static gboolean |
static gboolean |
115 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
116 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
117 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
118 |
refpos->lat, refpos->lon, 14); |
refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); |
119 |
} else { |
} else { |
120 |
/* no coordinates given: display the entire world */ |
/* no coordinates given: display the entire world */ |
121 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
126 |
} |
} |
127 |
|
|
128 |
static GtkWidget |
static GtkWidget |
129 |
*map_add_button(const gchar *icon, GCallback cb, gpointer data, |
*map_add_button(int icon, GCallback cb, gpointer data, |
130 |
char *tooltip) { |
char *tooltip) { |
131 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
132 |
gtk_button_set_image(GTK_BUTTON(button), |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon)); |
|
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_BUTTON)); |
|
133 |
g_signal_connect(button, "clicked", cb, data); |
g_signal_connect(button, "clicked", cb, data); |
134 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
135 |
gtk_widget_set_tooltip_text(button, tooltip); |
gtk_widget_set_tooltip_text(button, tooltip); |
137 |
return button; |
return button; |
138 |
} |
} |
139 |
|
|
140 |
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
141 |
|
return 1000.0*km/osm_gps_map_get_scale(OSM_GPS_MAP(context->widget)); |
142 |
|
} |
143 |
|
|
144 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
145 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
146 |
|
|
147 |
|
/* get reference position ... */ |
148 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
149 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
150 |
|
|
151 |
/* get reference position and go there */ |
/* ... and enable "goto" button if it's valid */ |
152 |
gtk_widget_set_sensitive(context->gps, ok); |
gtk_widget_set_sensitive(context->gps, ok); |
153 |
|
|
154 |
|
if(ok) { |
155 |
|
float heading = NAN; |
156 |
|
int radius = 0; |
157 |
|
|
158 |
|
if(context->appdata->use_gps) { |
159 |
|
heading = gps_get_heading(context->appdata); |
160 |
|
|
161 |
|
/* get error */ |
162 |
|
float eph = gps_get_eph(context->appdata); |
163 |
|
if(!isnan(eph)) |
164 |
|
radius = dist2pixel(context, eph/1000, refpos->lat); |
165 |
|
} |
166 |
|
|
167 |
|
g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); |
168 |
|
osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), |
169 |
|
refpos->lat, refpos->lon, heading); |
170 |
|
} else |
171 |
|
osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget)); |
172 |
|
|
173 |
return TRUE; |
return TRUE; |
174 |
} |
} |
175 |
|
|
177 |
GdkEventConfigure *event, |
GdkEventConfigure *event, |
178 |
map_context_t *context) { |
map_context_t *context) { |
179 |
|
|
180 |
cb_map_gps(NULL, context); |
/* set default values if they are invalid */ |
181 |
|
if(!context->appdata->map.zoom || |
182 |
|
isnan(context->appdata->map.pos.lat) || |
183 |
|
isnan(context->appdata->map.pos.lon)) { |
184 |
|
printf("no valid map position found\n"); |
185 |
|
|
186 |
|
pos_t *refpos = get_pos(context->appdata); |
187 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
188 |
|
/* use gps position if present */ |
189 |
|
context->appdata->map.pos = *refpos; |
190 |
|
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
191 |
|
} else { |
192 |
|
/* use world map otherwise */ |
193 |
|
context->appdata->map.pos.lat = 0.0; |
194 |
|
context->appdata->map.pos.lon = 0.0; |
195 |
|
context->appdata->map.zoom = 1; |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
|
/* jump to initial position */ |
200 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
201 |
|
context->appdata->map.pos.lat, |
202 |
|
context->appdata->map.pos.lon, |
203 |
|
context->appdata->map.zoom); |
204 |
|
|
205 |
return FALSE; |
return FALSE; |
206 |
} |
} |
207 |
|
|
221 |
appdata_t *appdata; |
appdata_t *appdata; |
222 |
GtkWidget *window; |
GtkWidget *window; |
223 |
GMainLoop *loop; |
GMainLoop *loop; |
224 |
|
cache_t *cache; |
225 |
} popup_context_t; |
} popup_context_t; |
226 |
|
|
227 |
|
/* draw shape */ |
228 |
|
#define ARROW_BORDER 20 |
229 |
|
#define CORNER_RADIUS 10 |
230 |
|
|
231 |
#ifndef USE_HILDON |
#ifndef USE_MAEMO |
232 |
#define POPUP_WIDTH 300 |
#define POPUP_WIDTH 300 |
233 |
#define POPUP_HEIGHT 100 |
#define POPUP_HEIGHT 100 |
234 |
#else |
#else |
235 |
#define POPUP_WIDTH 600 |
#define POPUP_WIDTH 360 |
236 |
#define POPUP_HEIGHT 200 |
#define POPUP_HEIGHT 120 |
237 |
#endif |
#endif |
238 |
|
|
239 |
static gboolean |
static gboolean |
300 |
shutdown_loop(context); |
shutdown_loop(context); |
301 |
} |
} |
302 |
|
|
|
/* draw shape */ |
|
|
#define ARROW_BORDER 20 |
|
|
#define CORNER_RADIUS 10 |
|
|
|
|
303 |
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
304 |
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
305 |
|
|
323 |
gdk_gc_set_foreground(gc, &white); |
gdk_gc_set_foreground(gc, &white); |
324 |
gdk_gc_set_background(gc, &black); |
gdk_gc_set_background(gc, &black); |
325 |
|
|
326 |
|
/* the tip is always above or below the "bubble" but never at its side */ |
327 |
|
guint tip_offset = (tip_y == 0)?ARROW_BORDER:0; |
328 |
|
|
329 |
gdk_draw_rectangle(mask, gc, TRUE, |
gdk_draw_rectangle(mask, gc, TRUE, |
330 |
0, ARROW_BORDER + CORNER_RADIUS, |
0, tip_offset + CORNER_RADIUS, |
331 |
POPUP_WIDTH, |
POPUP_WIDTH, |
332 |
POPUP_HEIGHT - 2*CORNER_RADIUS - 2*ARROW_BORDER); |
POPUP_HEIGHT - 2*CORNER_RADIUS - ARROW_BORDER); |
333 |
|
|
334 |
gdk_draw_rectangle(mask, gc, TRUE, |
gdk_draw_rectangle(mask, gc, TRUE, |
335 |
CORNER_RADIUS, ARROW_BORDER, |
CORNER_RADIUS, tip_offset, |
336 |
POPUP_WIDTH - 2*CORNER_RADIUS, |
POPUP_WIDTH - 2*CORNER_RADIUS, |
337 |
POPUP_HEIGHT - 2*ARROW_BORDER); |
POPUP_HEIGHT - ARROW_BORDER); |
338 |
|
|
339 |
int off[][2] = { |
int off[][2] = { |
340 |
{ CORNER_RADIUS, ARROW_BORDER + CORNER_RADIUS }, |
{ CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
341 |
{ POPUP_WIDTH - CORNER_RADIUS, |
{ POPUP_WIDTH - CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
|
ARROW_BORDER + CORNER_RADIUS }, |
|
342 |
{ POPUP_WIDTH - CORNER_RADIUS, |
{ POPUP_WIDTH - CORNER_RADIUS, |
343 |
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER }, |
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}, |
344 |
{ CORNER_RADIUS, |
{ CORNER_RADIUS, |
345 |
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER}}; |
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}}; |
346 |
|
|
347 |
int i; |
int i; |
348 |
for(i=0;i<4;i++) { |
for(i=0;i<4;i++) { |
361 |
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
362 |
} |
} |
363 |
|
|
364 |
|
/* create a left aligned label (normal ones are centered) */ |
365 |
|
static GtkWidget *gtk_label_left_new(char *str) { |
366 |
|
GtkWidget *label = gtk_label_new(str); |
367 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
368 |
|
return label; |
369 |
|
} |
370 |
|
|
371 |
|
/* the small labels are actually only on maemo small */ |
372 |
|
#ifdef USE_MAEMO |
373 |
|
#define MARKUP_SMALL "<span size='small'>%s</span>" |
374 |
|
GtkWidget *gtk_label_small_left_new(char *str) { |
375 |
|
GtkWidget *label = gtk_label_new(""); |
376 |
|
char *markup = g_markup_printf_escaped(MARKUP_SMALL, str); |
377 |
|
gtk_label_set_markup(GTK_LABEL(label), markup); |
378 |
|
g_free(markup); |
379 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
380 |
|
return label; |
381 |
|
} |
382 |
|
#define gtk_label_big_left_new(a) gtk_label_left_new(a) |
383 |
|
#else |
384 |
|
#define gtk_label_small_left_new(a) gtk_label_left_new(a) |
385 |
|
#define MARKUP_BIG "<span size='x-large'>%s</span>" |
386 |
|
GtkWidget *gtk_label_big_left_new(char *str) { |
387 |
|
GtkWidget *label = gtk_label_new(""); |
388 |
|
char *markup = g_markup_printf_escaped(MARKUP_BIG, str); |
389 |
|
gtk_label_set_markup(GTK_LABEL(label), markup); |
390 |
|
g_free(markup); |
391 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
392 |
|
return label; |
393 |
|
} |
394 |
|
#endif |
395 |
|
|
396 |
|
static gboolean |
397 |
|
on_cache_button_clicked(GtkButton *button, popup_context_t *context) { |
398 |
|
printf("clicked %s\n", context->cache->name); |
399 |
|
return FALSE; |
400 |
|
} |
401 |
|
|
402 |
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
403 |
popup_context_t pcontext; |
popup_context_t pcontext; |
404 |
pcontext.appdata = mcontext->appdata; |
pcontext.appdata = mcontext->appdata; |
405 |
|
pcontext.cache = cache; |
406 |
|
|
407 |
pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
408 |
gtk_widget_realize(pcontext.window); |
gtk_widget_realize(pcontext.window); |
440 |
cache->pos.lat, cache->pos.lon, |
cache->pos.lat, cache->pos.lon, |
441 |
&sx, &sy); |
&sx, &sy); |
442 |
|
|
|
printf("screen pos %d/%d\n", sx, sy); |
|
|
|
|
443 |
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
|
printf("window = %d/%d +%d+%d %d*%d\n", x, y, |
|
|
mcontext->widget->allocation.x, |
|
|
mcontext->widget->allocation.y, |
|
|
mcontext->widget->allocation.width, |
|
|
mcontext->widget->allocation.height |
|
|
); |
|
444 |
|
|
445 |
gint ax = 0, ay = 0; |
gint ax = 0, ay = 0; |
446 |
if(sx > mcontext->widget->allocation.width/2) |
if(sx > mcontext->widget->allocation.width/2) |
449 |
if(sy > mcontext->widget->allocation.height/2) |
if(sy > mcontext->widget->allocation.height/2) |
450 |
ay = POPUP_HEIGHT; |
ay = POPUP_HEIGHT; |
451 |
|
|
452 |
#if !defined(USE_HILDON) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
453 |
GdkColor color; |
GdkColor color; |
454 |
gdk_color_parse("darkgray", &color); |
gdk_color_parse("darkgray", &color); |
455 |
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
460 |
y + mcontext->widget->allocation.y + sy - ay); |
y + mcontext->widget->allocation.y + sy - ay); |
461 |
|
|
462 |
|
|
463 |
GtkWidget *frame = gtk_frame_new(NULL); |
GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); |
464 |
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); |
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
465 |
gtk_container_set_border_width(GTK_CONTAINER(frame), |
CORNER_RADIUS/2 + (ay?0:ARROW_BORDER), |
466 |
ARROW_BORDER+CORNER_RADIUS); |
CORNER_RADIUS/2 + (ay?ARROW_BORDER:0), |
467 |
gtk_container_add(GTK_CONTAINER(frame), |
CORNER_RADIUS, CORNER_RADIUS); |
468 |
gtk_button_new_with_label(cache->name)); |
|
469 |
|
/* --- actual content ---- */ |
470 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
471 |
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
472 |
|
|
473 |
|
gtk_box_pack_start(GTK_BOX(hbox), |
474 |
|
icon_get_widget(ICON_CACHE_TYPE, cache->type), |
475 |
|
FALSE, FALSE, 5); |
476 |
|
|
477 |
|
if(cache->id) |
478 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), |
479 |
|
gtk_label_big_left_new(cache->id)); |
480 |
|
|
481 |
|
GtkWidget *button = gtk_button_new(); |
482 |
|
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, 12)); |
483 |
|
g_signal_connect(button, "clicked", |
484 |
|
G_CALLBACK(on_cache_button_clicked), &pcontext); |
485 |
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
486 |
|
|
487 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
488 |
|
|
489 |
|
if(cache->name) { |
490 |
|
GtkWidget *label = gtk_label_small_left_new(cache->name); |
491 |
|
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); |
492 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
493 |
|
} |
494 |
|
|
495 |
|
hbox = gtk_hbox_new(FALSE, 0); |
496 |
|
if(cache->terrain) { |
497 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
498 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
499 |
|
gtk_label_small_left_new(_("Terrain:")), FALSE, FALSE, 0); |
500 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
501 |
|
icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)), |
502 |
|
FALSE, FALSE, 5); |
503 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
504 |
|
} |
505 |
|
|
506 |
|
if(cache->difficulty) { |
507 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
508 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
509 |
|
gtk_label_small_left_new(_("Difficulty:")), FALSE, FALSE, 0); |
510 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
511 |
|
icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)), |
512 |
|
FALSE, FALSE, 5); |
513 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
514 |
|
} |
515 |
|
|
516 |
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
517 |
|
|
518 |
|
gtk_container_add(GTK_CONTAINER(alignment), vbox); |
519 |
|
/* ----------------------- */ |
520 |
|
|
521 |
gtk_container_add(GTK_CONTAINER(pcontext.window), frame); |
|
522 |
|
gtk_container_add(GTK_CONTAINER(pcontext.window), alignment); |
523 |
|
|
524 |
/* --------- give the window its shape ----------- */ |
/* give window its shape */ |
525 |
popup_window_shape(pcontext.window, ax, ay); |
popup_window_shape(pcontext.window, ax, ay); |
526 |
|
|
527 |
gtk_widget_show_all(pcontext.window); |
gtk_widget_show_all(pcontext.window); |
587 |
return pos; |
return pos; |
588 |
} |
} |
589 |
|
|
590 |
static int dist2pixel(map_context_t *context, float km, float lat) { |
#define CLICK_FUZZ (24) |
|
int zoom; |
|
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
|
|
|
|
|
/* world at zoom 1 == 512 pixels */ |
|
|
float m_per_pix = |
|
|
cos(DEG2RAD(lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
|
|
|
|
|
return 1000.0*km/m_per_pix; |
|
|
} |
|
|
|
|
|
#define CLICK_FUZZ (16) |
|
591 |
|
|
592 |
static gboolean |
static gboolean |
593 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
616 |
static gboolean |
static gboolean |
617 |
on_map_button_release_event(GtkWidget *widget, |
on_map_button_release_event(GtkWidget *widget, |
618 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
619 |
if(context->press_on) { |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
|
620 |
|
|
621 |
|
if(context->press_on) { |
622 |
pos_t pos = |
pos_t pos = |
623 |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
624 |
|
|
629 |
cache_popup(context, nearest); |
cache_popup(context, nearest); |
630 |
} |
} |
631 |
context->press_on = NULL; |
context->press_on = NULL; |
632 |
|
} else { |
633 |
|
/* save new map position */ |
634 |
|
gfloat lat, lon; |
635 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
636 |
|
context->appdata->map.pos.lat = lat; |
637 |
|
context->appdata->map.pos.lon = lon; |
638 |
} |
} |
639 |
|
|
640 |
return FALSE; |
return FALSE; |
641 |
} |
} |
642 |
|
|
643 |
|
static void save_map_state(map_context_t *context) { |
644 |
|
/* save map parameters */ |
645 |
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
646 |
|
gint zoom; |
647 |
|
g_object_get(map, "zoom", &zoom, NULL); |
648 |
|
context->appdata->map.zoom = zoom; |
649 |
|
|
650 |
|
gfloat lat, lon; |
651 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
652 |
|
context->appdata->map.pos.lat = lat; |
653 |
|
context->appdata->map.pos.lon = lon; |
654 |
|
} |
655 |
|
|
656 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
657 |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
658 |
printf("destroy map view\n"); |
printf("destroy map view\n"); |
659 |
|
|
660 |
|
save_map_state(context); |
661 |
|
|
662 |
/* restore cur_view */ |
/* restore cur_view */ |
663 |
context->appdata->cur_view = context->old_view; |
context->appdata->cur_view = context->old_view; |
664 |
|
|
677 |
const char *proxy = get_proxy_uri(appdata); |
const char *proxy = get_proxy_uri(appdata); |
678 |
|
|
679 |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
680 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"map-source", MAP_SOURCE, |
681 |
"tile-cache", path, |
"tile-cache", path, |
682 |
proxy?"proxy-uri":NULL, proxy, |
"auto-center", FALSE, |
683 |
|
"record-trip-history", FALSE, |
684 |
|
"show-trip-history", FALSE, |
685 |
|
proxy?"proxy-uri":NULL, proxy, |
686 |
NULL); |
NULL); |
687 |
|
|
688 |
g_free(path); |
g_free(path); |
741 |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
742 |
|
|
743 |
context->zoomin = |
context->zoomin = |
744 |
map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
map_add_button(10, G_CALLBACK(cb_map_zoomin), |
745 |
context, _("Zoom in")); |
context, _("Zoom in")); |
746 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
747 |
|
|
748 |
context->zoomout = |
context->zoomout = |
749 |
map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
map_add_button(11, G_CALLBACK(cb_map_zoomout), |
750 |
context, _("Zoom out")); |
context, _("Zoom out")); |
751 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
752 |
|
|
753 |
context->gps = |
context->gps = |
754 |
map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps), |
map_add_button(9, G_CALLBACK(cb_map_gps), |
755 |
context, _("Jump to GPS position")); |
context, _("Jump to GPS position")); |
756 |
gtk_widget_set_sensitive(context->gps, FALSE); |
gtk_widget_set_sensitive(context->gps, FALSE); |
757 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
776 |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
777 |
gtk_widget_show_all(dialog); |
gtk_widget_show_all(dialog); |
778 |
gtk_dialog_run(GTK_DIALOG(dialog)); |
gtk_dialog_run(GTK_DIALOG(dialog)); |
779 |
|
save_map_state(context); |
780 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
781 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
782 |
g_free(context); |
g_free(context); |