- Make center_ratio a parameter to the macros.
- Combine some debug output to make it more clear.
- Misc other things.
menu_cb_settings(GtkAction * action)
{
settings_dialog();
-MACRO_RECALC_FOCUS_BASE();
-MACRO_RECALC_FOCUS_SIZE();
+MACRO_RECALC_FOCUS_BASE(_center_ratio);
+MACRO_RECALC_FOCUS_SIZE(_center_ratio);
map_force_redraw();
return TRUE;
}
gps_connect_now(_gps);
}
}
-MACRO_RECALC_FOCUS_BASE();
-MACRO_RECALC_FOCUS_SIZE();
+#if 0
+MACRO_RECALC_FOCUS_BASE(_center_ratio);
+MACRO_RECALC_FOCUS_SIZE(_center_ratio);
map_force_redraw();
+#endif
+
return TRUE;
}
/* Test if download succeeded (only if retries != 0). */
if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
gint zoom_diff = pui->zoom - _zoom;
+
/* Only refresh at same or "lower" (more detailed) zoom level. */
if (zoom_diff >= 0) {
+ guint tilex, tiley, tilex_end, tiley_end;
+
/* If zoom has changed since we first put in the request for
* this tile, then we may have to update more than one tile. */
- guint tilex, tiley, tilex_end, tiley_end;
for (tilex = pui->tilex << zoom_diff, tilex_end = tilex + (1 << zoom_diff); tilex < tilex_end; tilex++) {
for (tiley = pui->tiley << zoom_diff, tiley_end = tiley + (1 << zoom_diff); tiley < tiley_end; tiley++) {
g_debug("MDIR: %d %d", tilex, tiley);
tw=TILE_SIZE_PIXELS*((widget->allocation.width/TILE_SIZE_PIXELS)+2);
th=TILE_SIZE_PIXELS*((widget->allocation.height/TILE_SIZE_PIXELS)+2);
-g_debug("MAP: configure %d %d -> (%d,%d)", widget->allocation.width, widget->allocation.height, tw, th);
-
if (map_pixmap==NULL) {
- g_debug("Initial buffer pixmap");
map_pixmap=gdk_pixmap_new(widget->window, tw, th, -1);
} else {
if (tw>buf_width_pixels || th>buf_height_pixels) {
- g_debug("MC: Large buffer");
g_object_unref(map_pixmap);
map_pixmap=gdk_pixmap_new(widget->window, tw, th, -1);
- } else if (tw<buf_width_pixels-TILE_SIZE_PIXELS || th<buf_height_pixels-TILE_SIZE_PIXELS) {
- g_debug("MC: Small buffer");
+ } else if (tw<buf_width_pixels-(TILE_SIZE_PIXELS*2) || th<buf_height_pixels-(TILE_SIZE_PIXELS*2)) {
g_object_unref(map_pixmap);
map_pixmap=gdk_pixmap_new(widget->window, tw, th, -1);
- } else {
- g_debug("MC: No change ?");
}
}
+g_assert(map_pixmap);
buf_width_pixels=tw;
buf_height_pixels=th;
scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2;
scale_rect.width = SCALE_WIDTH;
-MACRO_RECALC_FOCUS_BASE();
-MACRO_RECALC_FOCUS_SIZE();
+MACRO_RECALC_FOCUS_BASE(_center_ratio);
+MACRO_RECALC_FOCUS_SIZE(_center_ratio);
_min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth));
_min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight));
if (_home.valid)
map_draw_position_icon(&_home);
+
if(_show_poi)
map_render_all_pois(buf_width_pixels, buf_height_pixels);
+
if(_show_tracks>0)
map_render_paths();
}
map_force_redraw(void)
{
guint new_x, new_y;
-#ifdef DEBUG_MAP_TIME
+#ifdef DEBUG
gulong tms;
g_timer_start(map_timer);
map_render_tile(_base_tilex + new_x, _base_tiley + new_y,
new_x * TILE_SIZE_PIXELS, new_y * TILE_SIZE_PIXELS, FALSE);
}
-#ifdef DEBUG_MAP_TIME
+#ifdef DEBUG
g_timer_stop(map_timer);
g_debug("Full redraw: %f sec\n", g_timer_elapsed(map_timer, &tms));
#endif
+
map_render_data();
MACRO_QUEUE_DRAW_AREA();
}
* current zoom level, or if the new zoom is invalid
* (not MIN_ZOOM <= new_zoom < MAX_ZOOM), then this method does nothing.
*/
-void
+gboolean
map_set_zoom(guint new_zoom)
{
/* Note that, since new_zoom is a guint and MIN_ZOOM is 0, this if
* condition also checks for new_zoom >= MIN_ZOOM. */
if (new_zoom > (MAX_ZOOM - 1))
- return;
+ return FALSE;
if (new_zoom == _zoom)
- return;
+ return FALSE;
_zoom = new_zoom / _curr_repo->view_zoom_steps * _curr_repo->view_zoom_steps;
_world_size_tiles = unit2tile(WORLD_SIZE_UNITS);
/* New zoom level, so we can't reuse the old buffer's pixels. */
/* Update state variables. */
MACRO_RECALC_OFFSET();
-MACRO_RECALC_FOCUS_BASE();
-MACRO_RECALC_FOCUS_SIZE();
+MACRO_RECALC_FOCUS_BASE(_center_ratio);
+MACRO_RECALC_FOCUS_SIZE(_center_ratio);
map_set_mark(&_gps->data);
map_force_redraw();
+return TRUE;
}
/**
base_old_x = base_new_x + new_base_tilex - _base_tilex;
_base_tilex = new_base_tilex;
_base_tiley = new_base_tiley;
+
for (j = 0; j < buf_height_tiles; ++j, new_y += ioy, old_y += ioy) {
new_x = base_new_x;
old_x = base_old_x;
}
MACRO_RECALC_OFFSET();
-MACRO_RECALC_FOCUS_BASE();
+MACRO_RECALC_FOCUS_BASE(_center_ratio);
map_set_mark(&_gps->data);
MACRO_QUEUE_DRAW_AREA();
x = unit2bufx(unitx);
y = unit2bufy(unity);
+if ((x > buf_width_pixels) || (y > buf_height_pixels))
+ return;
+
gdk_draw_pixbuf(map_pixmap, _gc[COLORABLE_POI],
p, 0, 0,
x - gdk_pixbuf_get_width(p) / 2,
static gboolean inp=FALSE;
/* We run the gtk mainloop in progress callback so we can be called again, we don't like that */
-if (inp==TRUE)
+if (inp==TRUE) {
+ g_debug("LOC: Query in progress");
return;
+}
inp=TRUE;
ilat=lat2mp_int(lat);
if (_gps->data.fix>1 && !force)
osm_set_way_range_from_speed(_gps->data.speed);
else
- osm_set_way_range(OSM_RANGE_WAY/8);
+ osm_set_way_range(2800);
osm_progress_set_widget(_db, _progress_item);
osm_get_location_data(ilat, ilon, _gps->data.heading, &map_loc);
};
#define MACRO_RECALC_OFFSET() { \
- _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \
- _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \
+ _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \
+ _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \
}
-#define MACRO_RECALC_FOCUS_BASE() { \
- _focus.unitx = x2unit(_screen_width_pixels * _center_ratio / 20); \
- _focus.unity = y2unit(_screen_height_pixels * _center_ratio / 20); \
+#define MACRO_RECALC_FOCUS_BASE(sens) { \
+ _focus.unitx = x2unit(_screen_width_pixels * sens / 20); \
+ _focus.unity = y2unit(_screen_height_pixels * sens / 20); \
}
#define MACRO_QUEUE_DRAW_AREA() \
/* Render all on-map metadata an annotations, including POI and paths. */
#define MACRO_MAP_RENDER_DATA() { \
- if(_show_poi) \
- map_render_poi(); \
- if(_show_tracks > 0) \
- map_render_paths(); \
+ if(_show_poi) \
+ map_render_poi(); \
+ if(_show_tracks > 0) \
+ map_render_paths(); \
}
-#define MACRO_RECALC_FOCUS_SIZE() { \
- _focus_unitwidth = pixel2unit((10 - _center_ratio) * _screen_width_pixels / 10); \
- _focus_unitheight = pixel2unit((10 - _center_ratio) * _screen_height_pixels / 10); \
+#define MACRO_RECALC_FOCUS_SIZE(sens) { \
+ _focus_unitwidth = pixel2unit((10 - sens) * _screen_width_pixels / 10); \
+ _focus_unitheight = pixel2unit((10 - sens) * _screen_height_pixels / 10); \
}
#define MACRO_RECALC_CENTER_BOUNDS() { \
- _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \
- _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \
- _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\
- _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight)- 1;\
+ _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \
+ _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \
+ _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\
+ _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight) - 1;\
}
typedef enum {
int map_zoom(gint zdir);
guint map_get_zoom(void);
-void map_set_zoom(guint zoom);
+gboolean map_set_zoom(guint zoom);
gboolean map_zoom_in(void);
gboolean map_zoom_out(void);
#define OSM_RANGE_STEP (8192)
#define OSM_RANGE_STOP (65535)
+/* Way range for searching again */
+#define OSM_RANGE_WAY (20000)
+
static sqlite3 *osmdb;
static gboolean osm_db_ok;
osm_set_way_range(guint sr)
{
way_dist_range=sr;
+g_debug("way_range set to %d", sr);
}
void
osm_set_way_range_from_speed(gfloat speed)
{
-if (speed>54.0)
- way_dist_range=OSM_RANGE_WAY;
-else
- way_dist_range=OSM_RANGE_WAY-lrint((speed/4)*1000);
+osm_set_way_range(speed>54.0 ? OSM_RANGE_WAY : (OSM_RANGE_WAY-lrint((speed/4)*1000)));
}
/*****************************************************************************/
dbpw=w;
if (w!=NULL) {
osm_progress_show(db);
- sid=g_timeout_add(200, (GSourceFunc)osm_progress_pulse, NULL);
+ sid=g_timeout_add(330, (GSourceFunc)osm_progress_pulse, NULL);
}
}
GList *w=NULL;
guint range=OSM_RANGE_START;
osm_way *cw=NULL;
+guint found_ways=0;
gdouble pdist=START_DIST, dist_n, dist_p;
while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=OSM_RANGE_STOP) {
range+=OSM_RANGE_STEP;
g_debug("Trying with range: %d", range);
}
-g_debug("Found %d ways withing range %d", g_list_length(w), range);
+found_ways=g_list_length(w);
+g_debug("Found %d ways withing range %d", found_ways, range);
-if (g_list_length(w)==0)
+if (found_ways==0)
return NULL;
for (iter=w; iter!=NULL; iter=iter->next) {
osm_way_node *wnp;
osm_way *way=(osm_way*)iter->data;
- g_debug("Way: %d (%d) has %d nodes, nearest is %d,%d",
- way->id, way->type, way->nodecnt, way->f, way->t);
-
way->node_t=NULL;
wnn=osm_way_get_next_node(way);
if (osm_way_distance(lat, lon, way->node_f, wnn, &dist_n)==FALSE) {
osm_way_node_free(wnn);
dist_n=START_DIST;
- } else if (dist_n<pdist) {
+ } else if (dist_n<pdist) { /* Is it near ?*/
pdist=dist_n;
cw=way;
way->distance=dist_n;
way->node_t=wnn;
- g_debug("#1 distance: %f (%f)", dist_n, pdist);
+ } else {
+ dist_n=START_DIST;
}
+ g_debug("WayN: #%d (T:%d), %d nodes, near [%d-%d], D: %.2f (Valid: %s)",
+ way->id, way->type, way->nodecnt, way->f, way->t, dist_n, dist_n==START_DIST ? "F" : "T");
+
wnp=osm_way_get_prev_node(way);
if (osm_way_distance(lat, lon, way->node_f, wnp, &dist_p)==FALSE) {
osm_way_node_free(wnp);
osm_way_node_free(wnn);
}
way->node_t=wnp;
- g_debug("#2 distance: %f (%f)", dist_p, pdist);
+ } else {
+ dist_p=START_DIST;
}
- g_debug("Found close way, distance: %f %f (%f)", dist_n, dist_p, pdist);
+ g_debug("WayP: #%d (T:%d), %d nodes, near [%d-%d], D: %.2f (Valid: %s)",
+ way->id, way->type, way->nodecnt, way->f, way->t, dist_p, dist_p==START_DIST ? "F" : "T");
if (!cw) {
osm_way_free(way);
osm_way_get_name(cw);
if (cw->type==WAY_MOTORWAY || cw->type==WAY_TRUNK ||
- cw->type==WAY_PRIMARY || cw->type==WAY_SECONDARY ||
- cw->type==WAY_TERTIARY) {
+ cw->type==WAY_PRIMARY || cw->type==WAY_SECONDARY || cw->type==WAY_TERTIARY) {
osm_way_get_ref(cw);
}
-g_debug("Found way: (ID: %d): [%s]:[%s][%s]", cw->id, cw->name, cw->ref, cw->int_ref);
-g_debug("T: %d F: %d N#: %d D: %f", cw->type, cw->flags, cw->nodecnt, cw->dist);
-g_debug("\tNF#: %d NT#: %d (D: %f)", cw->f, cw->t, cw->distance);
+g_debug("Found: (#%d): [%s]:[%s][%s]", cw->id, cw->name, cw->ref, cw->int_ref);
+g_debug("T: %d F: %d N#: %d D: %.2f", cw->type, cw->flags, cw->nodecnt, cw->dist);
+g_debug("NF#: %d NT#: %d (DC: %.2f)", cw->f, cw->t, cw->distance);
return cw;
}
*/
if ( (dist>(gdouble)way_dist_range) || (fabs(heading-map_loc->heading)>10.0)) {
/* We have moved a large amount, check way again */
- g_debug("Distance %f > %f range or angle %f > 10.0, checking location",
+ g_debug("Distance %.2f > %.2f range or angle %f > 10.0, checking location",
dist, (gdouble)way_dist_range, fabs(heading-map_loc->heading));
osm_way_free(map_loc->street);
map_loc->street=osm_find_nearest_way(lat, lon);
g_debug("Near city: %s", map_loc->primary->name);
else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE)
g_debug("Near town: %s", map_loc->primary->name);
- else
+ else {
+ g_assert(map_loc->primary!=NULL);
g_debug("Unknown");
+ }
} else {
g_debug("In: %s", map_loc->primary ? map_loc->primary->name : "?");
}
g_debug("Near city: %s", map_loc->primary->name);
else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE)
g_debug("Near town: %s", map_loc->primary->name);
- else
+ else {
+ g_assert(map_loc->primary!=NULL);
g_debug("Unknown");
-
+ }
}
}
#include <glib.h>
#include "osm.h"
-#define OSM_RANGE_WAY (20000)
-
/** Generic search item list indexes */
typedef enum {
ITEM_ID,