const gchar *attr_name = *curr_attr++;
const gchar *attr_val = *curr_attr++;
if (!strcmp(attr_name, "lat")) {
- lat =
- g_ascii_strtod(attr_val,
- &error_check);
+ lat = g_ascii_strtod(attr_val, &error_check);
if (error_check != attr_val)
has_lat = TRUE;
} else if (!strcmp(attr_name, "lon")) {
- lon =
- g_ascii_strtod(attr_val,
- &error_check);
+ lon = g_ascii_strtod(attr_val, &error_check);
if (error_check != attr_val)
has_lon = TRUE;
}
}
if (has_lat && has_lon) {
MACRO_PATH_INCREMENT_TAIL(data->path);
- latlon2unit(lat, lon,
- data->path.tail->unitx,
- data->path.tail->unity);
+ latlon2unit(lat, lon, data->path.tail->unitx, data->path.tail->unity);
data->path.tail->time = 0;
data->path.tail->altitude = NAN;
data->state = INSIDE_PATH_POINT;
case INSIDE_PATH_POINT_ELE:
if (!strcmp((gchar *) name, "ele")) {
gchar *error_check;
- data->path.tail->altitude
- = g_ascii_strtod(data->chars->str, &error_check);
+ data->path.tail->altitude = g_ascii_strtod(data->chars->str, &error_check);
if (error_check == data->chars->str)
data->path.tail->altitude = NAN;
data->state = INSIDE_PATH_POINT;
if (*ptr == 'Z')
/* Zulu (UTC) time. Undo the local time zone's
* offset. */
- data->path.tail->time +=
- time.tm_gmtoff;
+ data->path.tail->time += time.tm_gmtoff;
else {
/* Not Zulu (UTC). Must parse hours and minutes. */
gint offhours =
#define _GNU_SOURCE
#include <gtk/gtk.h>
-
#include <sqlite3.h>
#include "utils.h"
#include "poi.h"
#include "gps.h"
#include "map.h"
-#include "route.h"
#include "settings.h"
#include "mapper-types.h"
#include "ui-common.h"
+#define POI_FONT_SIZE (10)
+
+static GHashTable *poi_icon_hash = NULL;
+static PangoContext *context = NULL;
+static PangoLayout *layout = NULL;
+static PangoFontDescription *fontdesc = NULL;
+
+gboolean map_poi_init(GtkWidget *map_widget)
+{
+poi_icon_hash=g_hash_table_new(g_str_hash, g_str_equal);
+context = gtk_widget_get_pango_context(map_widget);
+layout = pango_layout_new(context);
+fontdesc = pango_font_description_new();
+pango_font_description_set_family(fontdesc,"Sans Serif");
+pango_font_description_set_size(fontdesc, POI_FONT_SIZE*PANGO_SCALE);
+pango_layout_set_font_description (layout, fontdesc);
+}
+
+static void map_poi_title(gint x, gint y,gchar *title)
+{
+pango_layout_set_text(layout, title, -1);
+gdk_draw_layout(_map_pixmap, _gc[COLORABLE_POI], x, y, layout);
+}
+
/**
* Render all the POI data. This should be done before rendering track data.
*/
void map_render_poi()
{
- guint unitx, unity;
- gfloat lat1, lat2, lon1, lon2;
- gchar buffer[100];
- gint poix, poiy;
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- if (_db && _poi_zoom > _zoom) {
- unitx = x2unit(0);
- unity = y2unit(BUF_HEIGHT_PIXELS);
- unit2latlon(unitx, unity, lat1, lon1);
- unitx = x2unit(BUF_WIDTH_PIXELS);
- unity = y2unit(0);
- unit2latlon(unitx, unity, lat2, lon2);
-
- if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1)
- || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2,
- lat2)
- || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3,
- lon1)
- || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4,
- lon2)) {
- g_printerr
- ("Failed to bind values for _stmt_select_poi");
- return;
- }
-
- while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
- lat1 = sqlite3_column_double(_stmt_select_poi, 0);
- lon1 = sqlite3_column_double(_stmt_select_poi, 1);
- gchar *poi_label =
- g_utf8_strdown(sqlite3_column_text
- (_stmt_select_poi, 3), -1);
- gchar *cat_label =
- g_utf8_strdown(sqlite3_column_text
- (_stmt_select_poi, 6), -1);
-
- latlon2unit(lat1, lon1, unitx, unity);
- poix = unit2bufx(unitx);
- poiy = unit2bufy(unity);
-
- /* Try to get icon for specific POI first. */
- snprintf(buffer, sizeof(buffer), "%s/poi/%s.jpg",
- _curr_repo->cache_dir, poi_label);
- pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
- if (error) {
- /* No icon for specific POI - try for category. */
- error = NULL;
- snprintf(buffer, sizeof(buffer),
- "%s/poi/%s.jpg", _curr_repo->cache_dir,
- cat_label);
- pixbuf =
- gdk_pixbuf_new_from_file(buffer, &error);
- }
- if (error) {
- /* No icon for POI or for category - draw default. */
- error = NULL;
- gdk_draw_rectangle(_map_pixmap,
- _gc[COLORABLE_POI], TRUE,
- poix -
- (gint) (1.5f * _draw_width),
- poiy -
- (gint) (1.5f * _draw_width),
- 3 * _draw_width,
- 3 * _draw_width);
- } else {
- gdk_draw_pixbuf(_map_pixmap,
- _gc[COLORABLE_POI],
- pixbuf,
- 0, 0,
- poix -
- gdk_pixbuf_get_width(pixbuf) /
- 2,
- poiy -
- gdk_pixbuf_get_height(pixbuf) /
- 2, -1, -1, GDK_RGB_DITHER_NONE,
- 0, 0);
- g_object_unref(pixbuf);
- }
-
- g_free(poi_label);
- g_free(cat_label);
- }
- sqlite3_reset(_stmt_select_poi);
+guint unitx, unity;
+gfloat lat1, lat2, lon1, lon2;
+gchar buffer[100];
+gint poix, poiy;
+GdkPixbuf *pixbuf = NULL;
+GError *error = NULL;
+printf("%s()\n", __PRETTY_FUNCTION__);
+
+if (!_db) return;
+if (_poi_zoom <= _zoom) return;
+
+unitx = x2unit(0);
+unity = y2unit(BUF_HEIGHT_PIXELS);
+unit2latlon(unitx, unity, lat1, lon1);
+unitx = x2unit(BUF_WIDTH_PIXELS);
+unity = y2unit(0);
+unit2latlon(unitx, unity, lat2, lon2);
+
+if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1)
+ || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2,lat2)
+ || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3,lon1)
+ || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4,lon2)) {
+ g_printerr("Failed to bind values for _stmt_select_poi");
+ return;
+}
+
+while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
+ lat1 = sqlite3_column_double(_stmt_select_poi, 0);
+ lon1 = sqlite3_column_double(_stmt_select_poi, 1);
+ gchar *poi_label = g_utf8_strdown(sqlite3_column_text(_stmt_select_poi, 3), -1);
+ gchar *cat_label = g_utf8_strdown(sqlite3_column_text(_stmt_select_poi, 6), -1);
+
+ latlon2unit(lat1, lon1, unitx, unity);
+ poix = unit2bufx(unitx);
+ poiy = unit2bufy(unity);
+
+ /* Try to get icon for specific POI first. */
+ snprintf(buffer, sizeof(buffer), "%s/poi/%s.jpg", _curr_repo->cache_dir, poi_label);
+ pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
+ if (error) {
+ /* No icon for specific POI - try for category. */
+ error = NULL;
+ snprintf(buffer, sizeof(buffer),"%s/poi/%s.jpg", _curr_repo->cache_dir, cat_label);
+ pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
+ }
+ if (error) {
+ /* No icon for POI or for category - draw default. */
+ error = NULL;
+ gdk_draw_rectangle(_map_pixmap,
+ _gc[COLORABLE_POI], TRUE,
+ poix - (gint) (1.5f * _draw_width),
+ poiy - (gint) (1.5f * _draw_width),
+ 3 * _draw_width,
+ 3 * _draw_width);
+ map_poi_title(poix, poiy, poi_label);
+ } else {
+ gdk_draw_pixbuf(_map_pixmap,
+ _gc[COLORABLE_POI],
+ pixbuf, 0, 0,
+ poix - gdk_pixbuf_get_width(pixbuf) /
+ 2,
+ poiy - gdk_pixbuf_get_height(pixbuf) /
+ 2, -1, -1, GDK_RGB_DITHER_NONE,
+ 0, 0);
+ g_object_unref(pixbuf);
}
- vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+ g_free(poi_label);
+ g_free(cat_label);
+}
+sqlite3_reset(_stmt_select_poi);
+
+vprintf("%s(): return\n", __PRETTY_FUNCTION__);
}
gtk_widget_show_all(hbox);
gps_show_info(); /* hides info, if necessary. */
-
gtk_widget_realize(_map_widget);
+ map_poi_init(_map_widget);
_map_pixmap = gdk_pixmap_new(_map_widget->window, BUF_WIDTH_PIXELS, BUF_HEIGHT_PIXELS, -1); /* -1: use bit depth of widget->window. */
_speed_limit_context = gtk_widget_get_pango_context(_map_widget);
_speed_limit_layout = pango_layout_new(_speed_limit_context);
_speed_limit_fontdesc = pango_font_description_new();
- pango_font_description_set_size(_speed_limit_fontdesc,
- 64 * PANGO_SCALE);
- pango_layout_set_font_description(_speed_limit_layout,
- _speed_limit_fontdesc);
+ pango_font_description_set_size(_speed_limit_fontdesc,64 * PANGO_SCALE);
+ pango_layout_set_font_description(_speed_limit_layout, _speed_limit_fontdesc);
pango_layout_set_alignment(_speed_limit_layout, PANGO_ALIGN_CENTER);
/* draw_sat_info() */
_sat_panel_fontdesc = pango_font_description_new();
pango_font_description_set_family(_sat_panel_fontdesc, "Sans Serif");
pango_font_description_set_size(_sat_panel_fontdesc, 14 * PANGO_SCALE);
- pango_layout_set_font_description(_sat_panel_layout,
- _sat_panel_fontdesc);
+ pango_layout_set_font_description(_sat_panel_layout, _sat_panel_fontdesc);
/* heading_panel_expose() */
_heading_panel_context = gtk_widget_get_pango_context(_map_widget);
_heading_panel_layout = pango_layout_new(_heading_panel_context);
_heading_panel_fontdesc = pango_font_description_new();
- pango_font_description_set_family(_heading_panel_fontdesc,
- "Sans Serif");
+ pango_font_description_set_family(_heading_panel_fontdesc, "Sans Serif");
/* draw_sat_details() */
_sat_details_context = gtk_widget_get_pango_context(_map_widget);
_sat_details_fontdesc = pango_font_description_new();
pango_font_description_set_family(_sat_details_fontdesc, "Sans Serif");
- pango_font_description_set_size(_sat_details_fontdesc,
- 10 * PANGO_SCALE);
- pango_layout_set_font_description(_sat_details_layout,
- _sat_details_fontdesc);
+ pango_font_description_set_size(_sat_details_fontdesc, 10 * PANGO_SCALE);
+ pango_layout_set_font_description(_sat_details_layout, _sat_details_fontdesc);
pango_layout_set_alignment(_sat_details_layout, PANGO_ALIGN_CENTER);
/* sat_details_panel_expose() */
_sat_details_expose_context = gtk_widget_get_pango_context(_map_widget);
- _sat_details_expose_layout =
- pango_layout_new(_sat_details_expose_context);
+ _sat_details_expose_layout = pango_layout_new(_sat_details_expose_context);
_sat_details_expose_fontdesc = pango_font_description_new();
- pango_font_description_set_family(_sat_details_expose_fontdesc,
- "Sans Serif");
- pango_layout_set_alignment(_sat_details_expose_layout,
- PANGO_ALIGN_CENTER);
- pango_font_description_set_size(_sat_details_expose_fontdesc,
- 14 * PANGO_SCALE);
- pango_layout_set_font_description(_sat_details_expose_layout,
- _sat_details_expose_fontdesc);
+ pango_font_description_set_family(_sat_details_expose_fontdesc, "Sans Serif");
+ pango_layout_set_alignment(_sat_details_expose_layout, PANGO_ALIGN_CENTER);
+ pango_font_description_set_size(_sat_details_expose_fontdesc,14 * PANGO_SCALE);
+ pango_layout_set_font_description(_sat_details_expose_layout, _sat_details_expose_fontdesc);
_last_spoken_phrase = g_strdup("");