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 |
#define GPS_DEFAULT_ZOOM 13 |
29 |
|
|
30 |
/* equatorial radius in meters */ |
/* equatorial radius in meters */ |
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 */ |
/* save new zoom */ |
98 |
context->appdata->map.zoom = zoom; |
context->appdata->map.zoom = zoom; |
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 |
|
|
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 */ |
/* draw shape */ |
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 350 |
#define POPUP_WIDTH 360 |
236 |
#define POPUP_HEIGHT 120 |
#define POPUP_HEIGHT 120 |
237 |
#endif |
#endif |
238 |
|
|
393 |
} |
} |
394 |
#endif |
#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); |
468 |
|
|
469 |
/* --- actual content ---- */ |
/* --- actual content ---- */ |
470 |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
471 |
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
472 |
|
|
473 |
if(cache->id) { |
gtk_box_pack_start(GTK_BOX(hbox), |
474 |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
icon_get_widget(ICON_CACHE_TYPE, cache->type), |
475 |
|
FALSE, FALSE, 5); |
476 |
gtk_box_pack_start(GTK_BOX(ihbox), |
|
477 |
icon_get_widget(ICON_CACHE_TYPE, cache->type), |
if(cache->id) |
478 |
FALSE, FALSE, 5); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), |
479 |
|
gtk_label_big_left_new(cache->id)); |
480 |
|
|
481 |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), |
GtkWidget *button = gtk_button_new(); |
482 |
gtk_label_big_left_new(cache->id)); |
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), ihbox); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
|
} |
|
488 |
|
|
489 |
if(cache->name) { |
if(cache->name) { |
490 |
GtkWidget *label = gtk_label_small_left_new(cache->name); |
GtkWidget *label = gtk_label_small_left_new(cache->name); |
492 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
493 |
} |
} |
494 |
|
|
495 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
hbox = gtk_hbox_new(FALSE, 0); |
496 |
if(cache->terrain) { |
if(cache->terrain) { |
497 |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
498 |
gtk_box_pack_start(GTK_BOX(ihbox), |
gtk_box_pack_start(GTK_BOX(ihbox), |
587 |
return pos; |
return pos; |
588 |
} |
} |
589 |
|
|
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
|
|
gint 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; |
|
|
} |
|
|
|
|
590 |
#define CLICK_FUZZ (24) |
#define CLICK_FUZZ (24) |
591 |
|
|
592 |
static gboolean |
static gboolean |
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 */ |