#define _GNU_SOURCE
#include <gtk/gtk.h>
-#include <sqlite3.h>
#include "utils.h"
#include "poi.h"
#include "settings.h"
#include "mapper-types.h"
#include "ui-common.h"
-#include "db.h"
+#include "map-poi.h"
+#include "latlon.h"
#define POI_FONT_SIZE_BIG (10)
#define POI_FONT_SIZE_SMALL (8)
/* POI Icon theme. "classic" or "square". Should be made into a configuration option */
static gchar *theme="square";
+static GtkListStore *poi_store=NULL;
+
+static gint last_zoom=-1;
+static guint prev_ux=0, prev_uy=0;
+
+/****************************************************************************/
+
gboolean
map_poi_init(GtkWidget *map_widget)
{
return def;
}
+static gboolean
+map_poi_reload_poi(guint unitx, guint unity, gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2)
+{
+guint pois;
+
+/* Reload POIs if we zoom out or have moved */
+if ((last_zoom<_zoom || prev_ux!=unitx || prev_uy!=unity) && poi_store!=NULL) {
+ gtk_list_store_clear(poi_store);
+ g_object_unref(G_OBJECT(poi_store));
+ poi_store=NULL;
+ g_printf("Reloading POIs\n");
+} else {
+ g_printf("Using cached POIs\n");
+}
+
+if (poi_store==NULL) {
+ if (poi_get_list_inside(lat1, lon1, lat2, lon2, &poi_store, &pois)==FALSE)
+ return FALSE;
+}
+return TRUE;
+}
+
+gboolean
+map_poi_find_at_latlon(gdouble lat, gdouble lon, guint *poi_id)
+{
+GtkTreeIter iter;
+gboolean found=FALSE;
+gboolean valid;
+gdouble pdist=99999.0;
+
+if (_poi_zoom <= _zoom)
+ return FALSE;
+
+#if 0
+if (_zoom>5)
+ return FALSE;
+#endif
+
+if (poi_store==NULL)
+ return FALSE;
+
+valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(poi_store), &iter);
+if (valid==FALSE)
+ return FALSE;
+
+while (valid) {
+ gdouble tmp, plat, plon;
+ guint id;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(poi_store),
+ &iter,
+ ITEM_ID, &id,
+ ITEM_LAT, &plat,
+ ITEM_LON, &plon,
+ -1);
+
+ /* XXX: Use quicker and simple distance check */
+ tmp=calculate_distance(lat, lon, plat, plon);
+ if ((tmp<pdist) && (tmp<0.011)) {
+ found=TRUE;
+ pdist=tmp;
+ *poi_id=id;
+ }
+
+ valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(poi_store), &iter);
+}
+
+return found;
+}
+
/**
* Render all the POI data.
* This should be done before rendering track data.
gdouble lat1, lat2, lon1, lon2;
gint poix, poiy;
GdkPixbuf *pixbuf = NULL;
-static GtkListStore *store=NULL;
GtkTreeIter iter;
-guint pois;
gboolean valid;
-static gint last_zoom=-1;
-static guint prev_ux=0, prev_uy=0;
if (_poi_zoom <= _zoom)
return;
unity = y2unit(0);
unit2latlon(unitx, unity, lat2, lon2);
-/* Reload POIs if we zoom out or have moved */
-if ((last_zoom<_zoom || prev_ux!=unitx || prev_uy!=unity) && store!=NULL) {
- gtk_list_store_clear(store);
- g_object_unref(G_OBJECT(store));
- store=NULL;
- g_printf("Reloading POIs\n");
-} else {
- g_printf("Using cached POIs\n");
-}
-
-if (store==NULL) {
- if (poi_get_list_inside(lat1, lon1, lat2, lon2, &store, &pois)==FALSE)
- return;
-}
+if (map_poi_reload_poi(unitx, unity, lat1, lon1, lat2, lon2)==FALSE)
+ return;
-valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(poi_store), &iter);
if (!valid)
return;
pango_layout_set_font_description (layout, fontdesc);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
}
+
last_zoom=_zoom;
prev_ux=unitx;
prev_uy=unity;
gchar *label;
gchar *icon=NULL, *color=NULL;
- gtk_tree_model_get(GTK_TREE_MODEL(store),
+ gtk_tree_model_get(GTK_TREE_MODEL(poi_store),
&iter,
ITEM_LAT, &lat1,
ITEM_LON, &lon1,
map_poi_title(poix, poiy, gc, label);
}
- valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(poi_store), &iter);
}
}
--- /dev/null
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ *
+ * POI and GPS-Info code originally written by Cezary Jackiewicz.
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef _MAPPER_MAP_POI_H
+#define _MAPPER_MAP_POI_H
+
+gboolean map_poi_init(GtkWidget *map_widget);
+void map_render_poi(void);
+gboolean map_poi_find_at_latlon(gdouble lat, gdouble lon, guint *poi_id);
+
+#endif
#include "settings.h"
#include "latlon.h"
#include "gpx.h"
+#include "map-poi.h"
#include "map-download.h"
#include "gtkcompass.h"
/******************************************************************************/
+GtkWidget *
+map_new(void)
+{
+return GTK_WIDGET(gtk_drawing_area_new());
+}
+
gboolean
map_cb_configure(GtkWidget *widget, GdkEventConfigure *event)
{
static void
map_draw_mark(void)
{
-gdk_draw_arc(_map_widget->window,
- _conn_state == RCVR_FIXED ? _gc[COLORABLE_MARK] : _gc[COLORABLE_MARK_OLD], FALSE,
- _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],
+gdk_draw_arc(_map_widget->window, _conn_state == RCVR_FIXED ? _gc[COLORABLE_MARK] : _gc[COLORABLE_MARK_OLD], FALSE,
+ _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],
_mark_x1, _mark_y1, _mark_x2, _mark_y2);
}
{
/* Force re-validation of place if user is clicking around */
map_loc.valid=FALSE;
+/* XXX: hmm, not the right place for this */
if (_gps.fix<2) {
_pos.unitx=_center.unitx;
_pos.unity=_center.unity;
+ unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
}
map_update_location(_center.unitx, _center.unity, TRUE);
return FALSE;
static void
map_drag_stop(gint x, gint y)
{
+if (map_drag_id==0)
+ return;
+
release[0]=x;
release[1]=y;
g_signal_handler_disconnect(G_OBJECT(_map_widget), map_drag_id);
gboolean
map_cb_button_press(GtkWidget * widget, GdkEventButton * event)
{
+gdouble lat, lon;
+guint poi_id;
+gint ux, uy;
+
_cmenu_position_x = event->x + 0.5;
_cmenu_position_y = event->y + 0.5;
case 1:
if (event->type==GDK_2BUTTON_PRESS) {
map_center_unit(x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5)));
+ map_set_zoom(_zoom - 1);
return FALSE;
}
if (event->type==GDK_3BUTTON_PRESS)
return FALSE;
- map_drag_start(event->x, event->y);
+
+ ux=x2unit(_cmenu_position_x);
+ uy=y2unit(_cmenu_position_y);
+
+ unit2latlon(ux, uy, lat, lon);
+ if (map_poi_find_at_latlon(lat, lon, &poi_id)==TRUE) {
+ g_printf("POI: %d\n", poi_id);
+ } else {
+ map_drag_start(event->x, event->y);
+ }
break;
case 2:
map_set_zoom(_zoom - 1);
default:
map_drag_stop(event->x, event->y);
map_render_data();
+ g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL);
break;
}
- g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL);
break;
case 2:
/* */
gboolean _map_location_known;
gdouble _map_location_dist;
+GtkWidget *map_new(void);
+
gboolean map_key_zoom_timeout();
int map_zoom(gint zdir);
ui_notebook.map=gtk_notebook_append_page(notebook, mapvbox, label);
/* Map widget */
-_map_widget = gtk_drawing_area_new();
+_map_widget = map_new();
gtk_paned_add2(GTK_PANED(hbox), _map_widget);
gtk_widget_realize(_map_widget);