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 |
638 |
{ |
{ |
639 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
640 |
|
|
641 |
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); |
|
642 |
|
|
643 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
644 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
670 |
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) |
671 |
#endif |
#endif |
672 |
{ |
{ |
673 |
int fd; |
FILE *file; |
674 |
tile_download_t *dl = (tile_download_t *)user_data; |
tile_download_t *dl = (tile_download_t *)user_data; |
675 |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
676 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
683 |
{ |
{ |
684 |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
685 |
{ |
{ |
686 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
file = g_fopen(dl->filename, "wb"); |
687 |
if (fd != -1) |
if (file != NULL) |
688 |
{ |
{ |
689 |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file); |
690 |
file_saved = TRUE; |
file_saved = TRUE; |
691 |
|
g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
692 |
|
fclose (file); |
693 |
|
|
|
g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
|
|
close (fd); |
|
694 |
} |
} |
695 |
} |
} |
696 |
else |
else |
703 |
{ |
{ |
704 |
GdkPixbuf *pixbuf = NULL; |
GdkPixbuf *pixbuf = NULL; |
705 |
|
|
706 |
|
/* if the file was actually stored on disk, we can simply */ |
707 |
|
/* load and decode it from that file */ |
708 |
if (priv->cache_dir) |
if (priv->cache_dir) |
709 |
{ |
{ |
710 |
if (file_saved) |
if (file_saved) |
738 |
g_warning("Error: Unable to determine image file format"); |
g_warning("Error: Unable to determine image file format"); |
739 |
} |
} |
740 |
} |
} |
741 |
|
|
742 |
/* Store the tile into the cache */ |
/* Store the tile into the cache */ |
743 |
if (G_LIKELY (pixbuf)) |
if (G_LIKELY (pixbuf)) |
744 |
{ |
{ |
753 |
* we are using it as a key in the hash table */ |
* we are using it as a key in the hash table */ |
754 |
dl->filename = NULL; |
dl->filename = NULL; |
755 |
} |
} |
|
|
|
756 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
757 |
} |
} |
758 |
g_hash_table_remove(priv->tile_queue, dl->uri); |
g_hash_table_remove(priv->tile_queue, dl->uri); |
811 |
g_free(dl->uri); |
g_free(dl->uri); |
812 |
g_free(dl); |
g_free(dl); |
813 |
} else { |
} else { |
814 |
dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x); |
dl->folder = g_strdup_printf("%s%c%d%c%d%c", |
815 |
dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y); |
priv->cache_dir, G_DIR_SEPARATOR, |
816 |
|
zoom, G_DIR_SEPARATOR, |
817 |
|
x, G_DIR_SEPARATOR); |
818 |
|
dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
819 |
|
priv->cache_dir, G_DIR_SEPARATOR, |
820 |
|
zoom, G_DIR_SEPARATOR, |
821 |
|
x, G_DIR_SEPARATOR, |
822 |
|
y, |
823 |
|
priv->image_format); |
824 |
dl->map = map; |
dl->map = map; |
825 |
dl->redraw = redraw; |
dl->redraw = redraw; |
826 |
|
|
838 |
if (cookie) { |
if (cookie) { |
839 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
840 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
|
|
|
841 |
} |
} |
842 |
} |
} |
843 |
} |
} |
859 |
{ |
{ |
860 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
861 |
gchar *filename; |
gchar *filename; |
862 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf = NULL; |
863 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
864 |
|
|
865 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
866 |
priv->cache_dir, |
priv->cache_dir, G_DIR_SEPARATOR, |
867 |
zoom, x, y); |
zoom, G_DIR_SEPARATOR, |
868 |
|
x, G_DIR_SEPARATOR, |
869 |
|
y, |
870 |
|
priv->image_format); |
871 |
|
|
872 |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
873 |
if (tile) |
if (tile) |
874 |
{ |
{ |
875 |
g_free (filename); |
g_free (filename); |
876 |
} |
} |
877 |
else if (priv->cache_dir) |
else |
878 |
{ |
{ |
879 |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
880 |
if (pixbuf) |
if (pixbuf) |
890 |
{ |
{ |
891 |
tile->redraw_cycle = priv->redraw_cycle; |
tile->redraw_cycle = priv->redraw_cycle; |
892 |
pixbuf = g_object_ref (tile->pixbuf); |
pixbuf = g_object_ref (tile->pixbuf); |
893 |
} else |
} |
|
pixbuf = NULL; |
|
894 |
|
|
895 |
return pixbuf; |
return pixbuf; |
896 |
} |
} |
954 |
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) |
955 |
{ |
{ |
956 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
957 |
|
gchar *filename; |
958 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf; |
959 |
|
|
960 |
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); |
961 |
|
|
962 |
/* try to get file from internal cache */ |
if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) { |
963 |
pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y); |
osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y); |
964 |
|
return; |
965 |
|
} |
966 |
|
|
967 |
/* 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", |
968 |
if (priv->cache_dir && !pixbuf) |
priv->cache_dir, G_DIR_SEPARATOR, |
969 |
{ |
zoom, G_DIR_SEPARATOR, |
970 |
gchar *filename; |
x, G_DIR_SEPARATOR, |
971 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
y, |
972 |
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); |
|
|
} |
|
973 |
|
|
974 |
g_free(filename); |
/* try to get file from internal cache first */ |
975 |
} |
if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y))) |
976 |
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
977 |
|
|
978 |
if (G_LIKELY(pixbuf)) |
if(pixbuf) |
979 |
{ |
{ |
980 |
|
g_debug("Found tile %s", filename); |
981 |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
982 |
g_object_unref (pixbuf); |
g_object_unref (pixbuf); |
983 |
} |
} |
1008 |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
1009 |
} |
} |
1010 |
} |
} |
1011 |
|
g_free(filename); |
1012 |
} |
} |
1013 |
|
|
1014 |
static void |
static void |
1102 |
|
|
1103 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
1104 |
map_y0 = priv->map_y - EXTRA_BORDER; |
map_y0 = priv->map_y - EXTRA_BORDER; |
|
|
|
1105 |
for(list = trackpoint_list; list != NULL; list = list->next) |
for(list = trackpoint_list; list != NULL; list = list->next) |
1106 |
{ |
{ |
1107 |
coord_t *tp = list->data; |
coord_t *tp = list->data; |
1156 |
|
|
1157 |
if (priv->show_trip_history) |
if (priv->show_trip_history) |
1158 |
osm_gps_map_print_track (map, priv->trip_history); |
osm_gps_map_print_track (map, priv->trip_history); |
1159 |
|
|
1160 |
if (priv->tracks) |
if (priv->tracks) |
1161 |
{ |
{ |
|
g_debug("TRACK"); |
|
1162 |
GSList* tmp = priv->tracks; |
GSList* tmp = priv->tracks; |
1163 |
while (tmp != NULL) |
while (tmp != NULL) |
1164 |
{ |
{ |
1168 |
} |
} |
1169 |
} |
} |
1170 |
|
|
1171 |
static gboolean |
static gboolean |
1172 |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
1173 |
{ |
{ |
1174 |
return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
1175 |
} |
} |
1176 |
|
|
1177 |
static void |
static void |
1178 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1179 |
{ |
{ |
1180 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1181 |
|
|
1182 |
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) |
1183 |
return; |
return; |
1184 |
|
|
1185 |
/* 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 |
1186 |
* during the last redraw operation */ |
* during the last redraw operation */ |
1187 |
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); |
1188 |
} |
} |
1189 |
|
|
1190 |
static gboolean |
static gboolean |
1260 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1261 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1262 |
|
|
1263 |
|
priv->map_source = -1; |
1264 |
|
|
1265 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1266 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1267 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1315 |
{ |
{ |
1316 |
GObject *object; |
GObject *object; |
1317 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1318 |
|
OsmGpsMap *map; |
1319 |
|
const char *uri; |
1320 |
|
|
1321 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1322 |
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); |
1323 |
|
map = OSM_GPS_MAP(object); |
1324 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1325 |
|
|
1326 |
|
//user can specify a map source ID, or a repo URI as the map source |
1327 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1328 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1329 |
|
g_debug("Using null source"); |
1330 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1331 |
|
|
1332 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1333 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1334 |
|
} |
1335 |
|
else if (priv->map_source >= 0) { |
1336 |
|
//check if the source given is valid |
1337 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1338 |
|
if (uri) { |
1339 |
|
g_debug("Setting map source from ID"); |
1340 |
|
g_free(priv->repo_uri); |
1341 |
|
|
1342 |
|
priv->repo_uri = g_strdup(uri); |
1343 |
|
priv->image_format = g_strdup( |
1344 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1345 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1346 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1347 |
|
} |
1348 |
|
} |
1349 |
|
|
1350 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1351 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1352 |
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); |
1357 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1358 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1359 |
//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 |
1360 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1361 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1362 |
g_free(old); |
g_free(old); |
1363 |
|
} else { |
1364 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1365 |
|
priv->cache_dir = g_strdup(md5); |
1366 |
} |
} |
1367 |
|
|
1368 |
g_free(md5); |
g_free(md5); |
1369 |
} |
} |
1370 |
|
|
1371 |
|
inspect_map_uri(map); |
1372 |
|
|
1373 |
return object; |
return object; |
1374 |
} |
} |
1375 |
|
|
1396 |
if(priv->pixmap) |
if(priv->pixmap) |
1397 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1398 |
|
|
1399 |
|
if (priv->null_tile) |
1400 |
|
g_object_unref (priv->null_tile); |
1401 |
|
|
1402 |
if(priv->gc_map) |
if(priv->gc_map) |
1403 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1404 |
|
|
1416 |
|
|
1417 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
1418 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
1419 |
|
g_free(priv->image_format); |
1420 |
|
|
1421 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
1422 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
1447 |
break; |
break; |
1448 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
1449 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
1450 |
break; |
break; |
1451 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1452 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
1453 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1454 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
1455 |
|
|
1456 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1457 |
GValue val = {0}; |
GValue val = {0}; |
1458 |
|
|
1459 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1460 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1461 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1465 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
1466 |
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); |
1467 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
1468 |
} else |
} else |
1469 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1470 |
|
|
1471 |
break; |
break; |
1472 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
1473 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
1474 |
|
priv->cache_dir = g_value_dup_string (value); |
1475 |
break; |
break; |
1476 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
1477 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
1502 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1503 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
1504 |
break; |
break; |
1505 |
|
case PROP_MAP_SOURCE: |
1506 |
|
priv->map_source = g_value_get_int (value); |
1507 |
|
break; |
1508 |
|
case PROP_IMAGE_FORMAT: |
1509 |
|
priv->image_format = g_value_dup_string (value); |
1510 |
|
break; |
1511 |
default: |
default: |
1512 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1513 |
break; |
break; |
1585 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1586 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
1587 |
break; |
break; |
1588 |
|
case PROP_MAP_SOURCE: |
1589 |
|
g_value_set_int(value, priv->map_source); |
1590 |
|
break; |
1591 |
|
case PROP_IMAGE_FORMAT: |
1592 |
|
g_value_set_string(value, priv->image_format); |
1593 |
|
break; |
1594 |
default: |
default: |
1595 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1596 |
break; |
break; |
1598 |
} |
} |
1599 |
|
|
1600 |
static gboolean |
static gboolean |
1601 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
1602 |
{ |
{ |
1603 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
1604 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1804 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
1805 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
1806 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
1807 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
1808 |
|
|
1809 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1810 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
1842 |
PROP_REPO_URI, |
PROP_REPO_URI, |
1843 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
1844 |
"repo uri", |
"repo uri", |
1845 |
"osm repo uri", |
"map source tile repository uri", |
1846 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
1847 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1848 |
|
|
1849 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1850 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
1851 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
1852 |
"proxy uri", |
"proxy uri", |
1859 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
1860 |
"tile cache", |
"tile cache", |
1861 |
"osm local tile cache dir", |
"osm local tile cache dir", |
1862 |
"/tmp/Maps", |
NULL, |
1863 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1864 |
|
|
1865 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1887 |
"maximum zoom level", |
"maximum zoom level", |
1888 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
1889 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
1890 |
17, |
OSM_MAX_ZOOM, |
1891 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1892 |
|
|
1893 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1897 |
"minimum zoom level", |
"minimum zoom level", |
1898 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
1899 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
1900 |
1, |
OSM_MIN_ZOOM, |
1901 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1902 |
|
|
1903 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
1980 |
20, |
20, |
1981 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
1982 |
|
|
1983 |
|
g_object_class_install_property (object_class, |
1984 |
|
PROP_MAP_SOURCE, |
1985 |
|
g_param_spec_int ("map-source", |
1986 |
|
"map source", |
1987 |
|
"map source ID", |
1988 |
|
-1, /* minimum property value */ |
1989 |
|
G_MAXINT, /* maximum property value */ |
1990 |
|
-1, |
1991 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
1992 |
|
|
1993 |
|
g_object_class_install_property (object_class, |
1994 |
|
PROP_IMAGE_FORMAT, |
1995 |
|
g_param_spec_string ("image-format", |
1996 |
|
"image format", |
1997 |
|
"map source tile repository image format (jpg, png)", |
1998 |
|
OSM_IMAGE_FORMAT, |
1999 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2000 |
|
} |
2001 |
|
|
2002 |
|
const char* |
2003 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2004 |
|
{ |
2005 |
|
switch(source) |
2006 |
|
{ |
2007 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2008 |
|
return "None"; |
2009 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2010 |
|
return "OpenStreetMap"; |
2011 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2012 |
|
return "OpenStreetMap Renderer"; |
2013 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2014 |
|
return "OpenAerialMap"; |
2015 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2016 |
|
return "Maps-For-Free"; |
2017 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2018 |
|
return "Google Maps"; |
2019 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2020 |
|
return "Google Satellite"; |
2021 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2022 |
|
return "Google Hybrid"; |
2023 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2024 |
|
return "Virtual Earth"; |
2025 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2026 |
|
return "Virtual Earth Satellite"; |
2027 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2028 |
|
return "Virtual Earth Hybrid"; |
2029 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2030 |
|
return "Yahoo Maps"; |
2031 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2032 |
|
return "Yahoo Satellite"; |
2033 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2034 |
|
return "Yahoo Hybrid"; |
2035 |
|
default: |
2036 |
|
return NULL; |
2037 |
|
} |
2038 |
|
return NULL; |
2039 |
|
} |
2040 |
|
|
2041 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2042 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2043 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2044 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2045 |
|
const char* |
2046 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2047 |
|
{ |
2048 |
|
switch(source) |
2049 |
|
{ |
2050 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2051 |
|
return "none://"; |
2052 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2053 |
|
return OSM_REPO_URI; |
2054 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2055 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2056 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2057 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2058 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2059 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2060 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2061 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2062 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2063 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2064 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2065 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2066 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2067 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2068 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2069 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2070 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2071 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2072 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2073 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2074 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2075 |
|
/* TODO: Implement signed Y, aka U |
2076 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2077 |
|
* x = tilex, |
2078 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2079 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2080 |
|
*/ |
2081 |
|
return NULL; |
2082 |
|
default: |
2083 |
|
return NULL; |
2084 |
|
} |
2085 |
|
return NULL; |
2086 |
|
} |
2087 |
|
|
2088 |
|
const char * |
2089 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2090 |
|
{ |
2091 |
|
switch(source) { |
2092 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2093 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2094 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2095 |
|
return "png"; |
2096 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2097 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2098 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2099 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2100 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2101 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2102 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2103 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2104 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2105 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2106 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2107 |
|
return "jpg"; |
2108 |
|
default: |
2109 |
|
return "bin"; |
2110 |
|
} |
2111 |
|
return "bin"; |
2112 |
|
} |
2113 |
|
|
2114 |
|
|
2115 |
|
int |
2116 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2117 |
|
{ |
2118 |
|
return 1; |
2119 |
|
} |
2120 |
|
|
2121 |
|
int |
2122 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2123 |
|
{ |
2124 |
|
switch(source) { |
2125 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2126 |
|
return 18; |
2127 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2128 |
|
return OSM_MAX_ZOOM; |
2129 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2130 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2131 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2132 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2133 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2134 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2135 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2136 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2137 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2138 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2139 |
|
return 17; |
2140 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2141 |
|
return 11; |
2142 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2143 |
|
return 18; |
2144 |
|
default: |
2145 |
|
return 17; |
2146 |
|
} |
2147 |
|
return 17; |
2148 |
} |
} |
2149 |
|
|
2150 |
void |
void |
2177 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2178 |
{ |
{ |
2179 |
// x = i, y = j |
// x = i, y = j |
2180 |
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", |
2181 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2182 |
|
zoom, G_DIR_SEPARATOR, |
2183 |
|
i, G_DIR_SEPARATOR, |
2184 |
|
j, |
2185 |
|
priv->image_format); |
2186 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2187 |
{ |
{ |
2188 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2189 |
num_tiles++; |
num_tiles++; |
2245 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2246 |
{ |
{ |
2247 |
int zoom_old; |
int zoom_old; |
2248 |
double factor = 1.0; |
double factor = 0.0; |
2249 |
int width_center, height_center; |
int width_center, height_center; |
2250 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2251 |
|
|
2316 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
2317 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
2318 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
2319 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
2320 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
2321 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
2322 |
|
|
2329 |
} |
} |
2330 |
} |
} |
2331 |
|
|
2332 |
|
gboolean |
2333 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
2334 |
|
{ |
2335 |
|
OsmGpsMapPrivate *priv = map->priv; |
2336 |
|
if (priv->images) { |
2337 |
|
GSList *list; |
2338 |
|
for(list = priv->images; list != NULL; list = list->next) |
2339 |
|
{ |
2340 |
|
image_t *im = list->data; |
2341 |
|
if (im->image == image) |
2342 |
|
{ |
2343 |
|
priv->images = g_slist_remove_link(priv->images, list); |
2344 |
|
g_object_unref(im->image); |
2345 |
|
g_free(im); |
2346 |
|
osm_gps_map_map_redraw_idle(map); |
2347 |
|
return TRUE; |
2348 |
|
} |
2349 |
|
} |
2350 |
|
} |
2351 |
|
return FALSE; |
2352 |
|
} |
2353 |
|
|
2354 |
void |
void |
2355 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
2356 |
{ |
{ |
2542 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
2543 |
} |
} |
2544 |
|
|
2545 |
|
float |
2546 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
2547 |
|
{ |
2548 |
|
OsmGpsMapPrivate *priv; |
2549 |
|
|
2550 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
2551 |
|
priv = map->priv; |
2552 |
|
|
2553 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
2554 |
|
} |
2555 |
|
|