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 |
|
#ifdef ENABLE_BALLOON |
102 |
|
//a balloon with additional info |
103 |
|
struct { |
104 |
|
coord_t *coo; |
105 |
|
gboolean valid; |
106 |
|
OsmGpsMapRect_t rect; |
107 |
|
OsmGpsMapBalloonCallback cb; |
108 |
|
gpointer data; |
109 |
|
} balloon; |
110 |
|
#endif |
111 |
|
|
112 |
|
#ifdef ENABLE_OSD |
113 |
|
//the osd controls |
114 |
|
struct { |
115 |
|
GdkPixmap *backup; |
116 |
|
gint backup_x, backup_y; |
117 |
|
// GdkPixbuf *pixbuf; |
118 |
|
} osd; |
119 |
|
#endif |
120 |
|
|
121 |
//additional images or tracks added to the map |
//additional images or tracks added to the map |
122 |
GSList *tracks; |
GSList *tracks; |
123 |
GSList *images; |
GSList *images; |
127 |
GdkGC *gc_map; |
GdkGC *gc_map; |
128 |
|
|
129 |
//The tile painted when one cannot be found |
//The tile painted when one cannot be found |
130 |
//GdkPixbuf *missing_tile; |
GdkPixbuf *null_tile; |
131 |
|
|
132 |
//For tracking click and drag |
//For tracking click and drag |
133 |
int drag_counter; |
int drag_counter; |
180 |
PROP_TILES_QUEUED, |
PROP_TILES_QUEUED, |
181 |
PROP_GPS_TRACK_WIDTH, |
PROP_GPS_TRACK_WIDTH, |
182 |
PROP_GPS_POINT_R1, |
PROP_GPS_POINT_R1, |
183 |
PROP_GPS_POINT_R2 |
PROP_GPS_POINT_R2, |
184 |
|
PROP_MAP_SOURCE, |
185 |
|
PROP_IMAGE_FORMAT |
186 |
}; |
}; |
187 |
|
|
188 |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
196 |
static void osm_gps_map_print_images (OsmGpsMap *map); |
static void osm_gps_map_print_images (OsmGpsMap *map); |
197 |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
198 |
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); |
199 |
|
#ifdef LIBSOUP22 |
200 |
|
static void osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data); |
201 |
|
#else |
202 |
|
static void osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data); |
203 |
|
#endif |
204 |
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); |
205 |
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); |
206 |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
450 |
g_log_default_handler (log_domain, log_level, message, user_data); |
g_log_default_handler (log_domain, log_level, message, user_data); |
451 |
} |
} |
452 |
|
|
453 |
|
static float |
454 |
|
osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon) |
455 |
|
{ |
456 |
|
/* world at zoom 1 == 512 pixels */ |
457 |
|
return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom)); |
458 |
|
} |
459 |
|
|
460 |
/* clears the trip list and all resources */ |
/* clears the trip list and all resources */ |
461 |
static void |
static void |
462 |
osm_gps_map_free_trip (OsmGpsMap *map) |
osm_gps_map_free_trip (OsmGpsMap *map) |
566 |
int x, y; |
int x, y; |
567 |
int r = priv->ui_gps_point_inner_radius; |
int r = priv->ui_gps_point_inner_radius; |
568 |
int r2 = priv->ui_gps_point_outer_radius; |
int r2 = priv->ui_gps_point_outer_radius; |
569 |
|
// int lw = priv->ui_gps_track_width; |
570 |
int mr = MAX(r,r2); |
int mr = MAX(r,r2); |
571 |
|
|
572 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
577 |
cairo_t *cr; |
cairo_t *cr; |
578 |
cairo_pattern_t *pat; |
cairo_pattern_t *pat; |
579 |
#else |
#else |
|
int lw = priv->ui_gps_track_width; |
|
580 |
GdkColor color; |
GdkColor color; |
581 |
GdkGC *marker; |
GdkGC *marker; |
582 |
#endif |
#endif |
651 |
(mr*2)+lw+lw); |
(mr*2)+lw+lw); |
652 |
#endif |
#endif |
653 |
} |
} |
654 |
|
} |
655 |
|
|
656 |
|
#ifdef ENABLE_BALLOON |
657 |
|
/* most visual effects are hardcoded by now, but may be made */ |
658 |
|
/* available via properties later */ |
659 |
|
#ifndef BALLOON_AREA_WIDTH |
660 |
|
#define BALLOON_AREA_WIDTH 290 |
661 |
|
#endif |
662 |
|
#ifndef BALLOON_AREA_HEIGHT |
663 |
|
#define BALLOON_AREA_HEIGHT 75 |
664 |
|
#endif |
665 |
|
#ifndef BALLOON_CORNER_RADIUS |
666 |
|
#define BALLOON_CORNER_RADIUS 20 |
667 |
|
#endif |
668 |
|
|
669 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/4) |
670 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
671 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
672 |
|
#define BALLOON_TRANSPARENCY 0.8 |
673 |
|
#define POINTER_HEIGHT 20 |
674 |
|
#define POINTER_FOOT_WIDTH 20 |
675 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
676 |
|
#define BALLOON_SHADOW 5 |
677 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
678 |
|
|
679 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS/3) |
680 |
|
|
681 |
|
|
682 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
683 |
|
/* for the shadow */ |
684 |
|
static void |
685 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
686 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
687 |
|
|
688 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
689 |
|
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0); |
690 |
|
if(!bottom) { |
691 |
|
/* insert top pointer */ |
692 |
|
cairo_line_to (cr, px1, y0); |
693 |
|
cairo_line_to (cr, px, py); |
694 |
|
cairo_line_to (cr, px0, y0); |
695 |
|
} |
696 |
|
|
697 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
698 |
|
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS); |
699 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
700 |
|
cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1); |
701 |
|
if(bottom) { |
702 |
|
/* insert bottom pointer */ |
703 |
|
cairo_line_to (cr, px0, y1); |
704 |
|
cairo_line_to (cr, px, py); |
705 |
|
cairo_line_to (cr, px1, y1); |
706 |
|
} |
707 |
|
|
708 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
709 |
|
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS); |
710 |
|
|
711 |
|
cairo_close_path (cr); |
712 |
|
} |
713 |
|
|
714 |
|
static void |
715 |
|
osm_gps_map_draw_balloon_int (OsmGpsMap *map) |
716 |
|
{ |
717 |
|
OsmGpsMapPrivate *priv = map->priv; |
718 |
|
|
719 |
|
if (priv->balloon.valid) { |
720 |
|
|
721 |
|
/* ------- convert given coordinate into screen position --------- */ |
722 |
|
int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) - |
723 |
|
priv->map_x + EXTRA_BORDER; |
724 |
|
int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) - |
725 |
|
priv->map_y + EXTRA_BORDER; |
726 |
|
|
727 |
|
/* check position of this relative to screen center to determine */ |
728 |
|
/* pointer direction ... */ |
729 |
|
int pointer_x = x0, pointer_x0, pointer_x1; |
730 |
|
int pointer_y = y0; |
731 |
|
|
732 |
|
/* ... and calculate position */ |
733 |
|
if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) { |
734 |
|
x0 -= BALLOON_WIDTH - POINTER_OFFSET; |
735 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
736 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
737 |
|
} else { |
738 |
|
x0 -= POINTER_OFFSET; |
739 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
740 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
741 |
|
} |
742 |
|
|
743 |
|
gboolean bottom = FALSE; |
744 |
|
if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) { |
745 |
|
bottom = TRUE; |
746 |
|
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
747 |
|
} else |
748 |
|
y0 += POINTER_HEIGHT; |
749 |
|
|
750 |
|
/* calculate bottom/right of box */ |
751 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
752 |
|
|
753 |
|
/* save balloon screen coordinates for later use */ |
754 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
755 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
756 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
757 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
758 |
|
|
759 |
|
#ifdef USE_CAIRO |
760 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
761 |
|
|
762 |
|
/* --------- draw shadow --------------- */ |
763 |
|
osm_gps_map_draw_balloon_shape (cr, |
764 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
765 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
766 |
|
bottom, pointer_x, pointer_y, |
767 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
768 |
|
|
769 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
770 |
|
cairo_fill_preserve (cr); |
771 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
772 |
|
cairo_set_line_width (cr, 0); |
773 |
|
cairo_stroke (cr); |
774 |
|
|
775 |
|
/* --------- draw main shape ----------- */ |
776 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
777 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
778 |
|
|
779 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
780 |
|
cairo_fill_preserve (cr); |
781 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
782 |
|
cairo_set_line_width (cr, 1); |
783 |
|
cairo_stroke (cr); |
784 |
|
|
785 |
|
|
786 |
|
/* ---------- draw close button --------- */ |
787 |
|
|
788 |
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
789 |
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
790 |
|
int crad = CLOSE_BUTTON_RADIUS; |
791 |
|
|
792 |
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
793 |
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
794 |
|
cairo_fill_preserve (cr); |
795 |
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
796 |
|
cairo_set_line_width (cr, 2); |
797 |
|
cairo_stroke(cr); |
798 |
|
|
799 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
800 |
|
cairo_set_line_width (cr, 3); |
801 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
802 |
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
803 |
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
804 |
|
cairo_stroke (cr); |
805 |
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
806 |
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
807 |
|
cairo_stroke (cr); |
808 |
|
|
809 |
|
if (priv->balloon.cb) { |
810 |
|
/* clip in case application tries to draw in */ |
811 |
|
/* exceed of the balloon */ |
812 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
813 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
814 |
|
cairo_clip (cr); |
815 |
|
cairo_new_path (cr); /* current path is not |
816 |
|
consumed by cairo_clip() */ |
817 |
|
|
818 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
819 |
|
} |
820 |
|
|
821 |
|
cairo_destroy(cr); |
822 |
|
|
823 |
|
gtk_widget_queue_draw_area (GTK_WIDGET(map), |
824 |
|
x0, y0, BALLOON_WIDTH, |
825 |
|
BALLOON_HEIGHT + POINTER_HEIGHT); |
826 |
|
#else |
827 |
|
#warning "Balloon display lacks a non-cairo implementation!" |
828 |
|
#endif |
829 |
|
} |
830 |
|
} |
831 |
|
|
832 |
|
/* the user clicked into the balloons main area. handle this */ |
833 |
|
static void |
834 |
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
835 |
|
{ |
836 |
|
OsmGpsMapPrivate *priv = map->priv; |
837 |
|
|
838 |
|
if (!priv->balloon.valid) |
839 |
|
return; |
840 |
|
|
841 |
|
/* check if the close button was clicked */ |
842 |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
843 |
|
(x < priv->balloon.rect.w) && |
844 |
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
845 |
|
|
846 |
|
priv->balloon.valid = FALSE; |
847 |
|
osm_gps_map_map_redraw_idle(map); |
848 |
|
} |
849 |
} |
} |
850 |
|
|
851 |
|
/* return true if balloon is being displayed and if */ |
852 |
|
/* the given coordinate is within this balloon */ |
853 |
|
static gboolean |
854 |
|
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
855 |
|
{ |
856 |
|
return (priv->balloon.valid && |
857 |
|
(x > priv->balloon.rect.x) && |
858 |
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
859 |
|
(y > priv->balloon.rect.y) && |
860 |
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
861 |
|
} |
862 |
|
#endif // ENABLE_BALLOON |
863 |
|
|
864 |
static void |
static void |
865 |
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) |
866 |
{ |
{ |
867 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
868 |
|
|
869 |
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); |
|
870 |
|
|
871 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
872 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
898 |
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) |
899 |
#endif |
#endif |
900 |
{ |
{ |
901 |
int fd; |
FILE *file; |
902 |
tile_download_t *dl = (tile_download_t *)user_data; |
tile_download_t *dl = (tile_download_t *)user_data; |
903 |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
904 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
911 |
{ |
{ |
912 |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
913 |
{ |
{ |
914 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
file = g_fopen(dl->filename, "wb"); |
915 |
if (fd != -1) |
if (file != NULL) |
916 |
{ |
{ |
917 |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file); |
918 |
file_saved = TRUE; |
file_saved = TRUE; |
919 |
|
g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
920 |
|
fclose (file); |
921 |
|
|
|
g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
|
|
close (fd); |
|
922 |
} |
} |
923 |
} |
} |
924 |
else |
else |
925 |
{ |
{ |
926 |
g_warning("Error creating tile download directory: %s", dl->folder); |
g_warning("Error creating tile download directory: %s", |
927 |
|
dl->folder); |
928 |
|
perror("perror:"); |
929 |
} |
} |
930 |
} |
} |
931 |
|
|
933 |
{ |
{ |
934 |
GdkPixbuf *pixbuf = NULL; |
GdkPixbuf *pixbuf = NULL; |
935 |
|
|
936 |
|
/* if the file was actually stored on disk, we can simply */ |
937 |
|
/* load and decode it from that file */ |
938 |
if (priv->cache_dir) |
if (priv->cache_dir) |
939 |
{ |
{ |
940 |
if (file_saved) |
if (file_saved) |
968 |
g_warning("Error: Unable to determine image file format"); |
g_warning("Error: Unable to determine image file format"); |
969 |
} |
} |
970 |
} |
} |
971 |
|
|
972 |
/* Store the tile into the cache */ |
/* Store the tile into the cache */ |
973 |
if (G_LIKELY (pixbuf)) |
if (G_LIKELY (pixbuf)) |
974 |
{ |
{ |
983 |
* we are using it as a key in the hash table */ |
* we are using it as a key in the hash table */ |
984 |
dl->filename = NULL; |
dl->filename = NULL; |
985 |
} |
} |
|
|
|
986 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
987 |
} |
} |
988 |
g_hash_table_remove(priv->tile_queue, dl->uri); |
g_hash_table_remove(priv->tile_queue, dl->uri); |
1041 |
g_free(dl->uri); |
g_free(dl->uri); |
1042 |
g_free(dl); |
g_free(dl); |
1043 |
} else { |
} else { |
1044 |
dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x); |
dl->folder = g_strdup_printf("%s%c%d%c%d%c", |
1045 |
dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y); |
priv->cache_dir, G_DIR_SEPARATOR, |
1046 |
|
zoom, G_DIR_SEPARATOR, |
1047 |
|
x, G_DIR_SEPARATOR); |
1048 |
|
dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1049 |
|
priv->cache_dir, G_DIR_SEPARATOR, |
1050 |
|
zoom, G_DIR_SEPARATOR, |
1051 |
|
x, G_DIR_SEPARATOR, |
1052 |
|
y, |
1053 |
|
priv->image_format); |
1054 |
dl->map = map; |
dl->map = map; |
1055 |
dl->redraw = redraw; |
dl->redraw = redraw; |
1056 |
|
|
1068 |
if (cookie) { |
if (cookie) { |
1069 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
1070 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
|
|
|
1071 |
} |
} |
1072 |
} |
} |
1073 |
} |
} |
1089 |
{ |
{ |
1090 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1091 |
gchar *filename; |
gchar *filename; |
1092 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf = NULL; |
1093 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
1094 |
|
|
1095 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1096 |
priv->cache_dir, |
priv->cache_dir, G_DIR_SEPARATOR, |
1097 |
zoom, x, y); |
zoom, G_DIR_SEPARATOR, |
1098 |
|
x, G_DIR_SEPARATOR, |
1099 |
|
y, |
1100 |
|
priv->image_format); |
1101 |
|
|
1102 |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
1103 |
if (tile) |
if (tile) |
1104 |
{ |
{ |
1105 |
g_free (filename); |
g_free (filename); |
1106 |
} |
} |
1107 |
else if (priv->cache_dir) |
else |
1108 |
{ |
{ |
1109 |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1110 |
if (pixbuf) |
if (pixbuf) |
1120 |
{ |
{ |
1121 |
tile->redraw_cycle = priv->redraw_cycle; |
tile->redraw_cycle = priv->redraw_cycle; |
1122 |
pixbuf = g_object_ref (tile->pixbuf); |
pixbuf = g_object_ref (tile->pixbuf); |
1123 |
} else |
} |
|
pixbuf = NULL; |
|
1124 |
|
|
1125 |
return pixbuf; |
return pixbuf; |
1126 |
} |
} |
1184 |
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) |
1185 |
{ |
{ |
1186 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1187 |
|
gchar *filename; |
1188 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf; |
1189 |
|
|
1190 |
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); |
1191 |
|
|
1192 |
/* try to get file from internal cache */ |
if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) { |
1193 |
pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y); |
osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y); |
1194 |
|
return; |
1195 |
|
} |
1196 |
|
|
1197 |
/* 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", |
1198 |
if (priv->cache_dir && !pixbuf) |
priv->cache_dir, G_DIR_SEPARATOR, |
1199 |
{ |
zoom, G_DIR_SEPARATOR, |
1200 |
gchar *filename; |
x, G_DIR_SEPARATOR, |
1201 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
y, |
1202 |
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); |
|
|
} |
|
1203 |
|
|
1204 |
g_free(filename); |
/* try to get file from internal cache first */ |
1205 |
} |
if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y))) |
1206 |
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1207 |
|
|
1208 |
if (G_LIKELY(pixbuf)) |
if(pixbuf) |
1209 |
{ |
{ |
1210 |
|
g_debug("Found tile %s", filename); |
1211 |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
1212 |
g_object_unref (pixbuf); |
g_object_unref (pixbuf); |
1213 |
} |
} |
1238 |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
1239 |
} |
} |
1240 |
} |
} |
1241 |
|
g_free(filename); |
1242 |
} |
} |
1243 |
|
|
1244 |
static void |
static void |
1332 |
|
|
1333 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
1334 |
map_y0 = priv->map_y - EXTRA_BORDER; |
map_y0 = priv->map_y - EXTRA_BORDER; |
|
|
|
1335 |
for(list = trackpoint_list; list != NULL; list = list->next) |
for(list = trackpoint_list; list != NULL; list = list->next) |
1336 |
{ |
{ |
1337 |
coord_t *tp = list->data; |
coord_t *tp = list->data; |
1386 |
|
|
1387 |
if (priv->show_trip_history) |
if (priv->show_trip_history) |
1388 |
osm_gps_map_print_track (map, priv->trip_history); |
osm_gps_map_print_track (map, priv->trip_history); |
1389 |
|
|
1390 |
if (priv->tracks) |
if (priv->tracks) |
1391 |
{ |
{ |
|
g_debug("TRACK"); |
|
1392 |
GSList* tmp = priv->tracks; |
GSList* tmp = priv->tracks; |
1393 |
while (tmp != NULL) |
while (tmp != NULL) |
1394 |
{ |
{ |
1398 |
} |
} |
1399 |
} |
} |
1400 |
|
|
1401 |
static gboolean |
static gboolean |
1402 |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
1403 |
{ |
{ |
1404 |
return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
1405 |
} |
} |
1406 |
|
|
1407 |
static void |
static void |
1408 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1409 |
{ |
{ |
1410 |
|
OsmGpsMapPrivate *priv = map->priv; |
1411 |
|
|
1412 |
|
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
1413 |
|
return; |
1414 |
|
|
1415 |
|
/* run through the cache, and remove the tiles which have not been used |
1416 |
|
* during the last redraw operation */ |
1417 |
|
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
1418 |
|
} |
1419 |
|
|
1420 |
|
#ifdef ENABLE_OSD |
1421 |
|
/* position and extent of bounding box */ |
1422 |
|
#define OSD_X (10) |
1423 |
|
#define OSD_Y (10) |
1424 |
|
|
1425 |
|
#define OSD_COLOR 0.5, 0.5, 1 |
1426 |
|
|
1427 |
|
/* parameters of the direction shape */ |
1428 |
|
#define D_RAD (20) // diameter of dpad |
1429 |
|
#define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center |
1430 |
|
#define D_LEN (D_RAD/4) // length of arrow |
1431 |
|
#define D_WID (D_LEN) // width of arrow |
1432 |
|
|
1433 |
|
/* parameters of the "zoom" pad */ |
1434 |
|
#define Z_STEP (-D_RAD/8) // distance between dpad and zoom |
1435 |
|
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
1436 |
|
|
1437 |
|
/* shadow also depends on control size */ |
1438 |
|
#define OSD_SHADOW (D_RAD/8) |
1439 |
|
|
1440 |
|
/* total width and height of controls incl. shadow */ |
1441 |
|
#define OSD_W (2*D_RAD + OSD_SHADOW) |
1442 |
|
#define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
1443 |
|
|
1444 |
|
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
1445 |
|
|
1446 |
|
#define Z_TOP (2 * D_RAD + Z_STEP) |
1447 |
|
#define Z_MID (Z_TOP + Z_RAD) |
1448 |
|
#define Z_BOT (Z_MID + Z_RAD) |
1449 |
|
#define Z_LEFT (Z_RAD) |
1450 |
|
#define Z_RIGHT (2 * D_RAD - Z_RAD) |
1451 |
|
|
1452 |
|
/* create the cairo shape used for the zoom buttons */ |
1453 |
|
static void |
1454 |
|
osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) { |
1455 |
|
cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
1456 |
|
cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); |
1457 |
|
cairo_arc (cr, x+Z_RIGHT, y+Z_MID, Z_RAD, -M_PI/2, M_PI/2); |
1458 |
|
cairo_line_to (cr, x+Z_LEFT, y+Z_BOT); |
1459 |
|
cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); |
1460 |
|
} |
1461 |
|
|
1462 |
|
/* create the cairo shape used for the dpad */ |
1463 |
|
static void |
1464 |
|
osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) { |
1465 |
|
cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
1466 |
|
} |
1467 |
|
|
1468 |
|
typedef enum { |
1469 |
|
OSD_NONE = 0, |
1470 |
|
OSD_BG, |
1471 |
|
OSD_UP, |
1472 |
|
OSD_DOWN, |
1473 |
|
OSD_LEFT, |
1474 |
|
OSD_RIGHT, |
1475 |
|
OSD_IN, |
1476 |
|
OSD_OUT, |
1477 |
|
OSD_GPS |
1478 |
|
} osd_button_t; |
1479 |
|
|
1480 |
|
static gboolean |
1481 |
|
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
1482 |
|
{ |
1483 |
|
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
1484 |
|
} |
1485 |
|
|
1486 |
|
/* check whether x/y is within the dpad */ |
1487 |
|
static osd_button_t |
1488 |
|
osm_gps_map_osd_check_dpad(gint x, gint y) |
1489 |
|
{ |
1490 |
|
/* within entire dpad circle */ |
1491 |
|
if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD)) |
1492 |
|
{ |
1493 |
|
/* convert into position relative to dpads centre */ |
1494 |
|
x -= (OSD_X + D_RAD); |
1495 |
|
y -= (OSD_Y + D_RAD); |
1496 |
|
|
1497 |
|
/* check for dpad center goes here! */ |
1498 |
|
if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD/3)) |
1499 |
|
return OSD_GPS; |
1500 |
|
|
1501 |
|
if( y < 0 && abs(x) < abs(y)) |
1502 |
|
return OSD_UP; |
1503 |
|
|
1504 |
|
if( y > 0 && abs(x) < abs(y)) |
1505 |
|
return OSD_DOWN; |
1506 |
|
|
1507 |
|
if( x < 0 && abs(y) < abs(x)) |
1508 |
|
return OSD_LEFT; |
1509 |
|
|
1510 |
|
if( x > 0 && abs(y) < abs(x)) |
1511 |
|
return OSD_RIGHT; |
1512 |
|
|
1513 |
|
return OSD_BG; |
1514 |
|
} |
1515 |
|
return OSD_NONE; |
1516 |
|
} |
1517 |
|
|
1518 |
|
/* check whether x/y is within the zoom pads */ |
1519 |
|
static osd_button_t |
1520 |
|
osm_gps_map_osd_check_zoom(gint x, gint y) { |
1521 |
|
if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < Z_BOT) { |
1522 |
|
|
1523 |
|
/* within circle around (-) label */ |
1524 |
|
if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD)) |
1525 |
|
return OSD_OUT; |
1526 |
|
|
1527 |
|
/* between center of (-) button and center of entire zoom control area */ |
1528 |
|
if(x > OSD_LEFT && x < OSD_X + D_RAD) |
1529 |
|
return OSD_OUT; |
1530 |
|
|
1531 |
|
/* within circle around (+) label */ |
1532 |
|
if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD)) |
1533 |
|
return OSD_IN; |
1534 |
|
|
1535 |
|
/* between center of (+) button and center of entire zoom control area */ |
1536 |
|
if(x < OSD_RIGHT && x > OSD_X + D_RAD) |
1537 |
|
return OSD_IN; |
1538 |
|
} |
1539 |
|
|
1540 |
|
return OSD_NONE; |
1541 |
|
} |
1542 |
|
|
1543 |
|
static osd_button_t |
1544 |
|
osm_gps_map_osd_check(gint x, gint y) { |
1545 |
|
osd_button_t but = OSD_NONE; |
1546 |
|
|
1547 |
|
/* first do a rough test for the OSD area. */ |
1548 |
|
/* this is just to avoid an unnecessary detailed test */ |
1549 |
|
if(x > OSD_X && x < OSD_X + OSD_W && |
1550 |
|
y > OSD_Y && y < OSD_Y + OSD_H) { |
1551 |
|
|
1552 |
|
but = osm_gps_map_osd_check_dpad(x, y); |
1553 |
|
|
1554 |
|
if(but == OSD_NONE) |
1555 |
|
but = osm_gps_map_osd_check_zoom(x, y); |
1556 |
|
} |
1557 |
|
|
1558 |
|
return but; |
1559 |
|
} |
1560 |
|
|
1561 |
|
static void |
1562 |
|
osm_gps_map_osd_shape_shadow(cairo_t *cr) { |
1563 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
1564 |
|
cairo_fill (cr); |
1565 |
|
cairo_stroke (cr); |
1566 |
|
} |
1567 |
|
|
1568 |
|
static void |
1569 |
|
osm_gps_map_osd_shape(cairo_t *cr) { |
1570 |
|
cairo_set_source_rgb (cr, 1, 1, 1); |
1571 |
|
cairo_fill_preserve (cr); |
1572 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
1573 |
|
cairo_set_line_width (cr, 1); |
1574 |
|
cairo_stroke (cr); |
1575 |
|
} |
1576 |
|
|
1577 |
|
static void |
1578 |
|
osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
1579 |
|
/* move reference to dpad center */ |
1580 |
|
x += D_RAD; |
1581 |
|
y += D_RAD; |
1582 |
|
|
1583 |
|
const static gint offset[][3][2] = { |
1584 |
|
/* left arrow/triangle */ |
1585 |
|
{ { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } }, |
1586 |
|
/* right arrow/triangle */ |
1587 |
|
{ { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } }, |
1588 |
|
/* top arrow/triangle */ |
1589 |
|
{ { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } }, |
1590 |
|
/* bottom arrow/triangle */ |
1591 |
|
{ { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } } |
1592 |
|
}; |
1593 |
|
|
1594 |
|
int i; |
1595 |
|
for(i=0;i<4;i++) { |
1596 |
|
cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]); |
1597 |
|
cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]); |
1598 |
|
cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]); |
1599 |
|
} |
1600 |
|
} |
1601 |
|
|
1602 |
|
/* draw the sattelite dish icon in the center of the dpad */ |
1603 |
|
#define GPS_V0 (D_RAD/8) |
1604 |
|
#define GPS_V1 (D_RAD/10) |
1605 |
|
#define GPS_V2 (D_RAD/5) |
1606 |
|
|
1607 |
|
/* draw a satellite receiver dish */ |
1608 |
|
static void |
1609 |
|
osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
1610 |
|
/* move reference to dpad center */ |
1611 |
|
x += D_RAD; |
1612 |
|
y += D_RAD + GPS_V0; |
1613 |
|
|
1614 |
|
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
1615 |
|
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
1616 |
|
cairo_rel_line_to (cr, +GPS_V0, +GPS_V0); |
1617 |
|
cairo_close_path (cr); |
1618 |
|
|
1619 |
|
cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2); |
1620 |
|
cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y); |
1621 |
|
cairo_close_path (cr); |
1622 |
|
|
1623 |
|
x += GPS_V1; |
1624 |
|
cairo_move_to (cr, x, y-GPS_V2); |
1625 |
|
cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); |
1626 |
|
} |
1627 |
|
|
1628 |
|
#define Z_LEN (2*Z_RAD/3) |
1629 |
|
|
1630 |
|
static void |
1631 |
|
osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
1632 |
|
cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
1633 |
|
cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); |
1634 |
|
|
1635 |
|
cairo_move_to (cr, x + Z_RIGHT, y + Z_MID - Z_LEN); |
1636 |
|
cairo_line_to (cr, x + Z_RIGHT, y + Z_MID + Z_LEN); |
1637 |
|
cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID); |
1638 |
|
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
1639 |
|
} |
1640 |
|
|
1641 |
|
static void |
1642 |
|
osm_gps_map_osd_labels(cairo_t *cr, gint width) { |
1643 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
1644 |
|
cairo_set_line_width (cr, width); |
1645 |
|
cairo_stroke (cr); |
1646 |
|
} |
1647 |
|
|
1648 |
|
static void |
1649 |
|
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width) { |
1650 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
1651 |
|
cairo_set_line_width (cr, width); |
1652 |
|
cairo_stroke (cr); |
1653 |
|
} |
1654 |
|
|
1655 |
|
static void |
1656 |
|
osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset) |
1657 |
|
{ |
1658 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1659 |
|
|
1660 |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
/* backup previous contents */ |
1661 |
return; |
if(!priv->osd.backup) |
1662 |
|
priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1); |
1663 |
|
|
1664 |
|
gint x = OSD_X + EXTRA_BORDER + xoffset; |
1665 |
|
gint y = OSD_Y + EXTRA_BORDER + yoffset; |
1666 |
|
|
1667 |
|
/* create backup of background */ |
1668 |
|
gdk_draw_drawable(priv->osd.backup, |
1669 |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
1670 |
|
priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2); |
1671 |
|
priv->osd.backup_x = x-1; |
1672 |
|
priv->osd.backup_y = y-1; |
1673 |
|
|
1674 |
|
#if 0 |
1675 |
|
/* create pixbuf for osd */ |
1676 |
|
if(!priv->osd.pixbuf) |
1677 |
|
priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, |
1678 |
|
TRUE, 8, OSD_W, OSD_H); |
1679 |
|
cairo_surface_t *surface = |
1680 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
1681 |
|
|
1682 |
|
/* fill with transparency */ |
1683 |
|
{ |
1684 |
|
cairo_t *cr = cairo_create(surface); |
1685 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1686 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1687 |
|
cairo_paint(cr); |
1688 |
|
cairo_destroy(cr); |
1689 |
|
} |
1690 |
|
#endif |
1691 |
|
|
1692 |
|
|
1693 |
|
#ifdef USE_CAIRO |
1694 |
|
// cairo_t *cr = cairo_create(surface); |
1695 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
1696 |
|
|
1697 |
|
/* --------- draw zoom and dpad shape shadow ----------- */ |
1698 |
|
|
1699 |
|
osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
1700 |
|
osm_gps_map_osd_shape_shadow(cr); |
1701 |
|
osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
1702 |
|
osm_gps_map_osd_shape_shadow(cr); |
1703 |
|
|
1704 |
|
/* --------- draw zoom and dpad shape ----------- */ |
1705 |
|
|
1706 |
|
osm_gps_map_osd_zoom_shape(cr, x, y); |
1707 |
|
osm_gps_map_osd_shape(cr); |
1708 |
|
osm_gps_map_osd_dpad_shape(cr, x, y); |
1709 |
|
osm_gps_map_osd_shape(cr); |
1710 |
|
|
1711 |
|
/* --------- draw zoom and dpad labels --------- */ |
1712 |
|
|
1713 |
|
osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
1714 |
|
osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
1715 |
|
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3); |
1716 |
|
osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
1717 |
|
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6); |
1718 |
|
|
1719 |
|
osm_gps_map_osd_zoom_labels(cr, x, y); |
1720 |
|
osm_gps_map_osd_dpad_labels(cr, x, y); |
1721 |
|
osm_gps_map_osd_labels(cr, Z_RAD/3); |
1722 |
|
osm_gps_map_osd_dpad_gps(cr, x, y); |
1723 |
|
osm_gps_map_osd_labels(cr, Z_RAD/6); |
1724 |
|
|
1725 |
|
cairo_destroy(cr); |
1726 |
|
|
1727 |
|
#else |
1728 |
|
#warning "OSD control display lacks a non-cairo implementation!" |
1729 |
|
#endif |
1730 |
|
} |
1731 |
|
|
1732 |
|
static void |
1733 |
|
osm_gps_map_osd_restore (OsmGpsMap *map) |
1734 |
|
{ |
1735 |
|
OsmGpsMapPrivate *priv = map->priv; |
1736 |
|
|
1737 |
/* run through the cache, and remove the tiles which have not been used |
/* restore backup of previous contents */ |
1738 |
* during the last redraw operation */ |
if(priv->osd.backup) { |
1739 |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
/* create backup of background */ |
1740 |
|
gdk_draw_drawable(priv->pixmap, |
1741 |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
1742 |
|
priv->osd.backup, 0, 0, |
1743 |
|
priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2); |
1744 |
|
} |
1745 |
} |
} |
1746 |
|
|
1747 |
|
#endif |
1748 |
|
|
1749 |
static gboolean |
static gboolean |
1750 |
osm_gps_map_map_redraw (OsmGpsMap *map) |
osm_gps_map_map_redraw (OsmGpsMap *map) |
1751 |
{ |
{ |
1776 |
osm_gps_map_print_tracks(map); |
osm_gps_map_print_tracks(map); |
1777 |
osm_gps_map_draw_gps_point(map); |
osm_gps_map_draw_gps_point(map); |
1778 |
osm_gps_map_print_images(map); |
osm_gps_map_print_images(map); |
1779 |
|
#ifdef ENABLE_BALLOON |
1780 |
|
osm_gps_map_draw_balloon_int(map); |
1781 |
|
#endif |
1782 |
|
#ifdef ENABLE_OSD |
1783 |
|
osm_gps_map_osd_draw_controls(map, 0, 0); |
1784 |
|
#endif |
1785 |
|
|
1786 |
//osm_gps_map_osd_speed(map, 1.5); |
//osm_gps_map_osd_speed(map, 1.5); |
1787 |
osm_gps_map_purge_cache(map); |
osm_gps_map_purge_cache(map); |
1813 |
priv->gps = g_new0(coord_t, 1); |
priv->gps = g_new0(coord_t, 1); |
1814 |
priv->gps_valid = FALSE; |
priv->gps_valid = FALSE; |
1815 |
|
|
1816 |
|
#ifdef ENABLE_BALLOON |
1817 |
|
priv->balloon.coo = g_new0(coord_t, 1); |
1818 |
|
priv->balloon.valid = FALSE; |
1819 |
|
priv->balloon.cb = NULL; |
1820 |
|
#endif |
1821 |
|
|
1822 |
|
#ifdef ENABLE_OSD |
1823 |
|
priv->osd.backup = NULL; |
1824 |
|
#endif |
1825 |
|
|
1826 |
priv->tracks = NULL; |
priv->tracks = NULL; |
1827 |
priv->images = NULL; |
priv->images = NULL; |
1828 |
|
|
1835 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1836 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1837 |
|
|
1838 |
|
priv->map_source = -1; |
1839 |
|
|
1840 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1841 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1842 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1890 |
{ |
{ |
1891 |
GObject *object; |
GObject *object; |
1892 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1893 |
|
OsmGpsMap *map; |
1894 |
|
const char *uri; |
1895 |
|
|
1896 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1897 |
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); |
1898 |
|
map = OSM_GPS_MAP(object); |
1899 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1900 |
|
|
1901 |
|
//user can specify a map source ID, or a repo URI as the map source |
1902 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1903 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1904 |
|
g_debug("Using null source"); |
1905 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1906 |
|
|
1907 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1908 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1909 |
|
} |
1910 |
|
else if (priv->map_source >= 0) { |
1911 |
|
//check if the source given is valid |
1912 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1913 |
|
if (uri) { |
1914 |
|
g_debug("Setting map source from ID"); |
1915 |
|
g_free(priv->repo_uri); |
1916 |
|
|
1917 |
|
priv->repo_uri = g_strdup(uri); |
1918 |
|
priv->image_format = g_strdup( |
1919 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1920 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1921 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1922 |
|
} |
1923 |
|
} |
1924 |
|
|
1925 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1926 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1927 |
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); |
1932 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1933 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1934 |
//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 |
1935 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1936 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1937 |
g_free(old); |
g_free(old); |
1938 |
|
} else { |
1939 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1940 |
|
priv->cache_dir = g_strdup(md5); |
1941 |
} |
} |
1942 |
|
|
1943 |
g_free(md5); |
g_free(md5); |
1944 |
} |
} |
1945 |
|
|
1946 |
|
inspect_map_uri(map); |
1947 |
|
|
1948 |
return object; |
return object; |
1949 |
} |
} |
1950 |
|
|
1971 |
if(priv->pixmap) |
if(priv->pixmap) |
1972 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1973 |
|
|
1974 |
|
if (priv->null_tile) |
1975 |
|
g_object_unref (priv->null_tile); |
1976 |
|
|
1977 |
if(priv->gc_map) |
if(priv->gc_map) |
1978 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1979 |
|
|
1980 |
if (priv->idle_map_redraw != 0) |
if (priv->idle_map_redraw != 0) |
1981 |
g_source_remove (priv->idle_map_redraw); |
g_source_remove (priv->idle_map_redraw); |
1982 |
|
|
1983 |
|
g_free(priv->gps); |
1984 |
|
|
1985 |
|
#ifdef ENABLE_BALLOON |
1986 |
|
g_free(priv->balloon.coo); |
1987 |
|
#endif |
1988 |
|
|
1989 |
|
#ifdef ENABLE_OSD |
1990 |
|
if (priv->osd.backup) |
1991 |
|
g_object_unref(priv->osd.backup); |
1992 |
|
#endif |
1993 |
|
|
1994 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
1995 |
} |
} |
1996 |
|
|
2002 |
|
|
2003 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
2004 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
2005 |
|
g_free(priv->image_format); |
2006 |
|
|
2007 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
2008 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
2033 |
break; |
break; |
2034 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
2035 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
2036 |
break; |
break; |
2037 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
2038 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
2039 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
2040 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
2041 |
|
|
2042 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
2043 |
GValue val = {0}; |
GValue val = {0}; |
2044 |
|
|
2045 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
2046 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
2047 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
2051 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
2052 |
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); |
2053 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
2054 |
} else |
} else |
2055 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
2056 |
|
|
2057 |
break; |
break; |
2058 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
2059 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
2060 |
|
priv->cache_dir = g_value_dup_string (value); |
2061 |
break; |
break; |
2062 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
2063 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
2088 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
2089 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
2090 |
break; |
break; |
2091 |
|
case PROP_MAP_SOURCE: |
2092 |
|
priv->map_source = g_value_get_int (value); |
2093 |
|
break; |
2094 |
|
case PROP_IMAGE_FORMAT: |
2095 |
|
priv->image_format = g_value_dup_string (value); |
2096 |
|
break; |
2097 |
default: |
default: |
2098 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
2099 |
break; |
break; |
2171 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
2172 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
2173 |
break; |
break; |
2174 |
|
case PROP_MAP_SOURCE: |
2175 |
|
g_value_set_int(value, priv->map_source); |
2176 |
|
break; |
2177 |
|
case PROP_IMAGE_FORMAT: |
2178 |
|
g_value_set_string(value, priv->image_format); |
2179 |
|
break; |
2180 |
default: |
default: |
2181 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
2182 |
break; |
break; |
2184 |
} |
} |
2185 |
|
|
2186 |
static gboolean |
static gboolean |
2187 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
2188 |
{ |
{ |
2189 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
2190 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
2206 |
{ |
{ |
2207 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2208 |
|
|
2209 |
|
#ifdef ENABLE_BALLOON |
2210 |
|
/* don't drag if the user clicked within the balloon */ |
2211 |
|
if (osm_gps_map_in_balloon(priv, |
2212 |
|
event->x + EXTRA_BORDER, |
2213 |
|
event->y + EXTRA_BORDER)) |
2214 |
|
{ |
2215 |
|
priv->drag_counter = -1; |
2216 |
|
return FALSE; |
2217 |
|
} |
2218 |
|
#endif |
2219 |
|
|
2220 |
|
#ifdef ENABLE_OSD |
2221 |
|
/* also don't drag on clicks into the control OSD */ |
2222 |
|
if(osm_gps_map_osd_check(event->x, event->y) != OSD_NONE) |
2223 |
|
{ |
2224 |
|
priv->drag_counter = -1; |
2225 |
|
return FALSE; |
2226 |
|
} |
2227 |
|
#endif |
2228 |
|
|
2229 |
priv->drag_counter = 0; |
priv->drag_counter = 0; |
2230 |
priv->drag_start_mouse_x = (int) event->x; |
priv->drag_start_mouse_x = (int) event->x; |
2231 |
priv->drag_start_mouse_y = (int) event->y; |
priv->drag_start_mouse_y = (int) event->y; |
2240 |
{ |
{ |
2241 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2242 |
|
|
2243 |
|
#ifdef ENABLE_OSD |
2244 |
|
/* released inside OSD control? */ |
2245 |
|
osd_button_t but = osm_gps_map_osd_check(event->x, event->y); |
2246 |
|
if(but != OSD_NONE) |
2247 |
|
{ |
2248 |
|
switch(but) { |
2249 |
|
case OSD_UP: |
2250 |
|
priv->map_y -= GTK_WIDGET(widget)->allocation.height/4; |
2251 |
|
priv->center_coord_set = FALSE; |
2252 |
|
break; |
2253 |
|
|
2254 |
|
case OSD_DOWN: |
2255 |
|
priv->map_y += GTK_WIDGET(widget)->allocation.height/4; |
2256 |
|
priv->center_coord_set = FALSE; |
2257 |
|
break; |
2258 |
|
|
2259 |
|
case OSD_LEFT: |
2260 |
|
priv->map_x -= GTK_WIDGET(widget)->allocation.width/4; |
2261 |
|
priv->center_coord_set = FALSE; |
2262 |
|
break; |
2263 |
|
|
2264 |
|
case OSD_RIGHT: |
2265 |
|
priv->map_x += GTK_WIDGET(widget)->allocation.width/4; |
2266 |
|
priv->center_coord_set = FALSE; |
2267 |
|
break; |
2268 |
|
|
2269 |
|
case OSD_IN: |
2270 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1); |
2271 |
|
break; |
2272 |
|
|
2273 |
|
case OSD_OUT: |
2274 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1); |
2275 |
|
break; |
2276 |
|
|
2277 |
|
default: |
2278 |
|
break; |
2279 |
|
} |
2280 |
|
|
2281 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
2282 |
|
|
2283 |
|
return FALSE; |
2284 |
|
} |
2285 |
|
#endif |
2286 |
|
|
2287 |
|
#ifdef ENABLE_BALLOON |
2288 |
|
/* released inside the balloon? */ |
2289 |
|
if (osm_gps_map_in_balloon(priv, |
2290 |
|
event->x + EXTRA_BORDER, |
2291 |
|
event->y + EXTRA_BORDER)) |
2292 |
|
{ |
2293 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
2294 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
2295 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
2296 |
|
} |
2297 |
|
#endif |
2298 |
|
|
2299 |
if (priv->dragging) |
if (priv->dragging) |
2300 |
{ |
{ |
2301 |
priv->dragging = FALSE; |
priv->dragging = FALSE; |
2313 |
|
|
2314 |
priv->drag_mouse_dx = 0; |
priv->drag_mouse_dx = 0; |
2315 |
priv->drag_mouse_dy = 0; |
priv->drag_mouse_dy = 0; |
2316 |
priv->drag_counter = 0; |
priv->drag_counter = -1; |
2317 |
|
|
2318 |
return FALSE; |
return FALSE; |
2319 |
} |
} |
2338 |
if (!(state & GDK_BUTTON1_MASK)) |
if (!(state & GDK_BUTTON1_MASK)) |
2339 |
return FALSE; |
return FALSE; |
2340 |
|
|
2341 |
|
if (priv->drag_counter < 0) |
2342 |
|
return FALSE; |
2343 |
|
|
2344 |
priv->drag_counter++; |
priv->drag_counter++; |
2345 |
|
|
2346 |
// we havent dragged more than 6 pixels |
// we havent dragged more than 6 pixels |
2355 |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
2356 |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
2357 |
|
|
2358 |
|
#ifdef ENABLE_OSD |
2359 |
|
/* undo OSD */ |
2360 |
|
osm_gps_map_osd_restore (OSM_GPS_MAP(widget)); |
2361 |
|
|
2362 |
|
/* draw new OSD */ |
2363 |
|
osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget), |
2364 |
|
-priv->drag_mouse_dx, |
2365 |
|
-priv->drag_mouse_dy); |
2366 |
|
#endif |
2367 |
|
|
2368 |
gdk_draw_drawable ( |
gdk_draw_drawable ( |
2369 |
widget->window, |
widget->window, |
2370 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2453 |
widget->window, |
widget->window, |
2454 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2455 |
priv->pixmap, |
priv->pixmap, |
2456 |
event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER, |
event->area.x + EXTRA_BORDER, |
2457 |
|
event->area.y + EXTRA_BORDER, |
2458 |
event->area.x, event->area.y, |
event->area.x, event->area.y, |
2459 |
event->area.width, event->area.height); |
event->area.width, event->area.height); |
2460 |
|
|
2461 |
|
#ifdef ENABLE_OSD_OVL |
2462 |
|
/* TODO: intersect with area */ |
2463 |
|
if (priv->osd.pixbuf) |
2464 |
|
{ |
2465 |
|
// gdk_draw_drawable (widget->window, |
2466 |
|
// widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2467 |
|
// priv->osd.pixbuf, 0, 0, |
2468 |
|
// OSD_X, OSD_Y, OSD_W, OSD_H); |
2469 |
|
} |
2470 |
|
#endif |
2471 |
|
|
2472 |
return FALSE; |
return FALSE; |
2473 |
} |
} |
2474 |
|
|
2491 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
2492 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
2493 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
2494 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
2495 |
|
|
2496 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2497 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
2529 |
PROP_REPO_URI, |
PROP_REPO_URI, |
2530 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
2531 |
"repo uri", |
"repo uri", |
2532 |
"osm repo uri", |
"map source tile repository uri", |
2533 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
2534 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2535 |
|
|
2536 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2537 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
2538 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
2539 |
"proxy uri", |
"proxy uri", |
2546 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
2547 |
"tile cache", |
"tile cache", |
2548 |
"osm local tile cache dir", |
"osm local tile cache dir", |
2549 |
"/tmp/Maps", |
NULL, |
2550 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2551 |
|
|
2552 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2574 |
"maximum zoom level", |
"maximum zoom level", |
2575 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2576 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2577 |
17, |
OSM_MAX_ZOOM, |
2578 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2579 |
|
|
2580 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2584 |
"minimum zoom level", |
"minimum zoom level", |
2585 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2586 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2587 |
1, |
OSM_MIN_ZOOM, |
2588 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2589 |
|
|
2590 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2667 |
20, |
20, |
2668 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2669 |
|
|
2670 |
|
g_object_class_install_property (object_class, |
2671 |
|
PROP_MAP_SOURCE, |
2672 |
|
g_param_spec_int ("map-source", |
2673 |
|
"map source", |
2674 |
|
"map source ID", |
2675 |
|
-1, /* minimum property value */ |
2676 |
|
G_MAXINT, /* maximum property value */ |
2677 |
|
-1, |
2678 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2679 |
|
|
2680 |
|
g_object_class_install_property (object_class, |
2681 |
|
PROP_IMAGE_FORMAT, |
2682 |
|
g_param_spec_string ("image-format", |
2683 |
|
"image format", |
2684 |
|
"map source tile repository image format (jpg, png)", |
2685 |
|
OSM_IMAGE_FORMAT, |
2686 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2687 |
|
} |
2688 |
|
|
2689 |
|
const char* |
2690 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2691 |
|
{ |
2692 |
|
switch(source) |
2693 |
|
{ |
2694 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2695 |
|
return "None"; |
2696 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2697 |
|
return "OpenStreetMap"; |
2698 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2699 |
|
return "OpenStreetMap Renderer"; |
2700 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2701 |
|
return "OpenAerialMap"; |
2702 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2703 |
|
return "Maps-For-Free"; |
2704 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2705 |
|
return "Google Maps"; |
2706 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2707 |
|
return "Google Satellite"; |
2708 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2709 |
|
return "Google Hybrid"; |
2710 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2711 |
|
return "Virtual Earth"; |
2712 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2713 |
|
return "Virtual Earth Satellite"; |
2714 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2715 |
|
return "Virtual Earth Hybrid"; |
2716 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2717 |
|
return "Yahoo Maps"; |
2718 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2719 |
|
return "Yahoo Satellite"; |
2720 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2721 |
|
return "Yahoo Hybrid"; |
2722 |
|
default: |
2723 |
|
return NULL; |
2724 |
|
} |
2725 |
|
return NULL; |
2726 |
|
} |
2727 |
|
|
2728 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2729 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2730 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2731 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2732 |
|
const char* |
2733 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2734 |
|
{ |
2735 |
|
switch(source) |
2736 |
|
{ |
2737 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2738 |
|
return "none://"; |
2739 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2740 |
|
return OSM_REPO_URI; |
2741 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2742 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2743 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2744 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2745 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2746 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2747 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2748 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2749 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2750 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2751 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2752 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2753 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2754 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2755 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2756 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2757 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2758 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2759 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2760 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2761 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2762 |
|
/* TODO: Implement signed Y, aka U |
2763 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2764 |
|
* x = tilex, |
2765 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2766 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2767 |
|
*/ |
2768 |
|
return NULL; |
2769 |
|
default: |
2770 |
|
return NULL; |
2771 |
|
} |
2772 |
|
return NULL; |
2773 |
|
} |
2774 |
|
|
2775 |
|
const char * |
2776 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2777 |
|
{ |
2778 |
|
switch(source) { |
2779 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2780 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2781 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2782 |
|
return "png"; |
2783 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2784 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2785 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2786 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2787 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2788 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2789 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2790 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2791 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2792 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2793 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2794 |
|
return "jpg"; |
2795 |
|
default: |
2796 |
|
return "bin"; |
2797 |
|
} |
2798 |
|
return "bin"; |
2799 |
|
} |
2800 |
|
|
2801 |
|
|
2802 |
|
int |
2803 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2804 |
|
{ |
2805 |
|
return 1; |
2806 |
|
} |
2807 |
|
|
2808 |
|
int |
2809 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2810 |
|
{ |
2811 |
|
switch(source) { |
2812 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2813 |
|
return 18; |
2814 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2815 |
|
return OSM_MAX_ZOOM; |
2816 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2817 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2818 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2819 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2820 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2821 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2822 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2823 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2824 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2825 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2826 |
|
return 17; |
2827 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2828 |
|
return 11; |
2829 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2830 |
|
return 18; |
2831 |
|
default: |
2832 |
|
return 17; |
2833 |
|
} |
2834 |
|
return 17; |
2835 |
} |
} |
2836 |
|
|
2837 |
void |
void |
2864 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2865 |
{ |
{ |
2866 |
// x = i, y = j |
// x = i, y = j |
2867 |
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", |
2868 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2869 |
|
zoom, G_DIR_SEPARATOR, |
2870 |
|
i, G_DIR_SEPARATOR, |
2871 |
|
j, |
2872 |
|
priv->image_format); |
2873 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2874 |
{ |
{ |
2875 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2876 |
num_tiles++; |
num_tiles++; |
2932 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2933 |
{ |
{ |
2934 |
int zoom_old; |
int zoom_old; |
2935 |
double factor = 1.0; |
double factor = 0.0; |
2936 |
int width_center, height_center; |
int width_center, height_center; |
2937 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2938 |
|
|
3003 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
3004 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
3005 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
3006 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
3007 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
3008 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
3009 |
|
|
3016 |
} |
} |
3017 |
} |
} |
3018 |
|
|
3019 |
|
gboolean |
3020 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
3021 |
|
{ |
3022 |
|
OsmGpsMapPrivate *priv = map->priv; |
3023 |
|
if (priv->images) { |
3024 |
|
GSList *list; |
3025 |
|
for(list = priv->images; list != NULL; list = list->next) |
3026 |
|
{ |
3027 |
|
image_t *im = list->data; |
3028 |
|
if (im->image == image) |
3029 |
|
{ |
3030 |
|
priv->images = g_slist_remove_link(priv->images, list); |
3031 |
|
g_object_unref(im->image); |
3032 |
|
g_free(im); |
3033 |
|
osm_gps_map_map_redraw_idle(map); |
3034 |
|
return TRUE; |
3035 |
|
} |
3036 |
|
} |
3037 |
|
} |
3038 |
|
return FALSE; |
3039 |
|
} |
3040 |
|
|
3041 |
void |
void |
3042 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
3043 |
{ |
{ |
3229 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
3230 |
} |
} |
3231 |
|
|
3232 |
|
float |
3233 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
3234 |
|
{ |
3235 |
|
OsmGpsMapPrivate *priv; |
3236 |
|
|
3237 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
3238 |
|
priv = map->priv; |
3239 |
|
|
3240 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
3241 |
|
} |
3242 |
|
|
3243 |
|
#ifdef ENABLE_BALLOON |
3244 |
|
void |
3245 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
3246 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
3247 |
|
{ |
3248 |
|
OsmGpsMapPrivate *priv; |
3249 |
|
|
3250 |
|
/* remove and previously installed balloon */ |
3251 |
|
osm_gps_map_clear_balloon (map); |
3252 |
|
|
3253 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
3254 |
|
priv = map->priv; |
3255 |
|
|
3256 |
|
priv->balloon.coo->rlat = deg2rad(latitude); |
3257 |
|
priv->balloon.coo->rlon = deg2rad(longitude); |
3258 |
|
priv->balloon.valid = TRUE; |
3259 |
|
|
3260 |
|
priv->balloon.cb = cb; |
3261 |
|
priv->balloon.data = data; |
3262 |
|
|
3263 |
|
// this redraws the map |
3264 |
|
osm_gps_map_map_redraw_idle(map); |
3265 |
|
} |
3266 |
|
|
3267 |
|
void |
3268 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
3269 |
|
{ |
3270 |
|
OsmGpsMapPrivate *priv; |
3271 |
|
|
3272 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
3273 |
|
priv = map->priv; |
3274 |
|
|
3275 |
|
priv->balloon.valid = FALSE; |
3276 |
|
|
3277 |
|
osm_gps_map_map_redraw_idle(map); |
3278 |
|
} |
3279 |
|
#endif |