]> err.no Git - mapper/commitdiff
Show distance to destination. Misc other fixes.
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 9 Aug 2007 16:24:16 +0000 (19:24 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 9 Aug 2007 16:24:16 +0000 (19:24 +0300)
src/map.c

index ebef065fce8c3e502681a9d821224cb026fc3440..46e097d8b4cb96bb008067a926ab084769759ca0 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -60,7 +60,7 @@ static gint _map_mode=0;
 guint _num_downloads=0;
 guint _curr_download=0;
 
-static osm_location map_loc = {NULL, NULL, NULL, FALSE, 0, 0};
+static osm_location map_loc = {NULL, NULL, NULL, FALSE, FALSE, 0, 0};
 static GHashTable *map_tile_hash = NULL;
 
 typedef struct _map_tile_rdata map_tile_rdata;
@@ -74,7 +74,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);
+static void map_update_location(gint x, gint y, gboolean force);
 
 gboolean get_next_pui(gpointer key, gpointer value, ProgressUpdateInfo ** data)
 {
@@ -115,12 +115,9 @@ gboolean curl_download_timeout()
                                fclose(pui->file);
                                if (msg->data.result != CURLE_OK)
                                        g_unlink(pui->dest_str);        /* Delete so we try again. */
-                               curl_multi_remove_handle(_curl_multi,
-                                                        msg->easy_handle);
+                               curl_multi_remove_handle(_curl_multi, msg->easy_handle);
                                g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                               (GSourceFunc)
-                                               map_download_idle_refresh, pui,
-                                               NULL);
+                                               (GSourceFunc)map_download_idle_refresh, pui, NULL);
                        }
                }
        }
@@ -144,9 +141,7 @@ gboolean curl_download_timeout()
 
                        if (!pui->src_str) {
                                /* Failed to generate URL. */
-                               g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                               (GSourceFunc)map_download_idle_refresh, pui,
-                                               NULL);
+                               g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_download_idle_refresh, pui, NULL);
                                continue;
                        }
 
@@ -155,9 +150,7 @@ gboolean curl_download_timeout()
                                /* We're not updating - check if file already exists. */
                                if (g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
                                        g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                                       (GSourceFunc)
-                                                       map_download_idle_refresh,
-                                                       pui, NULL);
+                                                       (GSourceFunc)map_download_idle_refresh, pui, NULL);
                                        continue;
                                }
                        }
@@ -200,8 +193,7 @@ gboolean curl_download_timeout()
                                         pui->dest_str);
                                MACRO_BANNER_SHOW_INFO(_window, buffer);
                                g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                               (GSourceFunc)
-                                               map_download_idle_refresh, pui,
+                                               (GSourceFunc)map_download_idle_refresh, pui,
                                                NULL);
                                continue;
                        }
@@ -216,7 +208,7 @@ gboolean curl_download_timeout()
                                 pui->tiley);
                        g_unlink(buffer);
                        g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                       (GSourceFunc) map_download_idle_refresh,
+                                       (GSourceFunc)map_download_idle_refresh,
                                        pui, NULL);
                } else
                        break;
@@ -873,7 +865,7 @@ void map_center_unit(guint new_center_unitx, guint new_center_unity)
                                                          TILE_SIZE_PIXELS,
                                                          TILE_SIZE_PIXELS);
                                } else {
-#if 1                  
+#if 0
                                        map_tile_rdata *mtr;
 
                                        mtr=g_slice_new(map_tile_rdata);
@@ -951,14 +943,16 @@ void map_move_mark()
 gboolean
 map_update_location_from_gps()
 {
-map_update_location(_pos.unitx, _pos.unity);
+map_update_location(_pos.unitx, _pos.unity, FALSE);
 return FALSE;
 }
 
 gboolean
 map_update_location_from_center()
 {
-map_update_location(_center.unitx, _center.unity);
+/* Force re-validation of place if user is clicking around */
+map_loc.valid=FALSE;
+map_update_location(_center.unitx, _center.unity, TRUE);
 return FALSE;
 }
 
@@ -1398,9 +1392,8 @@ if (!s && !mp && !sp) {
 gtk_label_set_label(GTK_LABEL(info_banner.location), buffer);
 }
 
-/* XXX: Move this to osm-db.c */
 static void 
-map_update_location(gint x, gint y)
+map_update_location(gint x, gint y, gboolean force)
 {
 gint ilat, ilon;
 gdouble lat,lon;
@@ -1415,16 +1408,29 @@ unit2latlon(x, y, lat, lon);
 ilat=lat2mp_int(lat);
 ilon=lon2mp_int(lon);
 
-if (_gps.fix>1)
+if (_gps.fix>1 && !force)
        osm_set_way_range_from_speed(_gps.speed);
 else
-       osm_set_way_range(OSM_RANGE_WAY);
+       osm_set_way_range(OSM_RANGE_WAY/4);
 
 osm_progress_set_widget(_db, _progress_item);
 _map_location_known=osm_get_location_data(ilat, ilon, &map_loc);
 _map_location_dist=map_loc.street ? map_loc.street->dist : 900000.0;
-map_set_place_information(map_loc.street, map_loc.primary, map_loc.secondary);
+if (map_loc.valid)
+       map_set_place_information(map_loc.street, map_loc.primary, map_loc.secondary);
+else
+       map_set_place_information(NULL, NULL, NULL);
 osm_progress_set_widget(_db, NULL);
+
+if (_dest.valid) {
+       gchar buffer[32];
+       gdouble dt=calculate_distance(lat, lon, _dest.lat, _dest.lon);
+       snprintf(buffer, sizeof(buffer), "%.02f %s", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
+       gtk_label_set_label(GTK_LABEL(info_banner.distance), buffer);
+} else {
+       gtk_label_set_label(GTK_LABEL(info_banner.distance), "");
+}
+
 inp=FALSE;
 }
 
@@ -1490,9 +1496,7 @@ gboolean map_cb_button_release(GtkWidget * widget, GdkEventButton * event)
        switch (event->button) {
        case 1:
                if (_center_mode > 0)
-                       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
-                                                      (_menu_ac_none_item),
-                                                      TRUE);
+                       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE);
 
                switch (_map_mode) {
                case MAP_MODE_DRAW_TRACK:
@@ -1511,9 +1515,9 @@ gboolean map_cb_button_release(GtkWidget * widget, GdkEventButton * event)
                ux = x2unit((gint) (event->x + 0.5));
                uy = y2unit((gint) (event->y + 0.5));
                map_update_location(ux, uy);
-#endif
-
+#else
                g_idle_add((GSourceFunc)map_update_location_from_center, NULL);
+#endif
 
                map_center_unit(x2unit((gint) (event->x + 0.5)),
                                y2unit((gint) (event->y + 0.5)));