2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
5 * Copyright (C) 2006-2007 John Costigan.
7 * POI and GPS-Info code originally written by Cezary Jackiewicz.
9 * Default map data provided by http://www.openstreetmap.org/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include "mapper-types.h"
36 #include "ui-common.h"
41 #define POI_FONT_SIZE_BIG (10)
42 #define POI_FONT_SIZE_SMALL (8)
44 /* POI icon text pango stuff */
45 static PangoContext *context = NULL;
46 static PangoLayout *layout = NULL;
47 static PangoFontDescription *fontdesc = NULL;
49 static GtkListStore *poi_store=NULL;
50 static gint last_zoom=-1;
51 static guint prev_ux=0, prev_uy=0;
53 /****************************************************************************/
56 map_poi_init(GtkWidget *map_widget)
58 context=gtk_widget_get_pango_context(map_widget);
59 layout=pango_layout_new(context);
60 fontdesc=pango_font_description_new();
61 pango_font_description_set_family(fontdesc,"Sans Serif");
62 pango_font_description_set_size(fontdesc, POI_FONT_SIZE_SMALL*PANGO_SCALE);
63 pango_layout_set_font_description (layout, fontdesc);
64 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
65 pango_layout_set_width(layout, 80*PANGO_SCALE);
66 poi_gc=gdk_gc_new(map_widget->window);
73 map_poi_cache_clear();
75 g_object_unref(layout);
76 g_object_unref(fontdesc);
77 g_object_unref(poi_gc);
82 map_poi_title(gint x, gint y, GdkGC *gc, gchar *title)
86 pango_layout_set_text(layout, title, -1);
87 pango_layout_get_pixel_size(layout, &w, &h);
88 gdk_draw_layout(_map_pixmap, gc, x-(w>>1), y-h-_draw_width, layout);
92 * Set POI color from given #rrggbb string, fallback to default if it fails
95 map_set_poi_fg_color_from_string(gchar *hexcolor, GdkGC *def)
102 if (gdk_color_parse(hexcolor, &color)) {
103 gdk_gc_set_rgb_fg_color(poi_gc, &color);
111 map_poi_cache_clear(void)
116 gtk_list_store_clear(poi_store);
117 g_object_unref(G_OBJECT(poi_store));
122 map_poi_reload_poi(guint unitx, guint unity, gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2)
126 /* Reload POIs if we zoom out or have moved */
127 if ((last_zoom<_zoom || prev_ux!=unitx || prev_uy!=unity) && poi_store!=NULL) {
128 g_printf("Reloading POIs\n");
129 map_poi_cache_clear();
131 g_printf("Using cached POIs\n");
134 if (poi_store==NULL) {
135 if (poi_get_list_inside(lat1, lon1, lat2, lon2, &poi_store, &pois)==FALSE)
142 map_poi_find_at_latlon(gdouble lat, gdouble lon, guint *poi_id)
145 gboolean found=FALSE;
147 gdouble pdist=99999.0;
149 if (_poi_zoom <= _zoom)
160 valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(poi_store), &iter);
165 gdouble tmp, plat, plon;
168 gtk_tree_model_get(GTK_TREE_MODEL(poi_store),
175 /* XXX: Use quicker and simple distance check */
176 tmp=calculate_distance(lat, lon, plat, plon);
177 if ((tmp<pdist) && (tmp<0.011)) {
183 valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(poi_store), &iter);
190 * Render all the POI data.
191 * This should be done before rendering track data.
194 map_render_all_pois(guint width, guint height)
196 GdkPixbuf *pixbuf = NULL;
200 gdouble lat1, lat2, lon1, lon2;
203 if (_poi_zoom <= _zoom)
207 unity = y2unit(height);
208 unit2latlon(unitx, unity, lat1, lon1);
210 unitx = x2unit(width);
212 unit2latlon(unitx, unity, lat2, lon2);
214 if (map_poi_reload_poi(unitx, unity, lat1, lon1, lat2, lon2)==FALSE)
217 valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(poi_store), &iter);
222 pango_font_description_set_size(fontdesc, POI_FONT_SIZE_BIG*PANGO_SCALE);
223 pango_layout_set_font_description (layout, fontdesc);
224 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
226 pango_font_description_set_size(fontdesc, POI_FONT_SIZE_SMALL*PANGO_SCALE);
227 pango_layout_set_font_description (layout, fontdesc);
228 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
238 gchar *icon=NULL, *color=NULL;
240 gtk_tree_model_get(GTK_TREE_MODEL(poi_store),
249 pixbuf=poi_get_icon(icon, _zoom<2 ? TRUE : FALSE);
250 gc=map_set_poi_fg_color_from_string(color, _gc[COLORABLE_POI]);
252 latlon2unit(lat1, lon1, unitx, unity);
253 poix=unit2bufx(unitx);
254 poiy=unit2bufy(unity);
257 /* No icon for POI or for category - draw default. */
258 gdk_draw_arc(_map_pixmap, gc, FALSE, poix - _draw_width, poiy - _draw_width,
259 (MAX_ZOOM-_zoom)/6 * _draw_width, (MAX_ZOOM-_zoom)/6 * _draw_width, 0, 360 * 64);
262 w=gdk_pixbuf_get_width(pixbuf);
263 h=gdk_pixbuf_get_height(pixbuf);
264 gdk_draw_pixbuf(_map_pixmap, gc, pixbuf, 0, 0, poix-w/2, poiy-h/2, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
266 /* Draw rectangle around icon. Not really need with the square icons */
268 gdk_draw_rectangle(_map_pixmap, gc, FALSE, poix-w/2-1, poiy-h/2-1, w+1, h+1);
272 if (_zoom<3 && label) {
273 map_poi_title(poix, poiy, gc, label);
276 valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(poi_store), &iter);