--- trunk/src/map-tool.c 2009/08/25 13:21:45 81
+++ trunk/src/map-tool.c 2009/09/23 11:23:45 123
@@ -17,6 +17,11 @@
* along with GPXView. If not, see .
*/
+/*
+ * http://topo.geofabrik.de/relief/${z}/${x}/${y}.png 8-15
+ * http://topo.geofabrik.de/trail/${z}/${x}/${y}.png 8-15
+ */
+
#include "gpxview.h"
#include "converter.h"
#include // for isnan
@@ -31,7 +36,8 @@
#include
#endif
-#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP
+/* default values */
+#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENCYCLEMAP
#define GPS_DEFAULT_ZOOM 13
#define PROXY_KEY "/system/http_proxy/"
@@ -137,41 +143,65 @@
GdkEventConfigure *event,
map_context_t *context) {
- /* set default values if they are invalid */
- if(!context->appdata->map.zoom ||
- isnan(context->appdata->map.pos.lat) ||
- isnan(context->appdata->map.pos.lon)) {
- printf("no valid map position found\n");
-
- pos_t *refpos = get_pos(context->appdata);
- if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
- /* use gps position if present */
- context->appdata->map.pos = *refpos;
- context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
- } else {
- /* use world map otherwise */
- context->appdata->map.pos.lat = 0.0;
- context->appdata->map.pos.lon = 0.0;
- context->appdata->map.zoom = 1;
+ if(!context->map_complete) {
+
+ /* set default values if they are invalid */
+ if(!context->appdata->map.zoom ||
+ isnan(context->appdata->map.pos.lat) ||
+ isnan(context->appdata->map.pos.lon)) {
+ printf("no valid map position found\n");
+
+ pos_t *refpos = get_pos(context->appdata);
+ if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
+ /* use gps position if present */
+ context->appdata->map.pos = *refpos;
+ context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
+ } else {
+ /* use world map otherwise */
+ context->appdata->map.pos.lat = 0.0;
+ context->appdata->map.pos.lon = 0.0;
+ context->appdata->map.zoom = 1;
+ }
}
+
+ /* 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);
+ context->map_complete = TRUE;
}
- /* 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);
-
return FALSE;
}
-static void map_draw_cachelist(GtkWidget *map, cache_t *cache) {
- while(cache) {
- GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
+static void map_draw_cache(GtkWidget *map, cache_t *cache) {
+ GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
+ /* check if there's also an overwritten coordinate */
+ if(cache->notes && cache->notes->override) {
+ GdkPixbuf *over = icon_get(ICON_MISC, 1);
+
+ osm_gps_map_add_image(OSM_GPS_MAP(map),
+ cache->notes->pos.lat, cache->notes->pos.lon, icon);
+
+ osm_gps_map_add_image(OSM_GPS_MAP(map),
+ cache->notes->pos.lat, cache->notes->pos.lon, over);
+ } else
osm_gps_map_add_image(OSM_GPS_MAP(map),
cache->pos.lat, cache->pos.lon, icon);
+}
+
+static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) {
+ if(!gpx->notes_loaded) {
+ notes_load_all(appdata, gpx);
+ gpx->notes_loaded = TRUE;
+ }
+
+ cache_t *cache = gpx->cache;
+ while(cache) {
+ map_draw_cache(map, cache);
cache = cache->next;
}
}
@@ -180,9 +210,11 @@
map_cachelist_nearest(cache_t *cache, pos_t *pos,
cache_t **result, float *distance) {
while(cache) {
+ pos_t cpos = gpx_cache_pos(cache);
+
float dist =
- pow(cache->pos.lat - pos->lat, 2) +
- pow(cache->pos.lon - pos->lon, 2);
+ pow(cpos.lat - pos->lat, 2) +
+ pow(cpos.lon - pos->lon, 2);
if(!(dist > *distance)) {
*result = cache;
@@ -198,7 +230,7 @@
float distance = NAN;
#ifdef USE_MAEMO
- if(!context->appdata->cur_gpx) {
+ if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
#endif
/* search all geocaches */
gpx_t *gpx = context->appdata->gpx;
@@ -207,10 +239,11 @@
gpx = gpx->next;
}
#ifdef USE_MAEMO
- } else {
+ } else if(context->appdata->cur_gpx) {
map_cachelist_nearest(context->appdata->cur_gpx->cache,
pos, &result, &distance);
- }
+ } else
+ result = context->appdata->cur_gpx->cache;
#endif
return result;
@@ -231,10 +264,14 @@
GdkEventButton *event, map_context_t *context) {
OsmGpsMap *map = OSM_GPS_MAP(context->widget);
+ /* check if we actually clicked parts of the OSD */
+ if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE)
+ return FALSE;
+
/* got a press event without release event? eat it! */
if(context->press_on != NULL) {
printf("PRESS: already\n");
- return TRUE;
+ return FALSE;
}
pos_t pos =
@@ -242,8 +279,10 @@
cache_t *nearest = map_closest(context, &pos);
if(nearest) {
- float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
- if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ)
+ pos_t cpos = gpx_cache_pos(nearest);
+
+ float dist = gpx_pos_get_distance(pos, cpos, FALSE);
+ if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ)
context->press_on = nearest;
}
@@ -299,6 +338,11 @@
GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
cairo_draw_pixbuf(cr, icon, x, y);
+ if(cache->notes && cache->notes->override) {
+ GdkPixbuf *over = icon_get(ICON_MISC, 1);
+ cairo_draw_pixbuf(cr, over, x, y);
+ }
+
/* ... and right of it the waypoint id */
cairo_text_extents_t extents;
@@ -407,11 +451,16 @@
cache_t *nearest = map_closest(context, &pos);
if(nearest && nearest == context->press_on) {
- float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
- if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {
+ pos_t cpos = gpx_cache_pos(nearest);
+
+ float dist = gpx_pos_get_distance(pos, cpos, FALSE);
+ if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ) {
- osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon,
- balloon_draw_cb, nearest);
+ osm_gps_map_osd_draw_balloon(map, cpos.lat, cpos.lon,
+ balloon_draw_cb, nearest);
+
+ osm_gps_map_osd_draw_nav (map, cpos.lat, cpos.lon, nearest->name);
+
}
}
context->press_on = NULL;
@@ -442,6 +491,10 @@
context->appdata->map.pos.lat = lat;
context->appdata->map.pos.lon = lon;
+ gint source;
+ g_object_get(map, "map-source", &source, NULL);
+ context->appdata->map.source = source;
+
#if MAEMO_VERSION_MAJOR == 5
/* restore cur_view */
context->appdata->cur_view = context->old_view;
@@ -483,6 +536,7 @@
context = appdata->map.context = g_new0(map_context_t, 1);
context->appdata = appdata;
+ context->map_complete = FALSE;
/* cleanup old (pre 0.8.7) path if it exists */
char *old_path = g_strdup_printf("%s/map/", appdata->image_path);
@@ -510,8 +564,11 @@
const char *proxy = get_proxy_uri(appdata);
+ gint source = context->appdata->map.source;
+ if(!source) source = MAP_SOURCE;
+
context->widget = g_object_new(OSM_TYPE_GPS_MAP,
- "map-source", MAP_SOURCE,
+ "map-source", source,
"tile-cache", path,
"auto-center", FALSE,
"record-trip-history", FALSE,
@@ -525,19 +582,22 @@
char *name = NULL;
#ifdef USE_MAEMO
- if(!appdata->cur_gpx) {
+ if(!appdata->cur_gpx && !appdata->cur_cache) {
#endif
/* draw all geocaches */
gpx_t *gpx = appdata->gpx;
while(gpx) {
- map_draw_cachelist(context->widget, gpx->cache);
+ map_draw_gpx(appdata, context->widget, gpx);
gpx = gpx->next;
}
- name = g_strdup(_("all geocaches"));
+ name = g_strdup(_("all"));
#ifdef USE_MAEMO
- } else {
- map_draw_cachelist(context->widget, appdata->cur_gpx->cache);
+ } else if(!appdata->cur_cache) {
+ map_draw_gpx(appdata, context->widget, appdata->cur_gpx);
name = g_strdup(appdata->cur_gpx->name);
+ } else {
+ map_draw_cache(context->widget, appdata->cur_cache);
+ name = g_strdup(appdata->cur_cache->name);
}
#endif