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; |
98 |
coord_t *gps; |
coord_t *gps; |
99 |
gboolean gps_valid; |
gboolean gps_valid; |
100 |
|
|
101 |
|
//a balloon with additional info |
102 |
|
struct { |
103 |
|
coord_t *coo; |
104 |
|
gboolean valid; |
105 |
|
OsmGpsMapRect_t rect; |
106 |
|
OsmGpsMapBalloonCallback cb; |
107 |
|
gpointer data; |
108 |
|
} balloon; |
109 |
|
|
110 |
//additional images or tracks added to the map |
//additional images or tracks added to the map |
111 |
GSList *tracks; |
GSList *tracks; |
112 |
GSList *images; |
GSList *images; |
116 |
GdkGC *gc_map; |
GdkGC *gc_map; |
117 |
|
|
118 |
//The tile painted when one cannot be found |
//The tile painted when one cannot be found |
119 |
//GdkPixbuf *missing_tile; |
GdkPixbuf *null_tile; |
120 |
|
|
121 |
//For tracking click and drag |
//For tracking click and drag |
122 |
int drag_counter; |
int drag_counter; |
169 |
PROP_TILES_QUEUED, |
PROP_TILES_QUEUED, |
170 |
PROP_GPS_TRACK_WIDTH, |
PROP_GPS_TRACK_WIDTH, |
171 |
PROP_GPS_POINT_R1, |
PROP_GPS_POINT_R1, |
172 |
PROP_GPS_POINT_R2 |
PROP_GPS_POINT_R2, |
173 |
|
PROP_MAP_SOURCE, |
174 |
|
PROP_IMAGE_FORMAT |
175 |
}; |
}; |
176 |
|
|
177 |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
185 |
static void osm_gps_map_print_images (OsmGpsMap *map); |
static void osm_gps_map_print_images (OsmGpsMap *map); |
186 |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
187 |
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); |
188 |
|
#ifdef LIBSOUP22 |
189 |
|
static void osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data); |
190 |
|
#else |
191 |
|
static void osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data); |
192 |
|
#endif |
193 |
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); |
194 |
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); |
195 |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
439 |
g_log_default_handler (log_domain, log_level, message, user_data); |
g_log_default_handler (log_domain, log_level, message, user_data); |
440 |
} |
} |
441 |
|
|
442 |
|
static float |
443 |
|
osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon) |
444 |
|
{ |
445 |
|
/* world at zoom 1 == 512 pixels */ |
446 |
|
return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom)); |
447 |
|
} |
448 |
|
|
449 |
/* clears the trip list and all resources */ |
/* clears the trip list and all resources */ |
450 |
static void |
static void |
451 |
osm_gps_map_free_trip (OsmGpsMap *map) |
osm_gps_map_free_trip (OsmGpsMap *map) |
555 |
int x, y; |
int x, y; |
556 |
int r = priv->ui_gps_point_inner_radius; |
int r = priv->ui_gps_point_inner_radius; |
557 |
int r2 = priv->ui_gps_point_outer_radius; |
int r2 = priv->ui_gps_point_outer_radius; |
558 |
|
// int lw = priv->ui_gps_track_width; |
559 |
int mr = MAX(r,r2); |
int mr = MAX(r,r2); |
560 |
|
|
561 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
566 |
cairo_t *cr; |
cairo_t *cr; |
567 |
cairo_pattern_t *pat; |
cairo_pattern_t *pat; |
568 |
#else |
#else |
|
int lw = priv->ui_gps_track_width; |
|
569 |
GdkColor color; |
GdkColor color; |
570 |
GdkGC *marker; |
GdkGC *marker; |
571 |
#endif |
#endif |
640 |
(mr*2)+lw+lw); |
(mr*2)+lw+lw); |
641 |
#endif |
#endif |
642 |
} |
} |
643 |
|
} |
644 |
|
|
645 |
|
/* most visual effects are hardcoded by now, but may be made */ |
646 |
|
/* available via properties later */ |
647 |
|
#define BALLOON_AREA_WIDTH 250 |
648 |
|
#define BALLOON_AREA_HEIGHT 75 |
649 |
|
|
650 |
|
#define BALLOON_CORNER_RADIUS 20 |
651 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/4) |
652 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
653 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
654 |
|
#define BALLOON_TRANSPARENCY 0.8 |
655 |
|
#define POINTER_HEIGHT 20 |
656 |
|
#define POINTER_FOOT_WIDTH 20 |
657 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
658 |
|
#define BALLOON_SHADOW 5 |
659 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
660 |
|
|
661 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS/3) |
662 |
|
|
663 |
|
|
664 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
665 |
|
/* for the shadow */ |
666 |
|
static void |
667 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
668 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
669 |
|
|
670 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
671 |
|
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0); |
672 |
|
if(!bottom) { |
673 |
|
/* insert top pointer */ |
674 |
|
cairo_line_to (cr, px1, y0); |
675 |
|
cairo_line_to (cr, px, py); |
676 |
|
cairo_line_to (cr, px0, y0); |
677 |
|
} |
678 |
|
|
679 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
680 |
|
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS); |
681 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
682 |
|
cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1); |
683 |
|
if(bottom) { |
684 |
|
/* insert bottom pointer */ |
685 |
|
cairo_line_to (cr, px0, y1); |
686 |
|
cairo_line_to (cr, px, py); |
687 |
|
cairo_line_to (cr, px1, y1); |
688 |
|
} |
689 |
|
|
690 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
691 |
|
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS); |
692 |
|
|
693 |
|
cairo_close_path (cr); |
694 |
|
} |
695 |
|
|
696 |
|
/* http://cairographics.org/samples/ */ |
697 |
|
static void |
698 |
|
osm_gps_map_draw_balloon_int (OsmGpsMap *map) |
699 |
|
{ |
700 |
|
OsmGpsMapPrivate *priv = map->priv; |
701 |
|
|
702 |
|
if (priv->balloon.valid) { |
703 |
|
|
704 |
|
/* ------- convert given coordinate into screen position --------- */ |
705 |
|
int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) - |
706 |
|
priv->map_x + EXTRA_BORDER; |
707 |
|
int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) - |
708 |
|
priv->map_y + EXTRA_BORDER; |
709 |
|
|
710 |
|
/* check position of this relative to screen center to determine */ |
711 |
|
/* pointer direction ... */ |
712 |
|
int pointer_x = x0, pointer_x0, pointer_x1; |
713 |
|
int pointer_y = y0; |
714 |
|
|
715 |
|
/* ... and calculate position */ |
716 |
|
if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) { |
717 |
|
x0 -= BALLOON_WIDTH - POINTER_OFFSET; |
718 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
719 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
720 |
|
} else { |
721 |
|
x0 -= POINTER_OFFSET; |
722 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
723 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
724 |
|
} |
725 |
|
|
726 |
|
gboolean bottom = FALSE; |
727 |
|
if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) { |
728 |
|
bottom = TRUE; |
729 |
|
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
730 |
|
} else |
731 |
|
y0 += POINTER_HEIGHT; |
732 |
|
|
733 |
|
/* calculate bottom/right of box */ |
734 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
735 |
|
|
736 |
|
/* save balloon screen coordinates for later use */ |
737 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
738 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
739 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
740 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
741 |
|
|
742 |
|
#ifdef USE_CAIRO |
743 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
744 |
|
|
745 |
|
/* --------- draw shadow --------------- */ |
746 |
|
osm_gps_map_draw_balloon_shape (cr, |
747 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
748 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
749 |
|
bottom, pointer_x, pointer_y, |
750 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
751 |
|
|
752 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
753 |
|
cairo_fill_preserve (cr); |
754 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
755 |
|
cairo_set_line_width (cr, 0); |
756 |
|
cairo_stroke (cr); |
757 |
|
|
758 |
|
/* --------- draw main shape ----------- */ |
759 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
760 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
761 |
|
|
762 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
763 |
|
cairo_fill_preserve (cr); |
764 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
765 |
|
cairo_set_line_width (cr, 1); |
766 |
|
cairo_stroke (cr); |
767 |
|
|
768 |
|
|
769 |
|
/* ---------- draw close button --------- */ |
770 |
|
|
771 |
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
772 |
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
773 |
|
int crad = CLOSE_BUTTON_RADIUS; |
774 |
|
|
775 |
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
776 |
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
777 |
|
cairo_fill_preserve (cr); |
778 |
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
779 |
|
cairo_set_line_width (cr, 2); |
780 |
|
cairo_stroke(cr); |
781 |
|
|
782 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
783 |
|
cairo_set_line_width (cr, 3); |
784 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
785 |
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
786 |
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
787 |
|
cairo_stroke (cr); |
788 |
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
789 |
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
790 |
|
cairo_stroke (cr); |
791 |
|
|
792 |
|
if (priv->balloon.cb) { |
793 |
|
/* clip in case application tries to draw in */ |
794 |
|
/* exceed of the balloon */ |
795 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
796 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
797 |
|
cairo_clip (cr); |
798 |
|
cairo_new_path (cr); /* current path is not |
799 |
|
consumed by cairo_clip() */ |
800 |
|
|
801 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
802 |
|
} |
803 |
|
|
804 |
|
gtk_widget_queue_draw_area (GTK_WIDGET(map), |
805 |
|
x0, y0, BALLOON_WIDTH, |
806 |
|
BALLOON_HEIGHT + POINTER_HEIGHT); |
807 |
|
#else |
808 |
|
#warning "Balloon display lacks a non-cairo implementation!" |
809 |
|
#endif |
810 |
|
} |
811 |
|
} |
812 |
|
|
813 |
|
/* the user clicked into the balloons main area. handle this */ |
814 |
|
static void |
815 |
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
816 |
|
{ |
817 |
|
OsmGpsMapPrivate *priv = map->priv; |
818 |
|
|
819 |
|
printf("clocked at %d %d\n", x, y); |
820 |
|
|
821 |
|
if (!priv->balloon.valid) |
822 |
|
return; |
823 |
|
|
824 |
|
/* check if the close button was clicked */ |
825 |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
826 |
|
(x < priv->balloon.rect.w) && |
827 |
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
828 |
|
|
829 |
|
priv->balloon.valid = FALSE; |
830 |
|
osm_gps_map_map_redraw_idle(map); |
831 |
|
} |
832 |
|
} |
833 |
|
|
834 |
|
/* return true if balloon is being displayed and if */ |
835 |
|
/* the given coordinate is within this balloon */ |
836 |
|
static gboolean |
837 |
|
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
838 |
|
{ |
839 |
|
return (priv->balloon.valid && |
840 |
|
(x > priv->balloon.rect.x) && |
841 |
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
842 |
|
(y > priv->balloon.rect.y) && |
843 |
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
844 |
} |
} |
845 |
|
|
846 |
static void |
static void |
848 |
{ |
{ |
849 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
850 |
|
|
851 |
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); |
|
852 |
|
|
853 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
854 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
880 |
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) |
881 |
#endif |
#endif |
882 |
{ |
{ |
883 |
int fd; |
FILE *file; |
884 |
tile_download_t *dl = (tile_download_t *)user_data; |
tile_download_t *dl = (tile_download_t *)user_data; |
885 |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
886 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
893 |
{ |
{ |
894 |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
895 |
{ |
{ |
896 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
file = g_fopen(dl->filename, "wb"); |
897 |
if (fd != -1) |
if (file != NULL) |
898 |
{ |
{ |
899 |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file); |
900 |
file_saved = TRUE; |
file_saved = TRUE; |
901 |
|
g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
902 |
|
fclose (file); |
903 |
|
|
|
g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
|
|
close (fd); |
|
904 |
} |
} |
905 |
} |
} |
906 |
else |
else |
913 |
{ |
{ |
914 |
GdkPixbuf *pixbuf = NULL; |
GdkPixbuf *pixbuf = NULL; |
915 |
|
|
916 |
|
/* if the file was actually stored on disk, we can simply */ |
917 |
|
/* load and decode it from that file */ |
918 |
if (priv->cache_dir) |
if (priv->cache_dir) |
919 |
{ |
{ |
920 |
if (file_saved) |
if (file_saved) |
948 |
g_warning("Error: Unable to determine image file format"); |
g_warning("Error: Unable to determine image file format"); |
949 |
} |
} |
950 |
} |
} |
951 |
|
|
952 |
/* Store the tile into the cache */ |
/* Store the tile into the cache */ |
953 |
if (G_LIKELY (pixbuf)) |
if (G_LIKELY (pixbuf)) |
954 |
{ |
{ |
963 |
* we are using it as a key in the hash table */ |
* we are using it as a key in the hash table */ |
964 |
dl->filename = NULL; |
dl->filename = NULL; |
965 |
} |
} |
|
|
|
966 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
967 |
} |
} |
968 |
g_hash_table_remove(priv->tile_queue, dl->uri); |
g_hash_table_remove(priv->tile_queue, dl->uri); |
1021 |
g_free(dl->uri); |
g_free(dl->uri); |
1022 |
g_free(dl); |
g_free(dl); |
1023 |
} else { |
} else { |
1024 |
dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x); |
dl->folder = g_strdup_printf("%s%c%d%c%d%c", |
1025 |
dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y); |
priv->cache_dir, G_DIR_SEPARATOR, |
1026 |
|
zoom, G_DIR_SEPARATOR, |
1027 |
|
x, G_DIR_SEPARATOR); |
1028 |
|
dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1029 |
|
priv->cache_dir, G_DIR_SEPARATOR, |
1030 |
|
zoom, G_DIR_SEPARATOR, |
1031 |
|
x, G_DIR_SEPARATOR, |
1032 |
|
y, |
1033 |
|
priv->image_format); |
1034 |
dl->map = map; |
dl->map = map; |
1035 |
dl->redraw = redraw; |
dl->redraw = redraw; |
1036 |
|
|
1048 |
if (cookie) { |
if (cookie) { |
1049 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
1050 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
|
|
|
1051 |
} |
} |
1052 |
} |
} |
1053 |
} |
} |
1069 |
{ |
{ |
1070 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1071 |
gchar *filename; |
gchar *filename; |
1072 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf = NULL; |
1073 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
1074 |
|
|
1075 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1076 |
priv->cache_dir, |
priv->cache_dir, G_DIR_SEPARATOR, |
1077 |
zoom, x, y); |
zoom, G_DIR_SEPARATOR, |
1078 |
|
x, G_DIR_SEPARATOR, |
1079 |
|
y, |
1080 |
|
priv->image_format); |
1081 |
|
|
1082 |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
1083 |
if (tile) |
if (tile) |
1084 |
{ |
{ |
1085 |
g_free (filename); |
g_free (filename); |
1086 |
} |
} |
1087 |
else if (priv->cache_dir) |
else |
1088 |
{ |
{ |
1089 |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1090 |
if (pixbuf) |
if (pixbuf) |
1100 |
{ |
{ |
1101 |
tile->redraw_cycle = priv->redraw_cycle; |
tile->redraw_cycle = priv->redraw_cycle; |
1102 |
pixbuf = g_object_ref (tile->pixbuf); |
pixbuf = g_object_ref (tile->pixbuf); |
1103 |
} else |
} |
|
pixbuf = NULL; |
|
1104 |
|
|
1105 |
return pixbuf; |
return pixbuf; |
1106 |
} |
} |
1164 |
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) |
1165 |
{ |
{ |
1166 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1167 |
|
gchar *filename; |
1168 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf; |
1169 |
|
|
1170 |
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); |
1171 |
|
|
1172 |
/* try to get file from internal cache */ |
if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) { |
1173 |
pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y); |
osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y); |
1174 |
|
return; |
1175 |
|
} |
1176 |
|
|
1177 |
/* 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", |
1178 |
if (priv->cache_dir && !pixbuf) |
priv->cache_dir, G_DIR_SEPARATOR, |
1179 |
{ |
zoom, G_DIR_SEPARATOR, |
1180 |
gchar *filename; |
x, G_DIR_SEPARATOR, |
1181 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
y, |
1182 |
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); |
|
|
} |
|
1183 |
|
|
1184 |
g_free(filename); |
/* try to get file from internal cache first */ |
1185 |
} |
if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y))) |
1186 |
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1187 |
|
|
1188 |
if (G_LIKELY(pixbuf)) |
if(pixbuf) |
1189 |
{ |
{ |
1190 |
|
g_debug("Found tile %s", filename); |
1191 |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
1192 |
g_object_unref (pixbuf); |
g_object_unref (pixbuf); |
1193 |
} |
} |
1218 |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
1219 |
} |
} |
1220 |
} |
} |
1221 |
|
g_free(filename); |
1222 |
} |
} |
1223 |
|
|
1224 |
static void |
static void |
1312 |
|
|
1313 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
1314 |
map_y0 = priv->map_y - EXTRA_BORDER; |
map_y0 = priv->map_y - EXTRA_BORDER; |
|
|
|
1315 |
for(list = trackpoint_list; list != NULL; list = list->next) |
for(list = trackpoint_list; list != NULL; list = list->next) |
1316 |
{ |
{ |
1317 |
coord_t *tp = list->data; |
coord_t *tp = list->data; |
1366 |
|
|
1367 |
if (priv->show_trip_history) |
if (priv->show_trip_history) |
1368 |
osm_gps_map_print_track (map, priv->trip_history); |
osm_gps_map_print_track (map, priv->trip_history); |
1369 |
|
|
1370 |
if (priv->tracks) |
if (priv->tracks) |
1371 |
{ |
{ |
|
g_debug("TRACK"); |
|
1372 |
GSList* tmp = priv->tracks; |
GSList* tmp = priv->tracks; |
1373 |
while (tmp != NULL) |
while (tmp != NULL) |
1374 |
{ |
{ |
1378 |
} |
} |
1379 |
} |
} |
1380 |
|
|
1381 |
static gboolean |
static gboolean |
1382 |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
1383 |
{ |
{ |
1384 |
return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
1385 |
} |
} |
1386 |
|
|
1387 |
static void |
static void |
1388 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1389 |
{ |
{ |
1390 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1391 |
|
|
1392 |
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) |
1393 |
return; |
return; |
1394 |
|
|
1395 |
/* 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 |
1396 |
* during the last redraw operation */ |
* during the last redraw operation */ |
1397 |
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); |
1398 |
} |
} |
1399 |
|
|
1400 |
static gboolean |
static gboolean |
1427 |
osm_gps_map_print_tracks(map); |
osm_gps_map_print_tracks(map); |
1428 |
osm_gps_map_draw_gps_point(map); |
osm_gps_map_draw_gps_point(map); |
1429 |
osm_gps_map_print_images(map); |
osm_gps_map_print_images(map); |
1430 |
|
osm_gps_map_draw_balloon_int(map); |
1431 |
|
|
1432 |
//osm_gps_map_osd_speed(map, 1.5); |
//osm_gps_map_osd_speed(map, 1.5); |
1433 |
osm_gps_map_purge_cache(map); |
osm_gps_map_purge_cache(map); |
1459 |
priv->gps = g_new0(coord_t, 1); |
priv->gps = g_new0(coord_t, 1); |
1460 |
priv->gps_valid = FALSE; |
priv->gps_valid = FALSE; |
1461 |
|
|
1462 |
|
priv->balloon.coo = g_new0(coord_t, 1); |
1463 |
|
priv->balloon.valid = FALSE; |
1464 |
|
priv->balloon.cb = NULL; |
1465 |
|
|
1466 |
priv->tracks = NULL; |
priv->tracks = NULL; |
1467 |
priv->images = NULL; |
priv->images = NULL; |
1468 |
|
|
1475 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1476 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1477 |
|
|
1478 |
|
priv->map_source = -1; |
1479 |
|
|
1480 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1481 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1482 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1530 |
{ |
{ |
1531 |
GObject *object; |
GObject *object; |
1532 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1533 |
|
OsmGpsMap *map; |
1534 |
|
const char *uri; |
1535 |
|
|
1536 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1537 |
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); |
1538 |
|
map = OSM_GPS_MAP(object); |
1539 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1540 |
|
|
1541 |
|
//user can specify a map source ID, or a repo URI as the map source |
1542 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1543 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1544 |
|
g_debug("Using null source"); |
1545 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1546 |
|
|
1547 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1548 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1549 |
|
} |
1550 |
|
else if (priv->map_source >= 0) { |
1551 |
|
//check if the source given is valid |
1552 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1553 |
|
if (uri) { |
1554 |
|
g_debug("Setting map source from ID"); |
1555 |
|
g_free(priv->repo_uri); |
1556 |
|
|
1557 |
|
priv->repo_uri = g_strdup(uri); |
1558 |
|
priv->image_format = g_strdup( |
1559 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1560 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1561 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1562 |
|
} |
1563 |
|
} |
1564 |
|
|
1565 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1566 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1567 |
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); |
1572 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1573 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1574 |
//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 |
1575 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1576 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1577 |
g_free(old); |
g_free(old); |
1578 |
|
} else { |
1579 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1580 |
|
priv->cache_dir = g_strdup(md5); |
1581 |
} |
} |
1582 |
|
|
1583 |
g_free(md5); |
g_free(md5); |
1584 |
} |
} |
1585 |
|
|
1586 |
|
inspect_map_uri(map); |
1587 |
|
|
1588 |
return object; |
return object; |
1589 |
} |
} |
1590 |
|
|
1611 |
if(priv->pixmap) |
if(priv->pixmap) |
1612 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1613 |
|
|
1614 |
|
if (priv->null_tile) |
1615 |
|
g_object_unref (priv->null_tile); |
1616 |
|
|
1617 |
if(priv->gc_map) |
if(priv->gc_map) |
1618 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1619 |
|
|
1620 |
if (priv->idle_map_redraw != 0) |
if (priv->idle_map_redraw != 0) |
1621 |
g_source_remove (priv->idle_map_redraw); |
g_source_remove (priv->idle_map_redraw); |
1622 |
|
|
1623 |
|
g_free(priv->gps); |
1624 |
|
g_free(priv->balloon.coo); |
1625 |
|
|
1626 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
1627 |
} |
} |
1628 |
|
|
1634 |
|
|
1635 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
1636 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
1637 |
|
g_free(priv->image_format); |
1638 |
|
|
1639 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
1640 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
1665 |
break; |
break; |
1666 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
1667 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
1668 |
break; |
break; |
1669 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1670 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
1671 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1672 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
1673 |
|
|
1674 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1675 |
GValue val = {0}; |
GValue val = {0}; |
1676 |
|
|
1677 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1678 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1679 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1683 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
1684 |
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); |
1685 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
1686 |
} else |
} else |
1687 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1688 |
|
|
1689 |
break; |
break; |
1690 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
1691 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
1692 |
|
priv->cache_dir = g_value_dup_string (value); |
1693 |
break; |
break; |
1694 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
1695 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
1720 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1721 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
1722 |
break; |
break; |
1723 |
|
case PROP_MAP_SOURCE: |
1724 |
|
priv->map_source = g_value_get_int (value); |
1725 |
|
break; |
1726 |
|
case PROP_IMAGE_FORMAT: |
1727 |
|
priv->image_format = g_value_dup_string (value); |
1728 |
|
break; |
1729 |
default: |
default: |
1730 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1731 |
break; |
break; |
1803 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1804 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
1805 |
break; |
break; |
1806 |
|
case PROP_MAP_SOURCE: |
1807 |
|
g_value_set_int(value, priv->map_source); |
1808 |
|
break; |
1809 |
|
case PROP_IMAGE_FORMAT: |
1810 |
|
g_value_set_string(value, priv->image_format); |
1811 |
|
break; |
1812 |
default: |
default: |
1813 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1814 |
break; |
break; |
1816 |
} |
} |
1817 |
|
|
1818 |
static gboolean |
static gboolean |
1819 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
1820 |
{ |
{ |
1821 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
1822 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1838 |
{ |
{ |
1839 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
1840 |
|
|
1841 |
|
/* don't drag if the user clicked within the balloon */ |
1842 |
|
if (osm_gps_map_in_balloon(priv, |
1843 |
|
event->x + EXTRA_BORDER, |
1844 |
|
event->y + EXTRA_BORDER)) |
1845 |
|
{ |
1846 |
|
priv->drag_counter = -1; |
1847 |
|
return FALSE; |
1848 |
|
} |
1849 |
|
|
1850 |
priv->drag_counter = 0; |
priv->drag_counter = 0; |
1851 |
priv->drag_start_mouse_x = (int) event->x; |
priv->drag_start_mouse_x = (int) event->x; |
1852 |
priv->drag_start_mouse_y = (int) event->y; |
priv->drag_start_mouse_y = (int) event->y; |
1861 |
{ |
{ |
1862 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
1863 |
|
|
1864 |
|
/* released inside the balloon? */ |
1865 |
|
if (osm_gps_map_in_balloon(priv, |
1866 |
|
event->x + EXTRA_BORDER, |
1867 |
|
event->y + EXTRA_BORDER)) |
1868 |
|
{ |
1869 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
1870 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
1871 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
1872 |
|
return FALSE; |
1873 |
|
} |
1874 |
|
|
1875 |
|
if (priv->drag_counter < 0) |
1876 |
|
return FALSE; |
1877 |
|
|
1878 |
if (priv->dragging) |
if (priv->dragging) |
1879 |
{ |
{ |
1880 |
priv->dragging = FALSE; |
priv->dragging = FALSE; |
1892 |
|
|
1893 |
priv->drag_mouse_dx = 0; |
priv->drag_mouse_dx = 0; |
1894 |
priv->drag_mouse_dy = 0; |
priv->drag_mouse_dy = 0; |
1895 |
priv->drag_counter = 0; |
priv->drag_counter = -1; |
1896 |
|
|
1897 |
return FALSE; |
return FALSE; |
1898 |
} |
} |
1917 |
if (!(state & GDK_BUTTON1_MASK)) |
if (!(state & GDK_BUTTON1_MASK)) |
1918 |
return FALSE; |
return FALSE; |
1919 |
|
|
1920 |
|
if (priv->drag_counter < 0) |
1921 |
|
return FALSE; |
1922 |
|
|
1923 |
priv->drag_counter++; |
priv->drag_counter++; |
1924 |
|
|
1925 |
// we havent dragged more than 6 pixels |
// we havent dragged more than 6 pixels |
2022 |
widget->window, |
widget->window, |
2023 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2024 |
priv->pixmap, |
priv->pixmap, |
2025 |
event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER, |
event->area.x + EXTRA_BORDER, |
2026 |
|
event->area.y + EXTRA_BORDER, |
2027 |
event->area.x, event->area.y, |
event->area.x, event->area.y, |
2028 |
event->area.width, event->area.height); |
event->area.width, event->area.height); |
2029 |
|
|
2049 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
2050 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
2051 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
2052 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
2053 |
|
|
2054 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2055 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
2087 |
PROP_REPO_URI, |
PROP_REPO_URI, |
2088 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
2089 |
"repo uri", |
"repo uri", |
2090 |
"osm repo uri", |
"map source tile repository uri", |
2091 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
2092 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2093 |
|
|
2094 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2095 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
2096 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
2097 |
"proxy uri", |
"proxy uri", |
2104 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
2105 |
"tile cache", |
"tile cache", |
2106 |
"osm local tile cache dir", |
"osm local tile cache dir", |
2107 |
"/tmp/Maps", |
NULL, |
2108 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2109 |
|
|
2110 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2132 |
"maximum zoom level", |
"maximum zoom level", |
2133 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2134 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2135 |
17, |
OSM_MAX_ZOOM, |
2136 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2137 |
|
|
2138 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2142 |
"minimum zoom level", |
"minimum zoom level", |
2143 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2144 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2145 |
1, |
OSM_MIN_ZOOM, |
2146 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2147 |
|
|
2148 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2225 |
20, |
20, |
2226 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2227 |
|
|
2228 |
|
g_object_class_install_property (object_class, |
2229 |
|
PROP_MAP_SOURCE, |
2230 |
|
g_param_spec_int ("map-source", |
2231 |
|
"map source", |
2232 |
|
"map source ID", |
2233 |
|
-1, /* minimum property value */ |
2234 |
|
G_MAXINT, /* maximum property value */ |
2235 |
|
-1, |
2236 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2237 |
|
|
2238 |
|
g_object_class_install_property (object_class, |
2239 |
|
PROP_IMAGE_FORMAT, |
2240 |
|
g_param_spec_string ("image-format", |
2241 |
|
"image format", |
2242 |
|
"map source tile repository image format (jpg, png)", |
2243 |
|
OSM_IMAGE_FORMAT, |
2244 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2245 |
|
} |
2246 |
|
|
2247 |
|
const char* |
2248 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2249 |
|
{ |
2250 |
|
switch(source) |
2251 |
|
{ |
2252 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2253 |
|
return "None"; |
2254 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2255 |
|
return "OpenStreetMap"; |
2256 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2257 |
|
return "OpenStreetMap Renderer"; |
2258 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2259 |
|
return "OpenAerialMap"; |
2260 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2261 |
|
return "Maps-For-Free"; |
2262 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2263 |
|
return "Google Maps"; |
2264 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2265 |
|
return "Google Satellite"; |
2266 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2267 |
|
return "Google Hybrid"; |
2268 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2269 |
|
return "Virtual Earth"; |
2270 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2271 |
|
return "Virtual Earth Satellite"; |
2272 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2273 |
|
return "Virtual Earth Hybrid"; |
2274 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2275 |
|
return "Yahoo Maps"; |
2276 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2277 |
|
return "Yahoo Satellite"; |
2278 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2279 |
|
return "Yahoo Hybrid"; |
2280 |
|
default: |
2281 |
|
return NULL; |
2282 |
|
} |
2283 |
|
return NULL; |
2284 |
|
} |
2285 |
|
|
2286 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2287 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2288 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2289 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2290 |
|
const char* |
2291 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2292 |
|
{ |
2293 |
|
switch(source) |
2294 |
|
{ |
2295 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2296 |
|
return "none://"; |
2297 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2298 |
|
return OSM_REPO_URI; |
2299 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2300 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2301 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2302 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2303 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2304 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2305 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2306 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2307 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2308 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2309 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2310 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2311 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2312 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2313 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2314 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2315 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2316 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2317 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2318 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2319 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2320 |
|
/* TODO: Implement signed Y, aka U |
2321 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2322 |
|
* x = tilex, |
2323 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2324 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2325 |
|
*/ |
2326 |
|
return NULL; |
2327 |
|
default: |
2328 |
|
return NULL; |
2329 |
|
} |
2330 |
|
return NULL; |
2331 |
|
} |
2332 |
|
|
2333 |
|
const char * |
2334 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2335 |
|
{ |
2336 |
|
switch(source) { |
2337 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2338 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2339 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2340 |
|
return "png"; |
2341 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2342 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2343 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2344 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2345 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2346 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2347 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2348 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2349 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2350 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2351 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2352 |
|
return "jpg"; |
2353 |
|
default: |
2354 |
|
return "bin"; |
2355 |
|
} |
2356 |
|
return "bin"; |
2357 |
|
} |
2358 |
|
|
2359 |
|
|
2360 |
|
int |
2361 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2362 |
|
{ |
2363 |
|
return 1; |
2364 |
|
} |
2365 |
|
|
2366 |
|
int |
2367 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2368 |
|
{ |
2369 |
|
switch(source) { |
2370 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2371 |
|
return 18; |
2372 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2373 |
|
return OSM_MAX_ZOOM; |
2374 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2375 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2376 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2377 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2378 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2379 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2380 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2381 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2382 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2383 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2384 |
|
return 17; |
2385 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2386 |
|
return 11; |
2387 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2388 |
|
return 18; |
2389 |
|
default: |
2390 |
|
return 17; |
2391 |
|
} |
2392 |
|
return 17; |
2393 |
} |
} |
2394 |
|
|
2395 |
void |
void |
2422 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2423 |
{ |
{ |
2424 |
// x = i, y = j |
// x = i, y = j |
2425 |
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", |
2426 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2427 |
|
zoom, G_DIR_SEPARATOR, |
2428 |
|
i, G_DIR_SEPARATOR, |
2429 |
|
j, |
2430 |
|
priv->image_format); |
2431 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2432 |
{ |
{ |
2433 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2434 |
num_tiles++; |
num_tiles++; |
2490 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2491 |
{ |
{ |
2492 |
int zoom_old; |
int zoom_old; |
2493 |
double factor = 1.0; |
double factor = 0.0; |
2494 |
int width_center, height_center; |
int width_center, height_center; |
2495 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2496 |
|
|
2561 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
2562 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
2563 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
2564 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
2565 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
2566 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
2567 |
|
|
2574 |
} |
} |
2575 |
} |
} |
2576 |
|
|
2577 |
|
gboolean |
2578 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
2579 |
|
{ |
2580 |
|
OsmGpsMapPrivate *priv = map->priv; |
2581 |
|
if (priv->images) { |
2582 |
|
GSList *list; |
2583 |
|
for(list = priv->images; list != NULL; list = list->next) |
2584 |
|
{ |
2585 |
|
image_t *im = list->data; |
2586 |
|
if (im->image == image) |
2587 |
|
{ |
2588 |
|
priv->images = g_slist_remove_link(priv->images, list); |
2589 |
|
g_object_unref(im->image); |
2590 |
|
g_free(im); |
2591 |
|
osm_gps_map_map_redraw_idle(map); |
2592 |
|
return TRUE; |
2593 |
|
} |
2594 |
|
} |
2595 |
|
} |
2596 |
|
return FALSE; |
2597 |
|
} |
2598 |
|
|
2599 |
void |
void |
2600 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
2601 |
{ |
{ |
2787 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
2788 |
} |
} |
2789 |
|
|
2790 |
|
float |
2791 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
2792 |
|
{ |
2793 |
|
OsmGpsMapPrivate *priv; |
2794 |
|
|
2795 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
2796 |
|
priv = map->priv; |
2797 |
|
|
2798 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
2799 |
|
} |
2800 |
|
|
2801 |
|
void |
2802 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
2803 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
2804 |
|
{ |
2805 |
|
OsmGpsMapPrivate *priv; |
2806 |
|
|
2807 |
|
/* remove and previously installed balloon */ |
2808 |
|
osm_gps_map_clear_balloon (map); |
2809 |
|
|
2810 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2811 |
|
priv = map->priv; |
2812 |
|
|
2813 |
|
priv->balloon.coo->rlat = deg2rad(latitude); |
2814 |
|
priv->balloon.coo->rlon = deg2rad(longitude); |
2815 |
|
priv->balloon.valid = TRUE; |
2816 |
|
|
2817 |
|
priv->balloon.cb = cb; |
2818 |
|
priv->balloon.data = data; |
2819 |
|
|
2820 |
|
// this redraws the map |
2821 |
|
osm_gps_map_map_redraw_idle(map); |
2822 |
|
} |
2823 |
|
|
2824 |
|
void |
2825 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
2826 |
|
{ |
2827 |
|
OsmGpsMapPrivate *priv; |
2828 |
|
|
2829 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2830 |
|
priv = map->priv; |
2831 |
|
|
2832 |
|
priv->balloon.valid = FALSE; |
2833 |
|
|
2834 |
|
osm_gps_map_map_redraw_idle(map); |
2835 |
|
} |