33 |
|
|
34 |
#include <gdk/gdk.h> |
#include <gdk/gdk.h> |
35 |
#include <glib.h> |
#include <glib.h> |
36 |
|
#include <glib/gstdio.h> |
37 |
#include <glib/gprintf.h> |
#include <glib/gprintf.h> |
38 |
#include <libsoup/soup.h> |
#include <libsoup/soup.h> |
39 |
|
|
84 |
//contains flags indicating the various special characters |
//contains flags indicating the various special characters |
85 |
//the uri string contains, that will be replaced when calculating |
//the uri string contains, that will be replaced when calculating |
86 |
//the uri to download. |
//the uri to download. |
87 |
|
OsmGpsMapSource_t map_source; |
88 |
char *repo_uri; |
char *repo_uri; |
89 |
|
char *image_format; |
90 |
int uri_format; |
int uri_format; |
91 |
//flag indicating if the map source is located on the google |
//flag indicating if the map source is located on the google |
92 |
gboolean the_google; |
gboolean the_google; |
107 |
GdkGC *gc_map; |
GdkGC *gc_map; |
108 |
|
|
109 |
//The tile painted when one cannot be found |
//The tile painted when one cannot be found |
110 |
//GdkPixbuf *missing_tile; |
GdkPixbuf *null_tile; |
111 |
|
|
112 |
//For tracking click and drag |
//For tracking click and drag |
113 |
int drag_counter; |
int drag_counter; |
160 |
PROP_TILES_QUEUED, |
PROP_TILES_QUEUED, |
161 |
PROP_GPS_TRACK_WIDTH, |
PROP_GPS_TRACK_WIDTH, |
162 |
PROP_GPS_POINT_R1, |
PROP_GPS_POINT_R1, |
163 |
PROP_GPS_POINT_R2 |
PROP_GPS_POINT_R2, |
164 |
|
PROP_MAP_SOURCE, |
165 |
|
PROP_IMAGE_FORMAT |
166 |
}; |
}; |
167 |
|
|
168 |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
176 |
static void osm_gps_map_print_images (OsmGpsMap *map); |
static void osm_gps_map_print_images (OsmGpsMap *map); |
177 |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
178 |
static void osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y); |
static void osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y); |
179 |
|
#ifdef LIBSOUP22 |
180 |
|
static void osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data); |
181 |
|
#else |
182 |
|
static void osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data); |
183 |
|
#endif |
184 |
static void osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw); |
static void osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw); |
185 |
static void osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y); |
static void osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y); |
186 |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
430 |
g_log_default_handler (log_domain, log_level, message, user_data); |
g_log_default_handler (log_domain, log_level, message, user_data); |
431 |
} |
} |
432 |
|
|
433 |
|
static float |
434 |
|
osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon) |
435 |
|
{ |
436 |
|
/* world at zoom 1 == 512 pixels */ |
437 |
|
return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom)); |
438 |
|
} |
439 |
|
|
440 |
/* clears the trip list and all resources */ |
/* clears the trip list and all resources */ |
441 |
static void |
static void |
442 |
osm_gps_map_free_trip (OsmGpsMap *map) |
osm_gps_map_free_trip (OsmGpsMap *map) |
546 |
int x, y; |
int x, y; |
547 |
int r = priv->ui_gps_point_inner_radius; |
int r = priv->ui_gps_point_inner_radius; |
548 |
int r2 = priv->ui_gps_point_outer_radius; |
int r2 = priv->ui_gps_point_outer_radius; |
549 |
|
// int lw = priv->ui_gps_track_width; |
550 |
int mr = MAX(r,r2); |
int mr = MAX(r,r2); |
551 |
|
|
552 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
557 |
cairo_t *cr; |
cairo_t *cr; |
558 |
cairo_pattern_t *pat; |
cairo_pattern_t *pat; |
559 |
#else |
#else |
|
int lw = priv->ui_gps_track_width; |
|
560 |
GdkColor color; |
GdkColor color; |
561 |
GdkGC *marker; |
GdkGC *marker; |
562 |
#endif |
#endif |
633 |
} |
} |
634 |
} |
} |
635 |
|
|
636 |
|
/* http://cairographics.org/samples/ */ |
637 |
|
static void |
638 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map) |
639 |
|
{ |
640 |
|
OsmGpsMapPrivate *priv = map->priv; |
641 |
|
|
642 |
|
/* xyz */ |
643 |
|
#define X 100 |
644 |
|
#define Y 100 |
645 |
|
#define RADIUS 20 |
646 |
|
#define WIDTH 150 |
647 |
|
#define HEIGHT 75 |
648 |
|
#define TRANSPARENCY 0.7 |
649 |
|
#define PIN_HEIGHT 20 |
650 |
|
#define PIN_FOOT_WIDTH 20 |
651 |
|
#define PIN_X (X + EXTRA_BORDER) |
652 |
|
#define PIN_X0 (X + EXTRA_BORDER + RADIUS + PIN_FOOT_WIDTH) |
653 |
|
#define PIN_X1 (X + EXTRA_BORDER + RADIUS) |
654 |
|
#define PIN_Y (Y + EXTRA_BORDER + HEIGHT + PIN_HEIGHT) |
655 |
|
|
656 |
|
#ifdef USE_CAIRO |
657 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
658 |
|
|
659 |
|
int x0 = X + EXTRA_BORDER, y0 = Y + EXTRA_BORDER; |
660 |
|
int x1 = x0 + WIDTH, y1 = y0 + HEIGHT; |
661 |
|
|
662 |
|
cairo_move_to (cr, x0, y0 + RADIUS); |
663 |
|
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + RADIUS, y0); |
664 |
|
cairo_line_to (cr, x1 - RADIUS, y0); |
665 |
|
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + RADIUS); |
666 |
|
cairo_line_to (cr, x1 , y1 - RADIUS); |
667 |
|
cairo_curve_to (cr, x1, y1, x1, y1, x1 - RADIUS, y1); |
668 |
|
|
669 |
|
/* insert pin */ |
670 |
|
cairo_line_to (cr, PIN_X0, y1); |
671 |
|
cairo_line_to (cr, PIN_X, PIN_Y); |
672 |
|
cairo_line_to (cr, PIN_X1, y1); |
673 |
|
|
674 |
|
|
675 |
|
cairo_line_to (cr, x0 + RADIUS, y1); |
676 |
|
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - RADIUS); |
677 |
|
|
678 |
|
cairo_close_path (cr); |
679 |
|
cairo_set_source_rgba (cr, 1, 1, 1, TRANSPARENCY); |
680 |
|
cairo_fill_preserve (cr); |
681 |
|
cairo_set_source_rgba (cr, 0, 0, 0, TRANSPARENCY); |
682 |
|
cairo_set_line_width (cr, 1); |
683 |
|
cairo_stroke (cr); |
684 |
|
|
685 |
|
gtk_widget_queue_draw_area (GTK_WIDGET(map), |
686 |
|
x0, |
687 |
|
y0, |
688 |
|
WIDTH, |
689 |
|
HEIGHT + PIN_HEIGHT); |
690 |
|
#endif |
691 |
|
} |
692 |
|
|
693 |
static void |
static void |
694 |
osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y) |
osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y) |
695 |
{ |
{ |
696 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
697 |
|
|
698 |
g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, |
g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, TILESIZE,TILESIZE); |
|
TILESIZE,TILESIZE); |
|
699 |
|
|
700 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
701 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
727 |
osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data) |
osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data) |
728 |
#endif |
#endif |
729 |
{ |
{ |
730 |
int fd; |
FILE *file; |
731 |
tile_download_t *dl = (tile_download_t *)user_data; |
tile_download_t *dl = (tile_download_t *)user_data; |
732 |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
733 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
740 |
{ |
{ |
741 |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
742 |
{ |
{ |
743 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
file = g_fopen(dl->filename, "wb"); |
744 |
if (fd != -1) |
if (file != NULL) |
745 |
{ |
{ |
746 |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file); |
747 |
file_saved = TRUE; |
file_saved = TRUE; |
748 |
|
g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
749 |
|
fclose (file); |
750 |
|
|
|
g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
|
|
close (fd); |
|
751 |
} |
} |
752 |
} |
} |
753 |
else |
else |
760 |
{ |
{ |
761 |
GdkPixbuf *pixbuf = NULL; |
GdkPixbuf *pixbuf = NULL; |
762 |
|
|
763 |
|
/* if the file was actually stored on disk, we can simply */ |
764 |
|
/* load and decode it from that file */ |
765 |
if (priv->cache_dir) |
if (priv->cache_dir) |
766 |
{ |
{ |
767 |
if (file_saved) |
if (file_saved) |
795 |
g_warning("Error: Unable to determine image file format"); |
g_warning("Error: Unable to determine image file format"); |
796 |
} |
} |
797 |
} |
} |
798 |
|
|
799 |
/* Store the tile into the cache */ |
/* Store the tile into the cache */ |
800 |
if (G_LIKELY (pixbuf)) |
if (G_LIKELY (pixbuf)) |
801 |
{ |
{ |
810 |
* we are using it as a key in the hash table */ |
* we are using it as a key in the hash table */ |
811 |
dl->filename = NULL; |
dl->filename = NULL; |
812 |
} |
} |
|
|
|
813 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
814 |
} |
} |
815 |
g_hash_table_remove(priv->tile_queue, dl->uri); |
g_hash_table_remove(priv->tile_queue, dl->uri); |
868 |
g_free(dl->uri); |
g_free(dl->uri); |
869 |
g_free(dl); |
g_free(dl); |
870 |
} else { |
} else { |
871 |
dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x); |
dl->folder = g_strdup_printf("%s%c%d%c%d%c", |
872 |
dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y); |
priv->cache_dir, G_DIR_SEPARATOR, |
873 |
|
zoom, G_DIR_SEPARATOR, |
874 |
|
x, G_DIR_SEPARATOR); |
875 |
|
dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
876 |
|
priv->cache_dir, G_DIR_SEPARATOR, |
877 |
|
zoom, G_DIR_SEPARATOR, |
878 |
|
x, G_DIR_SEPARATOR, |
879 |
|
y, |
880 |
|
priv->image_format); |
881 |
dl->map = map; |
dl->map = map; |
882 |
dl->redraw = redraw; |
dl->redraw = redraw; |
883 |
|
|
895 |
if (cookie) { |
if (cookie) { |
896 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
897 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
|
|
|
898 |
} |
} |
899 |
} |
} |
900 |
} |
} |
916 |
{ |
{ |
917 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
918 |
gchar *filename; |
gchar *filename; |
919 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf = NULL; |
920 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
921 |
|
|
922 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
923 |
priv->cache_dir, |
priv->cache_dir, G_DIR_SEPARATOR, |
924 |
zoom, x, y); |
zoom, G_DIR_SEPARATOR, |
925 |
|
x, G_DIR_SEPARATOR, |
926 |
|
y, |
927 |
|
priv->image_format); |
928 |
|
|
929 |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
930 |
if (tile) |
if (tile) |
931 |
{ |
{ |
932 |
g_free (filename); |
g_free (filename); |
933 |
} |
} |
934 |
else if (priv->cache_dir) |
else |
935 |
{ |
{ |
936 |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
937 |
if (pixbuf) |
if (pixbuf) |
947 |
{ |
{ |
948 |
tile->redraw_cycle = priv->redraw_cycle; |
tile->redraw_cycle = priv->redraw_cycle; |
949 |
pixbuf = g_object_ref (tile->pixbuf); |
pixbuf = g_object_ref (tile->pixbuf); |
950 |
} else |
} |
|
pixbuf = NULL; |
|
951 |
|
|
952 |
return pixbuf; |
return pixbuf; |
953 |
} |
} |
1011 |
osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y) |
osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y) |
1012 |
{ |
{ |
1013 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1014 |
|
gchar *filename; |
1015 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf; |
1016 |
|
|
1017 |
g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom); |
g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom); |
1018 |
|
|
1019 |
/* try to get file from internal cache */ |
if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) { |
1020 |
pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y); |
osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y); |
1021 |
|
return; |
1022 |
|
} |
1023 |
|
|
1024 |
/* if a disk cache is being used, try to read the file from there */ |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1025 |
if (priv->cache_dir && !pixbuf) |
priv->cache_dir, G_DIR_SEPARATOR, |
1026 |
{ |
zoom, G_DIR_SEPARATOR, |
1027 |
gchar *filename; |
x, G_DIR_SEPARATOR, |
1028 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
y, |
1029 |
priv->cache_dir, |
priv->image_format); |
|
zoom, x, y); |
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
|
|
if (pixbuf) |
|
|
{ |
|
|
g_debug("Found tile %s", filename); |
|
|
} |
|
1030 |
|
|
1031 |
g_free(filename); |
/* try to get file from internal cache first */ |
1032 |
} |
if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y))) |
1033 |
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1034 |
|
|
1035 |
if (G_LIKELY(pixbuf)) |
if(pixbuf) |
1036 |
{ |
{ |
1037 |
|
g_debug("Found tile %s", filename); |
1038 |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
1039 |
g_object_unref (pixbuf); |
g_object_unref (pixbuf); |
1040 |
} |
} |
1065 |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
1066 |
} |
} |
1067 |
} |
} |
1068 |
|
g_free(filename); |
1069 |
} |
} |
1070 |
|
|
1071 |
static void |
static void |
1159 |
|
|
1160 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
1161 |
map_y0 = priv->map_y - EXTRA_BORDER; |
map_y0 = priv->map_y - EXTRA_BORDER; |
|
|
|
1162 |
for(list = trackpoint_list; list != NULL; list = list->next) |
for(list = trackpoint_list; list != NULL; list = list->next) |
1163 |
{ |
{ |
1164 |
coord_t *tp = list->data; |
coord_t *tp = list->data; |
1213 |
|
|
1214 |
if (priv->show_trip_history) |
if (priv->show_trip_history) |
1215 |
osm_gps_map_print_track (map, priv->trip_history); |
osm_gps_map_print_track (map, priv->trip_history); |
1216 |
|
|
1217 |
if (priv->tracks) |
if (priv->tracks) |
1218 |
{ |
{ |
|
g_debug("TRACK"); |
|
1219 |
GSList* tmp = priv->tracks; |
GSList* tmp = priv->tracks; |
1220 |
while (tmp != NULL) |
while (tmp != NULL) |
1221 |
{ |
{ |
1225 |
} |
} |
1226 |
} |
} |
1227 |
|
|
1228 |
static gboolean |
static gboolean |
1229 |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
1230 |
{ |
{ |
1231 |
return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
1232 |
} |
} |
1233 |
|
|
1234 |
static void |
static void |
1235 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1236 |
{ |
{ |
1237 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1238 |
|
|
1239 |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
1240 |
return; |
return; |
1241 |
|
|
1242 |
/* run through the cache, and remove the tiles which have not been used |
/* run through the cache, and remove the tiles which have not been used |
1243 |
* during the last redraw operation */ |
* during the last redraw operation */ |
1244 |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
1245 |
} |
} |
1246 |
|
|
1247 |
static gboolean |
static gboolean |
1275 |
osm_gps_map_draw_gps_point(map); |
osm_gps_map_draw_gps_point(map); |
1276 |
osm_gps_map_print_images(map); |
osm_gps_map_print_images(map); |
1277 |
|
|
1278 |
|
osm_gps_map_draw_balloon(map); |
1279 |
|
|
1280 |
//osm_gps_map_osd_speed(map, 1.5); |
//osm_gps_map_osd_speed(map, 1.5); |
1281 |
osm_gps_map_purge_cache(map); |
osm_gps_map_purge_cache(map); |
1282 |
gtk_widget_queue_draw (GTK_WIDGET (map)); |
gtk_widget_queue_draw (GTK_WIDGET (map)); |
1319 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1320 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1321 |
|
|
1322 |
|
priv->map_source = -1; |
1323 |
|
|
1324 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1325 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1326 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1374 |
{ |
{ |
1375 |
GObject *object; |
GObject *object; |
1376 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1377 |
|
OsmGpsMap *map; |
1378 |
|
const char *uri; |
1379 |
|
|
1380 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1381 |
object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties); |
object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties); |
1382 |
|
map = OSM_GPS_MAP(object); |
1383 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1384 |
|
|
1385 |
|
//user can specify a map source ID, or a repo URI as the map source |
1386 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1387 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1388 |
|
g_debug("Using null source"); |
1389 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1390 |
|
|
1391 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1392 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1393 |
|
} |
1394 |
|
else if (priv->map_source >= 0) { |
1395 |
|
//check if the source given is valid |
1396 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1397 |
|
if (uri) { |
1398 |
|
g_debug("Setting map source from ID"); |
1399 |
|
g_free(priv->repo_uri); |
1400 |
|
|
1401 |
|
priv->repo_uri = g_strdup(uri); |
1402 |
|
priv->image_format = g_strdup( |
1403 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1404 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1405 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1406 |
|
} |
1407 |
|
} |
1408 |
|
|
1409 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1410 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1411 |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
1416 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1417 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1418 |
//the new cachedir is the given cache dir + the md5 of the repo_uri |
//the new cachedir is the given cache dir + the md5 of the repo_uri |
1419 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1420 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1421 |
g_free(old); |
g_free(old); |
1422 |
|
} else { |
1423 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1424 |
|
priv->cache_dir = g_strdup(md5); |
1425 |
} |
} |
1426 |
|
|
1427 |
g_free(md5); |
g_free(md5); |
1428 |
} |
} |
1429 |
|
|
1430 |
|
inspect_map_uri(map); |
1431 |
|
|
1432 |
return object; |
return object; |
1433 |
} |
} |
1434 |
|
|
1455 |
if(priv->pixmap) |
if(priv->pixmap) |
1456 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1457 |
|
|
1458 |
|
if (priv->null_tile) |
1459 |
|
g_object_unref (priv->null_tile); |
1460 |
|
|
1461 |
if(priv->gc_map) |
if(priv->gc_map) |
1462 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1463 |
|
|
1475 |
|
|
1476 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
1477 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
1478 |
|
g_free(priv->image_format); |
1479 |
|
|
1480 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
1481 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
1506 |
break; |
break; |
1507 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
1508 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
1509 |
break; |
break; |
1510 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1511 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
1512 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1513 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
1514 |
|
|
1515 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1516 |
GValue val = {0}; |
GValue val = {0}; |
1517 |
|
|
1518 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1519 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1520 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1524 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
1525 |
g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL); |
g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL); |
1526 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
1527 |
} else |
} else |
1528 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1529 |
|
|
1530 |
break; |
break; |
1531 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
1532 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
1533 |
|
priv->cache_dir = g_value_dup_string (value); |
1534 |
break; |
break; |
1535 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
1536 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
1561 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1562 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
1563 |
break; |
break; |
1564 |
|
case PROP_MAP_SOURCE: |
1565 |
|
priv->map_source = g_value_get_int (value); |
1566 |
|
break; |
1567 |
|
case PROP_IMAGE_FORMAT: |
1568 |
|
priv->image_format = g_value_dup_string (value); |
1569 |
|
break; |
1570 |
default: |
default: |
1571 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1572 |
break; |
break; |
1644 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1645 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
1646 |
break; |
break; |
1647 |
|
case PROP_MAP_SOURCE: |
1648 |
|
g_value_set_int(value, priv->map_source); |
1649 |
|
break; |
1650 |
|
case PROP_IMAGE_FORMAT: |
1651 |
|
g_value_set_string(value, priv->image_format); |
1652 |
|
break; |
1653 |
default: |
default: |
1654 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1655 |
break; |
break; |
1657 |
} |
} |
1658 |
|
|
1659 |
static gboolean |
static gboolean |
1660 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
1661 |
{ |
{ |
1662 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
1663 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1863 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
1864 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
1865 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
1866 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
1867 |
|
|
1868 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1869 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
1901 |
PROP_REPO_URI, |
PROP_REPO_URI, |
1902 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
1903 |
"repo uri", |
"repo uri", |
1904 |
"osm repo uri", |
"map source tile repository uri", |
1905 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
1906 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1907 |
|
|
1908 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1909 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
1910 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
1911 |
"proxy uri", |
"proxy uri", |
1918 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
1919 |
"tile cache", |
"tile cache", |
1920 |
"osm local tile cache dir", |
"osm local tile cache dir", |
1921 |
"/tmp/Maps", |
NULL, |
1922 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1923 |
|
|
1924 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1946 |
"maximum zoom level", |
"maximum zoom level", |
1947 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
1948 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
1949 |
17, |
OSM_MAX_ZOOM, |
1950 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1951 |
|
|
1952 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1956 |
"minimum zoom level", |
"minimum zoom level", |
1957 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
1958 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
1959 |
1, |
OSM_MIN_ZOOM, |
1960 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1961 |
|
|
1962 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2039 |
20, |
20, |
2040 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2041 |
|
|
2042 |
|
g_object_class_install_property (object_class, |
2043 |
|
PROP_MAP_SOURCE, |
2044 |
|
g_param_spec_int ("map-source", |
2045 |
|
"map source", |
2046 |
|
"map source ID", |
2047 |
|
-1, /* minimum property value */ |
2048 |
|
G_MAXINT, /* maximum property value */ |
2049 |
|
-1, |
2050 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2051 |
|
|
2052 |
|
g_object_class_install_property (object_class, |
2053 |
|
PROP_IMAGE_FORMAT, |
2054 |
|
g_param_spec_string ("image-format", |
2055 |
|
"image format", |
2056 |
|
"map source tile repository image format (jpg, png)", |
2057 |
|
OSM_IMAGE_FORMAT, |
2058 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2059 |
|
} |
2060 |
|
|
2061 |
|
const char* |
2062 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2063 |
|
{ |
2064 |
|
switch(source) |
2065 |
|
{ |
2066 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2067 |
|
return "None"; |
2068 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2069 |
|
return "OpenStreetMap"; |
2070 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2071 |
|
return "OpenStreetMap Renderer"; |
2072 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2073 |
|
return "OpenAerialMap"; |
2074 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2075 |
|
return "Maps-For-Free"; |
2076 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2077 |
|
return "Google Maps"; |
2078 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2079 |
|
return "Google Satellite"; |
2080 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2081 |
|
return "Google Hybrid"; |
2082 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2083 |
|
return "Virtual Earth"; |
2084 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2085 |
|
return "Virtual Earth Satellite"; |
2086 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2087 |
|
return "Virtual Earth Hybrid"; |
2088 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2089 |
|
return "Yahoo Maps"; |
2090 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2091 |
|
return "Yahoo Satellite"; |
2092 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2093 |
|
return "Yahoo Hybrid"; |
2094 |
|
default: |
2095 |
|
return NULL; |
2096 |
|
} |
2097 |
|
return NULL; |
2098 |
|
} |
2099 |
|
|
2100 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2101 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2102 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2103 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2104 |
|
const char* |
2105 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2106 |
|
{ |
2107 |
|
switch(source) |
2108 |
|
{ |
2109 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2110 |
|
return "none://"; |
2111 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2112 |
|
return OSM_REPO_URI; |
2113 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2114 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2115 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2116 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2117 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2118 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2119 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2120 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2121 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2122 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2123 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2124 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2125 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2126 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2127 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2128 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2129 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2130 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2131 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2132 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2133 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2134 |
|
/* TODO: Implement signed Y, aka U |
2135 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2136 |
|
* x = tilex, |
2137 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2138 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2139 |
|
*/ |
2140 |
|
return NULL; |
2141 |
|
default: |
2142 |
|
return NULL; |
2143 |
|
} |
2144 |
|
return NULL; |
2145 |
|
} |
2146 |
|
|
2147 |
|
const char * |
2148 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2149 |
|
{ |
2150 |
|
switch(source) { |
2151 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2152 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2153 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2154 |
|
return "png"; |
2155 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2156 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2157 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2158 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2159 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2160 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2161 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2162 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2163 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2164 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2165 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2166 |
|
return "jpg"; |
2167 |
|
default: |
2168 |
|
return "bin"; |
2169 |
|
} |
2170 |
|
return "bin"; |
2171 |
|
} |
2172 |
|
|
2173 |
|
|
2174 |
|
int |
2175 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2176 |
|
{ |
2177 |
|
return 1; |
2178 |
|
} |
2179 |
|
|
2180 |
|
int |
2181 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2182 |
|
{ |
2183 |
|
switch(source) { |
2184 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2185 |
|
return 18; |
2186 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2187 |
|
return OSM_MAX_ZOOM; |
2188 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2189 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2190 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2191 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2192 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2193 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2194 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2195 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2196 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2197 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2198 |
|
return 17; |
2199 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2200 |
|
return 11; |
2201 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2202 |
|
return 18; |
2203 |
|
default: |
2204 |
|
return 17; |
2205 |
|
} |
2206 |
|
return 17; |
2207 |
} |
} |
2208 |
|
|
2209 |
void |
void |
2236 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2237 |
{ |
{ |
2238 |
// x = i, y = j |
// x = i, y = j |
2239 |
filename = g_strdup_printf("%s/%u/%u/%u.png", priv->cache_dir, zoom, i, j); |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
2240 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2241 |
|
zoom, G_DIR_SEPARATOR, |
2242 |
|
i, G_DIR_SEPARATOR, |
2243 |
|
j, |
2244 |
|
priv->image_format); |
2245 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2246 |
{ |
{ |
2247 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2248 |
num_tiles++; |
num_tiles++; |
2304 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2305 |
{ |
{ |
2306 |
int zoom_old; |
int zoom_old; |
2307 |
double factor = 1.0; |
double factor = 0.0; |
2308 |
int width_center, height_center; |
int width_center, height_center; |
2309 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2310 |
|
|
2375 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
2376 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
2377 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
2378 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
2379 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
2380 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
2381 |
|
|
2388 |
} |
} |
2389 |
} |
} |
2390 |
|
|
2391 |
|
gboolean |
2392 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
2393 |
|
{ |
2394 |
|
OsmGpsMapPrivate *priv = map->priv; |
2395 |
|
if (priv->images) { |
2396 |
|
GSList *list; |
2397 |
|
for(list = priv->images; list != NULL; list = list->next) |
2398 |
|
{ |
2399 |
|
image_t *im = list->data; |
2400 |
|
if (im->image == image) |
2401 |
|
{ |
2402 |
|
priv->images = g_slist_remove_link(priv->images, list); |
2403 |
|
g_object_unref(im->image); |
2404 |
|
g_free(im); |
2405 |
|
osm_gps_map_map_redraw_idle(map); |
2406 |
|
return TRUE; |
2407 |
|
} |
2408 |
|
} |
2409 |
|
} |
2410 |
|
return FALSE; |
2411 |
|
} |
2412 |
|
|
2413 |
void |
void |
2414 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
2415 |
{ |
{ |
2601 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
2602 |
} |
} |
2603 |
|
|
2604 |
|
float |
2605 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
2606 |
|
{ |
2607 |
|
OsmGpsMapPrivate *priv; |
2608 |
|
|
2609 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
2610 |
|
priv = map->priv; |
2611 |
|
|
2612 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
2613 |
|
} |
2614 |
|
|