mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:03:23 +00:00
Show single dives in map.
This adds a "Show in map" entry in the dive list context menu. It will zoom to the dive location if it exists, otherwise the full map will be displayed. I've also switched map tiles from OpenStreetMap to Google Maps just to show off that we can. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3fb80bcaeb
commit
e9953fa5e6
4 changed files with 71 additions and 14 deletions
1
dive.h
1
dive.h
|
@ -500,6 +500,7 @@ extern void show_dive_stats(struct dive *);
|
|||
extern void clear_stats_widgets(void);
|
||||
|
||||
extern void show_gps_locations(void);
|
||||
extern void show_gps_location(struct dive *);
|
||||
|
||||
extern void show_yearly_stats(void);
|
||||
|
||||
|
|
11
divelist.c
11
divelist.c
|
@ -1659,6 +1659,11 @@ void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
|
|||
}
|
||||
}
|
||||
|
||||
static void show_gps_location_cb(GtkWidget *menuitem, struct dive *dive)
|
||||
{
|
||||
show_gps_location(dive);
|
||||
}
|
||||
|
||||
static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
|
||||
{
|
||||
gtk_tree_view_expand_all(tree_view);
|
||||
|
@ -2470,6 +2475,10 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
|
|||
g_signal_connect(menuitem, "activate", G_CALLBACK(edit_dive_from_path_cb), path);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
}
|
||||
menuitem = gtk_menu_item_new_with_label(_("Show in map"));
|
||||
g_signal_connect(menuitem, "activate", G_CALLBACK(show_gps_location_cb), dive);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
|
||||
/* only offer trip editing options when we are displaying the tree model */
|
||||
if (dive_list.model == dive_list.treemodel) {
|
||||
int depth = gtk_tree_path_get_depth(path);
|
||||
|
@ -2503,9 +2512,11 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
|
|||
menuitem = gtk_menu_item_new_with_label(_("Expand all"));
|
||||
g_signal_connect(menuitem, "activate", G_CALLBACK(expand_all_cb), tree_view);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
|
||||
menuitem = gtk_menu_item_new_with_label(_("Collapse all"));
|
||||
g_signal_connect(menuitem, "activate", G_CALLBACK(collapse_all_cb), tree_view);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
|
||||
gtk_widget_show_all(menu);
|
||||
|
||||
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
|
||||
|
|
BIN
flag.png
Normal file
BIN
flag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
73
gps.c
73
gps.c
|
@ -2,6 +2,7 @@
|
|||
/* Creates the UI displaying the dives locations on a map.
|
||||
*/
|
||||
#include <glib/gi18n.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include "osm-gps-map.h"
|
||||
|
||||
|
@ -10,7 +11,10 @@
|
|||
#include "display-gtk.h"
|
||||
#include "divelist.h"
|
||||
|
||||
static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_OPENSTREETMAP;
|
||||
/* Several map providers are available, such as OSM_GPS_MAP_SOURCE_OPENSTREETMAP
|
||||
and OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE. We should make more of
|
||||
them available from e.g. a pull-down menu */
|
||||
static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_GOOGLE_STREET;
|
||||
|
||||
|
||||
static void on_close (GtkWidget *widget, gpointer user_data)
|
||||
|
@ -27,15 +31,11 @@ static void add_gps_point(OsmGpsMap *map, float latitude, float longitude)
|
|||
}
|
||||
|
||||
|
||||
void show_gps_locations()
|
||||
OsmGpsMap *init_map()
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
OsmGpsMap *map;
|
||||
OsmGpsMapLayer *osd;
|
||||
char *cachedir, *cachebasedir;
|
||||
int idx;
|
||||
struct dive *dp;
|
||||
|
||||
cachebasedir = osm_gps_map_get_default_cache_directory();
|
||||
cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
|
||||
|
@ -59,14 +59,12 @@ void show_gps_locations()
|
|||
|
||||
osm_gps_map_layer_add(OSM_GPS_MAP(map), osd);
|
||||
g_object_unref(G_OBJECT(osd));
|
||||
for (idx = 0; idx < dive_table.nr; idx++) {
|
||||
dp = dive_table.dives[idx];
|
||||
if (dp->latitude.udeg != 0 && dp->longitude.udeg != 0){
|
||||
add_gps_point(map, dp->latitude.udeg / 1000000.0,
|
||||
dp->longitude.udeg / 1000000.0);
|
||||
}
|
||||
}
|
||||
osm_gps_map_set_center_and_zoom(map, 0, 0, 0);
|
||||
return map;
|
||||
}
|
||||
|
||||
void show_map(OsmGpsMap *map)
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
/* Enable keyboard navigation */
|
||||
osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_F11);
|
||||
|
@ -89,3 +87,50 @@ void show_gps_locations()
|
|||
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
|
||||
void show_gps_location(struct dive *dp)
|
||||
{
|
||||
OsmGpsMap *map;
|
||||
GError *gerror = NULL;
|
||||
GdkPixbuf *picture;
|
||||
|
||||
double lat = dp->latitude.udeg / 1000000.0;
|
||||
double lng = dp->longitude.udeg / 1000000.0;
|
||||
|
||||
map = init_map();
|
||||
|
||||
if (lat != 0 || lng != 0) {
|
||||
add_gps_point(map, lat, lng);
|
||||
osm_gps_map_set_center_and_zoom(map, lat, lng, 8);
|
||||
picture = gdk_pixbuf_new_from_file("./flag.png", &gerror);
|
||||
if (picture) {
|
||||
osm_gps_map_image_add_with_alignment(map, lat, lng, picture, 0, 1);
|
||||
} else {
|
||||
printf("error message: %s\n", gerror->message);
|
||||
}
|
||||
|
||||
} else {
|
||||
osm_gps_map_set_center_and_zoom(map, 0, 0, 2);
|
||||
}
|
||||
show_map(map);
|
||||
}
|
||||
|
||||
void show_gps_locations()
|
||||
{
|
||||
OsmGpsMap *map;
|
||||
struct dive *dp;
|
||||
int idx;
|
||||
|
||||
map = init_map();
|
||||
|
||||
for (idx = 0; idx < dive_table.nr; idx++) {
|
||||
dp = dive_table.dives[idx];
|
||||
if (dp->latitude.udeg != 0 || dp->longitude.udeg != 0){
|
||||
add_gps_point(map, dp->latitude.udeg / 1000000.0,
|
||||
dp->longitude.udeg / 1000000.0);
|
||||
}
|
||||
}
|
||||
osm_gps_map_set_center_and_zoom(map, 0, 0, 2);
|
||||
|
||||
show_map(map);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue