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 |
36 |
#include <X11/Xatom.h> |
#include <X11/Xatom.h> |
37 |
#endif |
#endif |
38 |
|
|
39 |
#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP |
/* default values */ |
40 |
|
#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENCYCLEMAP |
41 |
#define GPS_DEFAULT_ZOOM 13 |
#define GPS_DEFAULT_ZOOM 13 |
42 |
|
|
43 |
#define PROXY_KEY "/system/http_proxy/" |
#define PROXY_KEY "/system/http_proxy/" |
143 |
GdkEventConfigure *event, |
GdkEventConfigure *event, |
144 |
map_context_t *context) { |
map_context_t *context) { |
145 |
|
|
146 |
/* set default values if they are invalid */ |
if(!context->map_complete) { |
147 |
if(!context->appdata->map.zoom || |
|
148 |
isnan(context->appdata->map.pos.lat) || |
/* set default values if they are invalid */ |
149 |
isnan(context->appdata->map.pos.lon)) { |
if(!context->appdata->map.zoom || |
150 |
printf("no valid map position found\n"); |
isnan(context->appdata->map.pos.lat) || |
151 |
|
isnan(context->appdata->map.pos.lon)) { |
152 |
pos_t *refpos = get_pos(context->appdata); |
printf("no valid map position found\n"); |
153 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
|
154 |
/* use gps position if present */ |
pos_t *refpos = get_pos(context->appdata); |
155 |
context->appdata->map.pos = *refpos; |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
156 |
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
/* use gps position if present */ |
157 |
} else { |
context->appdata->map.pos = *refpos; |
158 |
/* use world map otherwise */ |
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
159 |
context->appdata->map.pos.lat = 0.0; |
} else { |
160 |
context->appdata->map.pos.lon = 0.0; |
/* use world map otherwise */ |
161 |
context->appdata->map.zoom = 1; |
context->appdata->map.pos.lat = 0.0; |
162 |
|
context->appdata->map.pos.lon = 0.0; |
163 |
|
context->appdata->map.zoom = 1; |
164 |
|
} |
165 |
} |
} |
166 |
|
|
167 |
|
/* jump to initial position */ |
168 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
169 |
|
context->appdata->map.pos.lat, |
170 |
|
context->appdata->map.pos.lon, |
171 |
|
context->appdata->map.zoom); |
172 |
|
context->map_complete = TRUE; |
173 |
} |
} |
174 |
|
|
|
/* 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); |
|
|
|
|
175 |
return FALSE; |
return FALSE; |
176 |
} |
} |
177 |
|
|
241 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
242 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
243 |
|
|
244 |
|
/* check if we actually clicked parts of the OSD */ |
245 |
|
if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) |
246 |
|
return FALSE; |
247 |
|
|
248 |
/* got a press event without release event? eat it! */ |
/* got a press event without release event? eat it! */ |
249 |
if(context->press_on != NULL) { |
if(context->press_on != NULL) { |
250 |
printf("PRESS: already\n"); |
printf("PRESS: already\n"); |
251 |
return TRUE; |
return FALSE; |
252 |
} |
} |
253 |
|
|
254 |
pos_t pos = |
pos_t pos = |
456 |
context->appdata->map.pos.lat = lat; |
context->appdata->map.pos.lat = lat; |
457 |
context->appdata->map.pos.lon = lon; |
context->appdata->map.pos.lon = lon; |
458 |
|
|
459 |
|
gint source; |
460 |
|
g_object_get(map, "map-source", &source, NULL); |
461 |
|
context->appdata->map.source = source; |
462 |
|
|
463 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
464 |
/* restore cur_view */ |
/* restore cur_view */ |
465 |
context->appdata->cur_view = context->old_view; |
context->appdata->cur_view = context->old_view; |
501 |
|
|
502 |
context = appdata->map.context = g_new0(map_context_t, 1); |
context = appdata->map.context = g_new0(map_context_t, 1); |
503 |
context->appdata = appdata; |
context->appdata = appdata; |
504 |
|
context->map_complete = FALSE; |
505 |
|
|
506 |
/* cleanup old (pre 0.8.7) path if it exists */ |
/* cleanup old (pre 0.8.7) path if it exists */ |
507 |
char *old_path = g_strdup_printf("%s/map/", appdata->image_path); |
char *old_path = g_strdup_printf("%s/map/", appdata->image_path); |
529 |
|
|
530 |
const char *proxy = get_proxy_uri(appdata); |
const char *proxy = get_proxy_uri(appdata); |
531 |
|
|
532 |
|
gint source = context->appdata->map.source; |
533 |
|
if(!source) source = MAP_SOURCE; |
534 |
|
|
535 |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
536 |
"map-source", MAP_SOURCE, |
"map-source", source, |
537 |
"tile-cache", path, |
"tile-cache", path, |
538 |
"auto-center", FALSE, |
"auto-center", FALSE, |
539 |
"record-trip-history", FALSE, |
"record-trip-history", FALSE, |