From 3e0184a8f179a2e308956b671ef9a1174bcb3d3c Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 23 Jul 2007 14:24:23 +0300 Subject: [PATCH] Cleanups. Use a smaller box for nearest poi. Update location info when gps position changes. --- src/map.c | 49 ++++++++++++++++++++++++++----------------------- src/poi.c | 4 ++-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/map.c b/src/map.c index 457ebe4..8badac1 100644 --- a/src/map.c +++ b/src/map.c @@ -64,6 +64,7 @@ void map_force_redraw(); gboolean curl_download_timeout(); gchar *map_construct_url(guint tilex, guint tiley, guint zoom); gboolean map_download_idle_refresh(ProgressUpdateInfo * pui); +static void map_update_location(gint x, gint y); gboolean get_next_pui(gpointer key, gpointer value, ProgressUpdateInfo ** data) { @@ -260,10 +261,7 @@ void map_draw_mark() _mark_x1 - _draw_width, _mark_y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0, 360 * 64); gdk_draw_line(_map_widget->window, - _conn_state == RCVR_FIXED - ? (_show_velvec - ? _gc[COLORABLE_MARK_VELOCITY] : _gc[COLORABLE_MARK]) - : _gc[COLORABLE_MARK_OLD], + _conn_state == RCVR_FIXED ? (_show_velvec ? _gc[COLORABLE_MARK_VELOCITY] : _gc[COLORABLE_MARK]) : _gc[COLORABLE_MARK_OLD], _mark_x1, _mark_y1, _mark_x2, _mark_y2); vprintf("%s(): return\n", __PRETTY_FUNCTION__); @@ -973,6 +971,8 @@ void refresh_mark() if (_speed_limit_on) speed_limit(); + map_update_location(_pos.unitx, _pos.unity); + vprintf("%s(): return\n", __PRETTY_FUNCTION__); } @@ -1339,23 +1339,25 @@ if (az==TRUE) { } -static void map_draw_route(gint x, gint y) +static void +map_draw_route(gint x, gint y) { - cmenu_route_add_way(x, y); +cmenu_route_add_way(x, y); } -static void map_draw_track(gint x, gint y) +static void +map_draw_track(gint x, gint y) { - _pos.unitx = x2unit((gint) (x + 0.5)); - _pos.unity = y2unit((gint) (y + 0.5)); - unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); - _gps.speed = 20.f; - integerize_data(); - track_add(time(NULL), FALSE); - refresh_mark(); +_pos.unitx = x2unit((gint) (x + 0.5)); +_pos.unity = y2unit((gint) (y + 0.5)); +unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); +_gps.speed = 20.f; +integerize_data(); +track_add(time(NULL), FALSE); +refresh_mark(); } -void +static void map_set_place_information(osm_way *s, osm_place *mp, osm_place *sp, PoiInfo *p) { gchar buffer[256]; @@ -1376,9 +1378,9 @@ gtk_label_set_label(GTK_LABEL(_info_banner), buffer); } /* XXX: */ -static void map_print_int_latlon(gint x, gint y) +static void +map_update_location(gint x, gint y) { -gint ux, uy; gint ilat, ilon; gdouble lat,lon; osm_way *street; @@ -1386,9 +1388,7 @@ osm_place mplace; osm_place splace; PoiInfo *p; -ux = x2unit((gint) (x + 0.5)); -uy = y2unit((gint) (y + 0.5)); -unit2latlon(ux, uy, lat, lon); +unit2latlon(x, y, lat, lon); ilat=lat2mp_int(lat); ilon=lon2mp_int(lon); @@ -1396,8 +1396,6 @@ ilon=lon2mp_int(lon); mplace.name=NULL; splace.name=NULL; -g_printf("IntPos: %d , %d\n", ilat, ilon); - street=osm_find_nearest_way(ilat, ilon); if (street) g_printf("WAY: %d %s %s\n", street->id, street->name, street->ref); @@ -1435,6 +1433,7 @@ if (splace.isin!=0) { } map_set_place_information(street, &mplace, &splace, p); +osm_way_free(street); } gboolean map_cb_scroll_event(GtkWidget * widget, GdkEventScroll * event) @@ -1493,6 +1492,7 @@ gboolean map_cb_button_press(GtkWidget * widget, GdkEventButton * event) gboolean map_cb_button_release(GtkWidget * widget, GdkEventButton * event) { +gint ux,uy; printf("%s()\n", __PRETTY_FUNCTION__); switch (event->button) { @@ -1515,7 +1515,10 @@ gboolean map_cb_button_release(GtkWidget * widget, GdkEventButton * event) break; } - map_print_int_latlon(event->x,event->y); + ux = x2unit((gint) (event->x + 0.5)); + uy = y2unit((gint) (event->y + 0.5)); + + map_update_location(ux, uy); map_center_unit(x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5))); diff --git a/src/poi.c b/src/poi.c index 209d456..1446993 100644 --- a/src/poi.c +++ b/src/poi.c @@ -192,8 +192,8 @@ poi_db_prepare(sqlite3 *db) "select p.lat, p.lon, p.label, c.label, c.icon, c.color" " from poi p, category c " " where c.enabled = 1 and p.cat_id = c.cat_id " - " and p.lat between $LAT-0.11 and $LAT+0.11 " - " and p.lon between $LON-0.11 and $LAT+0.11 " + " and p.lat between $LAT-0.10 and $LAT+0.10 " + " and p.lon between $LON-0.10 and $LAT+0.10 " " order by (($LAT - p.lat) * ($LAT - p.lat) " "+ ($LON - p.lon) * ($LON - p.lon)) limit 1", -1, &_stmt_select_nearest_poi, NULL); -- 2.39.5