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 |
|
#ifdef ENABLE_OSD |
111 |
|
//the osd controls |
112 |
|
struct { |
113 |
|
GdkPixmap *backup; |
114 |
|
gint backup_x, backup_y; |
115 |
|
|
116 |
|
|
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 |
|
/* most visual effects are hardcoded by now, but may be made */ |
657 |
|
/* available via properties later */ |
658 |
|
#define BALLOON_AREA_WIDTH 290 |
659 |
|
#define BALLOON_AREA_HEIGHT 75 |
660 |
|
|
661 |
|
#define BALLOON_CORNER_RADIUS 20 |
662 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/4) |
663 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
664 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
665 |
|
#define BALLOON_TRANSPARENCY 0.8 |
666 |
|
#define POINTER_HEIGHT 20 |
667 |
|
#define POINTER_FOOT_WIDTH 20 |
668 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
669 |
|
#define BALLOON_SHADOW 5 |
670 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
671 |
|
|
672 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS/3) |
673 |
|
|
674 |
|
|
675 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
676 |
|
/* for the shadow */ |
677 |
|
static void |
678 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
679 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
680 |
|
|
681 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
682 |
|
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0); |
683 |
|
if(!bottom) { |
684 |
|
/* insert top pointer */ |
685 |
|
cairo_line_to (cr, px1, y0); |
686 |
|
cairo_line_to (cr, px, py); |
687 |
|
cairo_line_to (cr, px0, y0); |
688 |
|
} |
689 |
|
|
690 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
691 |
|
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS); |
692 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
693 |
|
cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1); |
694 |
|
if(bottom) { |
695 |
|
/* insert bottom pointer */ |
696 |
|
cairo_line_to (cr, px0, y1); |
697 |
|
cairo_line_to (cr, px, py); |
698 |
|
cairo_line_to (cr, px1, y1); |
699 |
|
} |
700 |
|
|
701 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
702 |
|
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS); |
703 |
|
|
704 |
|
cairo_close_path (cr); |
705 |
|
} |
706 |
|
|
707 |
|
static void |
708 |
|
osm_gps_map_draw_balloon_int (OsmGpsMap *map) |
709 |
|
{ |
710 |
|
OsmGpsMapPrivate *priv = map->priv; |
711 |
|
|
712 |
|
if (priv->balloon.valid) { |
713 |
|
|
714 |
|
/* ------- convert given coordinate into screen position --------- */ |
715 |
|
int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) - |
716 |
|
priv->map_x + EXTRA_BORDER; |
717 |
|
int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) - |
718 |
|
priv->map_y + EXTRA_BORDER; |
719 |
|
|
720 |
|
/* check position of this relative to screen center to determine */ |
721 |
|
/* pointer direction ... */ |
722 |
|
int pointer_x = x0, pointer_x0, pointer_x1; |
723 |
|
int pointer_y = y0; |
724 |
|
|
725 |
|
/* ... and calculate position */ |
726 |
|
if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) { |
727 |
|
x0 -= BALLOON_WIDTH - POINTER_OFFSET; |
728 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
729 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
730 |
|
} else { |
731 |
|
x0 -= POINTER_OFFSET; |
732 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
733 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
734 |
|
} |
735 |
|
|
736 |
|
gboolean bottom = FALSE; |
737 |
|
if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) { |
738 |
|
bottom = TRUE; |
739 |
|
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
740 |
|
} else |
741 |
|
y0 += POINTER_HEIGHT; |
742 |
|
|
743 |
|
/* calculate bottom/right of box */ |
744 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
745 |
|
|
746 |
|
/* save balloon screen coordinates for later use */ |
747 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
748 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
749 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
750 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
751 |
|
|
752 |
|
#ifdef USE_CAIRO |
753 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
754 |
|
|
755 |
|
/* --------- draw shadow --------------- */ |
756 |
|
osm_gps_map_draw_balloon_shape (cr, |
757 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
758 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
759 |
|
bottom, pointer_x, pointer_y, |
760 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
761 |
|
|
762 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
763 |
|
cairo_fill_preserve (cr); |
764 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
765 |
|
cairo_set_line_width (cr, 0); |
766 |
|
cairo_stroke (cr); |
767 |
|
|
768 |
|
/* --------- draw main shape ----------- */ |
769 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
770 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
771 |
|
|
772 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
773 |
|
cairo_fill_preserve (cr); |
774 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
775 |
|
cairo_set_line_width (cr, 1); |
776 |
|
cairo_stroke (cr); |
777 |
|
|
778 |
|
|
779 |
|
/* ---------- draw close button --------- */ |
780 |
|
|
781 |
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
782 |
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
783 |
|
int crad = CLOSE_BUTTON_RADIUS; |
784 |
|
|
785 |
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
786 |
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
787 |
|
cairo_fill_preserve (cr); |
788 |
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
789 |
|
cairo_set_line_width (cr, 2); |
790 |
|
cairo_stroke(cr); |
791 |
|
|
792 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
793 |
|
cairo_set_line_width (cr, 3); |
794 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
795 |
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
796 |
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
797 |
|
cairo_stroke (cr); |
798 |
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
799 |
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
800 |
|
cairo_stroke (cr); |
801 |
|
|
802 |
|
if (priv->balloon.cb) { |
803 |
|
/* clip in case application tries to draw in */ |
804 |
|
/* exceed of the balloon */ |
805 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
806 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
807 |
|
cairo_clip (cr); |
808 |
|
cairo_new_path (cr); /* current path is not |
809 |
|
consumed by cairo_clip() */ |
810 |
|
|
811 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
812 |
|
} |
813 |
|
|
814 |
|
cairo_destroy(cr); |
815 |
|
|
816 |
|
gtk_widget_queue_draw_area (GTK_WIDGET(map), |
817 |
|
x0, y0, BALLOON_WIDTH, |
818 |
|
BALLOON_HEIGHT + POINTER_HEIGHT); |
819 |
|
#else |
820 |
|
#warning "Balloon display lacks a non-cairo implementation!" |
821 |
|
#endif |
822 |
|
} |
823 |
|
} |
824 |
|
|
825 |
|
/* the user clicked into the balloons main area. handle this */ |
826 |
|
static void |
827 |
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
828 |
|
{ |
829 |
|
OsmGpsMapPrivate *priv = map->priv; |
830 |
|
|
831 |
|
if (!priv->balloon.valid) |
832 |
|
return; |
833 |
|
|
834 |
|
/* check if the close button was clicked */ |
835 |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
836 |
|
(x < priv->balloon.rect.w) && |
837 |
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
838 |
|
|
839 |
|
priv->balloon.valid = FALSE; |
840 |
|
osm_gps_map_map_redraw_idle(map); |
841 |
|
} |
842 |
|
} |
843 |
|
|
844 |
|
/* return true if balloon is being displayed and if */ |
845 |
|
/* the given coordinate is within this balloon */ |
846 |
|
static gboolean |
847 |
|
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
848 |
|
{ |
849 |
|
return (priv->balloon.valid && |
850 |
|
(x > priv->balloon.rect.x) && |
851 |
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
852 |
|
(y > priv->balloon.rect.y) && |
853 |
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
854 |
} |
} |
855 |
|
|
856 |
static void |
static void |
858 |
{ |
{ |
859 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
860 |
|
|
861 |
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); |
|
862 |
|
|
863 |
/* draw pixbuf onto pixmap */ |
/* draw pixbuf onto pixmap */ |
864 |
gdk_draw_pixbuf (priv->pixmap, |
gdk_draw_pixbuf (priv->pixmap, |
890 |
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) |
891 |
#endif |
#endif |
892 |
{ |
{ |
893 |
int fd; |
FILE *file; |
894 |
tile_download_t *dl = (tile_download_t *)user_data; |
tile_download_t *dl = (tile_download_t *)user_data; |
895 |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
OsmGpsMap *map = OSM_GPS_MAP(dl->map); |
896 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
903 |
{ |
{ |
904 |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
if (g_mkdir_with_parents(dl->folder,0700) == 0) |
905 |
{ |
{ |
906 |
fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
file = g_fopen(dl->filename, "wb"); |
907 |
if (fd != -1) |
if (file != NULL) |
908 |
{ |
{ |
909 |
write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg)); |
fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file); |
910 |
file_saved = TRUE; |
file_saved = TRUE; |
911 |
|
g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
912 |
|
fclose (file); |
913 |
|
|
|
g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename); |
|
|
close (fd); |
|
914 |
} |
} |
915 |
} |
} |
916 |
else |
else |
923 |
{ |
{ |
924 |
GdkPixbuf *pixbuf = NULL; |
GdkPixbuf *pixbuf = NULL; |
925 |
|
|
926 |
|
/* if the file was actually stored on disk, we can simply */ |
927 |
|
/* load and decode it from that file */ |
928 |
if (priv->cache_dir) |
if (priv->cache_dir) |
929 |
{ |
{ |
930 |
if (file_saved) |
if (file_saved) |
958 |
g_warning("Error: Unable to determine image file format"); |
g_warning("Error: Unable to determine image file format"); |
959 |
} |
} |
960 |
} |
} |
961 |
|
|
962 |
/* Store the tile into the cache */ |
/* Store the tile into the cache */ |
963 |
if (G_LIKELY (pixbuf)) |
if (G_LIKELY (pixbuf)) |
964 |
{ |
{ |
973 |
* we are using it as a key in the hash table */ |
* we are using it as a key in the hash table */ |
974 |
dl->filename = NULL; |
dl->filename = NULL; |
975 |
} |
} |
|
|
|
976 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
977 |
} |
} |
978 |
g_hash_table_remove(priv->tile_queue, dl->uri); |
g_hash_table_remove(priv->tile_queue, dl->uri); |
1031 |
g_free(dl->uri); |
g_free(dl->uri); |
1032 |
g_free(dl); |
g_free(dl); |
1033 |
} else { |
} else { |
1034 |
dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x); |
dl->folder = g_strdup_printf("%s%c%d%c%d%c", |
1035 |
dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y); |
priv->cache_dir, G_DIR_SEPARATOR, |
1036 |
|
zoom, G_DIR_SEPARATOR, |
1037 |
|
x, G_DIR_SEPARATOR); |
1038 |
|
dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1039 |
|
priv->cache_dir, G_DIR_SEPARATOR, |
1040 |
|
zoom, G_DIR_SEPARATOR, |
1041 |
|
x, G_DIR_SEPARATOR, |
1042 |
|
y, |
1043 |
|
priv->image_format); |
1044 |
dl->map = map; |
dl->map = map; |
1045 |
dl->redraw = redraw; |
dl->redraw = redraw; |
1046 |
|
|
1058 |
if (cookie) { |
if (cookie) { |
1059 |
g_debug("Adding Google Cookie"); |
g_debug("Adding Google Cookie"); |
1060 |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
soup_message_headers_append(msg->request_headers, "Cookie", cookie); |
|
|
|
1061 |
} |
} |
1062 |
} |
} |
1063 |
} |
} |
1079 |
{ |
{ |
1080 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1081 |
gchar *filename; |
gchar *filename; |
1082 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf = NULL; |
1083 |
OsmCachedTile *tile; |
OsmCachedTile *tile; |
1084 |
|
|
1085 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
1086 |
priv->cache_dir, |
priv->cache_dir, G_DIR_SEPARATOR, |
1087 |
zoom, x, y); |
zoom, G_DIR_SEPARATOR, |
1088 |
|
x, G_DIR_SEPARATOR, |
1089 |
|
y, |
1090 |
|
priv->image_format); |
1091 |
|
|
1092 |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
tile = g_hash_table_lookup (priv->tile_cache, filename); |
1093 |
if (tile) |
if (tile) |
1094 |
{ |
{ |
1095 |
g_free (filename); |
g_free (filename); |
1096 |
} |
} |
1097 |
else if (priv->cache_dir) |
else |
1098 |
{ |
{ |
1099 |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1100 |
if (pixbuf) |
if (pixbuf) |
1110 |
{ |
{ |
1111 |
tile->redraw_cycle = priv->redraw_cycle; |
tile->redraw_cycle = priv->redraw_cycle; |
1112 |
pixbuf = g_object_ref (tile->pixbuf); |
pixbuf = g_object_ref (tile->pixbuf); |
1113 |
} else |
} |
|
pixbuf = NULL; |
|
1114 |
|
|
1115 |
return pixbuf; |
return pixbuf; |
1116 |
} |
} |
1174 |
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) |
1175 |
{ |
{ |
1176 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1177 |
|
gchar *filename; |
1178 |
GdkPixbuf *pixbuf; |
GdkPixbuf *pixbuf; |
1179 |
|
|
1180 |
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); |
1181 |
|
|
1182 |
/* try to get file from internal cache */ |
if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) { |
1183 |
pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y); |
osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y); |
1184 |
|
return; |
1185 |
|
} |
1186 |
|
|
1187 |
/* 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", |
1188 |
if (priv->cache_dir && !pixbuf) |
priv->cache_dir, G_DIR_SEPARATOR, |
1189 |
{ |
zoom, G_DIR_SEPARATOR, |
1190 |
gchar *filename; |
x, G_DIR_SEPARATOR, |
1191 |
filename = g_strdup_printf("%s/%u/%u/%u.png", |
y, |
1192 |
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); |
|
|
} |
|
1193 |
|
|
1194 |
g_free(filename); |
/* try to get file from internal cache first */ |
1195 |
} |
if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y))) |
1196 |
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL); |
1197 |
|
|
1198 |
if (G_LIKELY(pixbuf)) |
if(pixbuf) |
1199 |
{ |
{ |
1200 |
|
g_debug("Found tile %s", filename); |
1201 |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y); |
1202 |
g_object_unref (pixbuf); |
g_object_unref (pixbuf); |
1203 |
} |
} |
1228 |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
TRUE, offset_x, offset_y, TILESIZE, TILESIZE); |
1229 |
} |
} |
1230 |
} |
} |
1231 |
|
g_free(filename); |
1232 |
} |
} |
1233 |
|
|
1234 |
static void |
static void |
1322 |
|
|
1323 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
1324 |
map_y0 = priv->map_y - EXTRA_BORDER; |
map_y0 = priv->map_y - EXTRA_BORDER; |
|
|
|
1325 |
for(list = trackpoint_list; list != NULL; list = list->next) |
for(list = trackpoint_list; list != NULL; list = list->next) |
1326 |
{ |
{ |
1327 |
coord_t *tp = list->data; |
coord_t *tp = list->data; |
1376 |
|
|
1377 |
if (priv->show_trip_history) |
if (priv->show_trip_history) |
1378 |
osm_gps_map_print_track (map, priv->trip_history); |
osm_gps_map_print_track (map, priv->trip_history); |
1379 |
|
|
1380 |
if (priv->tracks) |
if (priv->tracks) |
1381 |
{ |
{ |
|
g_debug("TRACK"); |
|
1382 |
GSList* tmp = priv->tracks; |
GSList* tmp = priv->tracks; |
1383 |
while (tmp != NULL) |
while (tmp != NULL) |
1384 |
{ |
{ |
1388 |
} |
} |
1389 |
} |
} |
1390 |
|
|
1391 |
static gboolean |
static gboolean |
1392 |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user) |
1393 |
{ |
{ |
1394 |
return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle); |
1395 |
} |
} |
1396 |
|
|
1397 |
static void |
static void |
1398 |
osm_gps_map_purge_cache (OsmGpsMap *map) |
osm_gps_map_purge_cache (OsmGpsMap *map) |
1399 |
{ |
{ |
1400 |
|
OsmGpsMapPrivate *priv = map->priv; |
1401 |
|
|
1402 |
|
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
1403 |
|
return; |
1404 |
|
|
1405 |
|
/* run through the cache, and remove the tiles which have not been used |
1406 |
|
* during the last redraw operation */ |
1407 |
|
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
1408 |
|
} |
1409 |
|
|
1410 |
|
#ifdef ENABLE_OSD |
1411 |
|
/* position and extent of bounding box */ |
1412 |
|
#define OSD_X (10) |
1413 |
|
#define OSD_Y (10) |
1414 |
|
#define OSD_W (80+5) |
1415 |
|
#define OSD_H (120+5) |
1416 |
|
|
1417 |
|
static void |
1418 |
|
osm_gps_map_draw_osd_controls (OsmGpsMap *map, gint xoffset, gint yoffset) |
1419 |
|
{ |
1420 |
|
/* xyz */ |
1421 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1422 |
|
|
1423 |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
/* backup previous contents */ |
1424 |
return; |
if(!priv->osd.backup) |
1425 |
|
priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W, OSD_H, -1); |
1426 |
|
|
1427 |
|
gint x = OSD_X + EXTRA_BORDER + xoffset; |
1428 |
|
gint y = OSD_Y + EXTRA_BORDER + yoffset; |
1429 |
|
|
1430 |
|
/* create backup of background */ |
1431 |
|
gdk_draw_drawable(priv->osd.backup, |
1432 |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
1433 |
|
priv->pixmap, x, y, 0, 0, OSD_W, OSD_H); |
1434 |
|
priv->osd.backup_x = x; |
1435 |
|
priv->osd.backup_y = y; |
1436 |
|
|
1437 |
|
#if 0 |
1438 |
|
/* create pixbuf for osd */ |
1439 |
|
if(!priv->osd.pixbuf) |
1440 |
|
priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, |
1441 |
|
TRUE, 8, OSD_W, OSD_H); |
1442 |
|
cairo_surface_t *surface = |
1443 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
1444 |
|
|
1445 |
|
/* fill with transparency */ |
1446 |
|
{ |
1447 |
|
cairo_t *cr = cairo_create(surface); |
1448 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1449 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1450 |
|
cairo_paint(cr); |
1451 |
|
cairo_destroy(cr); |
1452 |
|
} |
1453 |
|
#endif |
1454 |
|
|
1455 |
|
|
1456 |
|
#ifdef USE_CAIRO |
1457 |
|
// cairo_t *cr = cairo_create(surface); |
1458 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
1459 |
|
|
1460 |
|
#define RAD 40 |
1461 |
|
#define TIP 35 |
1462 |
|
#define LEN 15 |
1463 |
|
#define WID 15 |
1464 |
|
|
1465 |
|
/* --------- the direction "pad" shape and shadow ----------- */ |
1466 |
|
cairo_arc (cr, x+RAD+5, y+RAD+5, RAD, 0, 2 * M_PI); |
1467 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
1468 |
|
cairo_fill (cr); |
1469 |
|
cairo_stroke (cr); |
1470 |
|
|
1471 |
|
cairo_arc (cr, x+RAD, y+RAD, RAD, 0, 2 * M_PI); |
1472 |
|
cairo_set_source_rgb (cr, 1, 1, 1); |
1473 |
|
cairo_fill_preserve (cr); |
1474 |
|
cairo_set_source_rgb (cr, 0.6, 0.6, 1); |
1475 |
|
cairo_set_line_width (cr, 1); |
1476 |
|
cairo_stroke (cr); |
1477 |
|
|
1478 |
|
/* ---------- the zoom pad shape and shadow -------------- */ |
1479 |
|
cairo_move_to (cr, x, y+2*RAD); |
1480 |
|
cairo_line_to (cr, x+2*RAD-10, y+2*RAD); |
1481 |
|
cairo_curve_to (cr, x+2*RAD, y+2*RAD, |
1482 |
|
x+2*RAD, y+3*RAD, |
1483 |
|
x+2*RAD-10, y+3*RAD); |
1484 |
|
cairo_close_path (cr); |
1485 |
|
|
1486 |
|
|
1487 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
1488 |
|
cairo_fill (cr); |
1489 |
|
cairo_stroke (cr); |
1490 |
|
|
1491 |
|
|
1492 |
|
/* left arrow/triangle */ |
1493 |
|
cairo_move_to (cr, x+RAD-TIP, y+RAD); |
1494 |
|
cairo_rel_line_to (cr, +LEN, -WID/2); |
1495 |
|
cairo_rel_line_to (cr, 0, +WID); |
1496 |
|
cairo_rel_line_to (cr, -LEN, -WID/2); |
1497 |
|
cairo_close_path (cr); |
1498 |
|
|
1499 |
|
/* right arrow/triangle */ |
1500 |
|
cairo_move_to (cr, x+RAD+TIP, y+RAD); |
1501 |
|
cairo_rel_line_to (cr, -LEN, -WID/2); |
1502 |
|
cairo_rel_line_to (cr, 0, +WID); |
1503 |
|
cairo_rel_line_to (cr, +LEN, -WID/2); |
1504 |
|
cairo_close_path (cr); |
1505 |
|
|
1506 |
|
/* top arrow/triangle */ |
1507 |
|
cairo_move_to (cr, x+RAD, y+RAD-TIP); |
1508 |
|
cairo_rel_line_to (cr, -WID/2, +LEN); |
1509 |
|
cairo_rel_line_to (cr, +WID, 0); |
1510 |
|
cairo_rel_line_to (cr, -WID/2, -LEN); |
1511 |
|
cairo_close_path (cr); |
1512 |
|
|
1513 |
|
/* bottom arrow/triangle */ |
1514 |
|
cairo_move_to (cr, x+RAD, y+RAD+TIP); |
1515 |
|
cairo_rel_line_to (cr, -WID/2, -LEN); |
1516 |
|
cairo_rel_line_to (cr, +WID, 0); |
1517 |
|
cairo_rel_line_to (cr, -WID/2, +LEN); |
1518 |
|
cairo_close_path (cr); |
1519 |
|
|
1520 |
|
cairo_set_source_rgb (cr, 0.6, 0.6, 1); |
1521 |
|
cairo_fill_preserve (cr); |
1522 |
|
cairo_set_line_width (cr, 0); |
1523 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
1524 |
|
cairo_stroke (cr); |
1525 |
|
|
1526 |
/* run through the cache, and remove the tiles which have not been used |
|
1527 |
* during the last redraw operation */ |
cairo_destroy(cr); |
1528 |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
|
1529 |
|
#else |
1530 |
|
#warning "OSD control display lacks a non-cairo implementation!" |
1531 |
|
#endif |
1532 |
} |
} |
1533 |
|
|
1534 |
|
static void |
1535 |
|
osm_gps_map_osd_restore (OsmGpsMap *map) |
1536 |
|
{ |
1537 |
|
OsmGpsMapPrivate *priv = map->priv; |
1538 |
|
|
1539 |
|
/* restore backup of previous contents */ |
1540 |
|
if(priv->osd.backup) { |
1541 |
|
/* create backup of background */ |
1542 |
|
gdk_draw_drawable(priv->pixmap, |
1543 |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
1544 |
|
priv->osd.backup, 0, 0, |
1545 |
|
priv->osd.backup_x, priv->osd.backup_y, OSD_W, OSD_H); |
1546 |
|
} |
1547 |
|
} |
1548 |
|
|
1549 |
|
#endif |
1550 |
|
|
1551 |
static gboolean |
static gboolean |
1552 |
osm_gps_map_map_redraw (OsmGpsMap *map) |
osm_gps_map_map_redraw (OsmGpsMap *map) |
1553 |
{ |
{ |
1578 |
osm_gps_map_print_tracks(map); |
osm_gps_map_print_tracks(map); |
1579 |
osm_gps_map_draw_gps_point(map); |
osm_gps_map_draw_gps_point(map); |
1580 |
osm_gps_map_print_images(map); |
osm_gps_map_print_images(map); |
1581 |
|
osm_gps_map_draw_balloon_int(map); |
1582 |
|
#ifdef ENABLE_OSD |
1583 |
|
osm_gps_map_draw_osd_controls(map, 0, 0); |
1584 |
|
#endif |
1585 |
|
|
1586 |
//osm_gps_map_osd_speed(map, 1.5); |
//osm_gps_map_osd_speed(map, 1.5); |
1587 |
osm_gps_map_purge_cache(map); |
osm_gps_map_purge_cache(map); |
1613 |
priv->gps = g_new0(coord_t, 1); |
priv->gps = g_new0(coord_t, 1); |
1614 |
priv->gps_valid = FALSE; |
priv->gps_valid = FALSE; |
1615 |
|
|
1616 |
|
priv->balloon.coo = g_new0(coord_t, 1); |
1617 |
|
priv->balloon.valid = FALSE; |
1618 |
|
priv->balloon.cb = NULL; |
1619 |
|
|
1620 |
|
#ifdef ENABLE_OSD |
1621 |
|
priv->osd.backup = NULL; |
1622 |
|
#endif |
1623 |
|
|
1624 |
priv->tracks = NULL; |
priv->tracks = NULL; |
1625 |
priv->images = NULL; |
priv->images = NULL; |
1626 |
|
|
1633 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1634 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1635 |
|
|
1636 |
|
priv->map_source = -1; |
1637 |
|
|
1638 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1639 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1640 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1688 |
{ |
{ |
1689 |
GObject *object; |
GObject *object; |
1690 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1691 |
|
OsmGpsMap *map; |
1692 |
|
const char *uri; |
1693 |
|
|
1694 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1695 |
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); |
1696 |
|
map = OSM_GPS_MAP(object); |
1697 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1698 |
|
|
1699 |
|
//user can specify a map source ID, or a repo URI as the map source |
1700 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1701 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1702 |
|
g_debug("Using null source"); |
1703 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1704 |
|
|
1705 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1706 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1707 |
|
} |
1708 |
|
else if (priv->map_source >= 0) { |
1709 |
|
//check if the source given is valid |
1710 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1711 |
|
if (uri) { |
1712 |
|
g_debug("Setting map source from ID"); |
1713 |
|
g_free(priv->repo_uri); |
1714 |
|
|
1715 |
|
priv->repo_uri = g_strdup(uri); |
1716 |
|
priv->image_format = g_strdup( |
1717 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1718 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1719 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1720 |
|
} |
1721 |
|
} |
1722 |
|
|
1723 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1724 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1725 |
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); |
1730 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1731 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1732 |
//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 |
1733 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1734 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1735 |
g_free(old); |
g_free(old); |
1736 |
|
} else { |
1737 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1738 |
|
priv->cache_dir = g_strdup(md5); |
1739 |
} |
} |
1740 |
|
|
1741 |
g_free(md5); |
g_free(md5); |
1742 |
} |
} |
1743 |
|
|
1744 |
|
inspect_map_uri(map); |
1745 |
|
|
1746 |
return object; |
return object; |
1747 |
} |
} |
1748 |
|
|
1769 |
if(priv->pixmap) |
if(priv->pixmap) |
1770 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1771 |
|
|
1772 |
|
if (priv->null_tile) |
1773 |
|
g_object_unref (priv->null_tile); |
1774 |
|
|
1775 |
if(priv->gc_map) |
if(priv->gc_map) |
1776 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1777 |
|
|
1778 |
if (priv->idle_map_redraw != 0) |
if (priv->idle_map_redraw != 0) |
1779 |
g_source_remove (priv->idle_map_redraw); |
g_source_remove (priv->idle_map_redraw); |
1780 |
|
|
1781 |
|
g_free(priv->gps); |
1782 |
|
g_free(priv->balloon.coo); |
1783 |
|
|
1784 |
|
#ifdef ENABLE_OSD |
1785 |
|
if (priv->osd.backup) |
1786 |
|
g_object_unref(priv->osd.backup); |
1787 |
|
#endif |
1788 |
|
|
1789 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
1790 |
} |
} |
1791 |
|
|
1797 |
|
|
1798 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
1799 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
1800 |
|
g_free(priv->image_format); |
1801 |
|
|
1802 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
1803 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
1828 |
break; |
break; |
1829 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
1830 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
1831 |
break; |
break; |
1832 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1833 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
1834 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1835 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
1836 |
|
|
1837 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1838 |
GValue val = {0}; |
GValue val = {0}; |
1839 |
|
|
1840 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1841 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1842 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1846 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
1847 |
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); |
1848 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
1849 |
} else |
} else |
1850 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1851 |
|
|
1852 |
break; |
break; |
1853 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
1854 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
1855 |
|
priv->cache_dir = g_value_dup_string (value); |
1856 |
break; |
break; |
1857 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
1858 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
1883 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1884 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
1885 |
break; |
break; |
1886 |
|
case PROP_MAP_SOURCE: |
1887 |
|
priv->map_source = g_value_get_int (value); |
1888 |
|
break; |
1889 |
|
case PROP_IMAGE_FORMAT: |
1890 |
|
priv->image_format = g_value_dup_string (value); |
1891 |
|
break; |
1892 |
default: |
default: |
1893 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1894 |
break; |
break; |
1966 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1967 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
1968 |
break; |
break; |
1969 |
|
case PROP_MAP_SOURCE: |
1970 |
|
g_value_set_int(value, priv->map_source); |
1971 |
|
break; |
1972 |
|
case PROP_IMAGE_FORMAT: |
1973 |
|
g_value_set_string(value, priv->image_format); |
1974 |
|
break; |
1975 |
default: |
default: |
1976 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1977 |
break; |
break; |
1979 |
} |
} |
1980 |
|
|
1981 |
static gboolean |
static gboolean |
1982 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
1983 |
{ |
{ |
1984 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
1985 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
2001 |
{ |
{ |
2002 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2003 |
|
|
2004 |
|
/* don't drag if the user clicked within the balloon */ |
2005 |
|
if (osm_gps_map_in_balloon(priv, |
2006 |
|
event->x + EXTRA_BORDER, |
2007 |
|
event->y + EXTRA_BORDER)) |
2008 |
|
{ |
2009 |
|
priv->drag_counter = -1; |
2010 |
|
return FALSE; |
2011 |
|
} |
2012 |
|
|
2013 |
priv->drag_counter = 0; |
priv->drag_counter = 0; |
2014 |
priv->drag_start_mouse_x = (int) event->x; |
priv->drag_start_mouse_x = (int) event->x; |
2015 |
priv->drag_start_mouse_y = (int) event->y; |
priv->drag_start_mouse_y = (int) event->y; |
2024 |
{ |
{ |
2025 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2026 |
|
|
2027 |
|
/* released inside the balloon? */ |
2028 |
|
if (osm_gps_map_in_balloon(priv, |
2029 |
|
event->x + EXTRA_BORDER, |
2030 |
|
event->y + EXTRA_BORDER)) |
2031 |
|
{ |
2032 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
2033 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
2034 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
2035 |
|
return FALSE; |
2036 |
|
} |
2037 |
|
|
2038 |
|
if (priv->drag_counter < 0) |
2039 |
|
return FALSE; |
2040 |
|
|
2041 |
if (priv->dragging) |
if (priv->dragging) |
2042 |
{ |
{ |
2043 |
priv->dragging = FALSE; |
priv->dragging = FALSE; |
2055 |
|
|
2056 |
priv->drag_mouse_dx = 0; |
priv->drag_mouse_dx = 0; |
2057 |
priv->drag_mouse_dy = 0; |
priv->drag_mouse_dy = 0; |
2058 |
priv->drag_counter = 0; |
priv->drag_counter = -1; |
2059 |
|
|
2060 |
return FALSE; |
return FALSE; |
2061 |
} |
} |
2080 |
if (!(state & GDK_BUTTON1_MASK)) |
if (!(state & GDK_BUTTON1_MASK)) |
2081 |
return FALSE; |
return FALSE; |
2082 |
|
|
2083 |
|
if (priv->drag_counter < 0) |
2084 |
|
return FALSE; |
2085 |
|
|
2086 |
priv->drag_counter++; |
priv->drag_counter++; |
2087 |
|
|
2088 |
// we havent dragged more than 6 pixels |
// we havent dragged more than 6 pixels |
2097 |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
2098 |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
2099 |
|
|
2100 |
|
#ifdef ENABLE_OSD |
2101 |
|
/* undo OSD */ |
2102 |
|
osm_gps_map_osd_restore (OSM_GPS_MAP(widget)); |
2103 |
|
|
2104 |
|
/* draw new OSD */ |
2105 |
|
osm_gps_map_draw_osd_controls (OSM_GPS_MAP(widget), |
2106 |
|
-priv->drag_mouse_dx, |
2107 |
|
-priv->drag_mouse_dy); |
2108 |
|
#endif |
2109 |
|
|
2110 |
gdk_draw_drawable ( |
gdk_draw_drawable ( |
2111 |
widget->window, |
widget->window, |
2112 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2195 |
widget->window, |
widget->window, |
2196 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2197 |
priv->pixmap, |
priv->pixmap, |
2198 |
event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER, |
event->area.x + EXTRA_BORDER, |
2199 |
|
event->area.y + EXTRA_BORDER, |
2200 |
event->area.x, event->area.y, |
event->area.x, event->area.y, |
2201 |
event->area.width, event->area.height); |
event->area.width, event->area.height); |
2202 |
|
|
2203 |
|
#ifdef ENABLE_OSD_OVL |
2204 |
|
/* TODO: intersect with area */ |
2205 |
|
if (priv->osd.pixbuf) |
2206 |
|
{ |
2207 |
|
// gdk_draw_drawable (widget->window, |
2208 |
|
// widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2209 |
|
// priv->osd.pixbuf, 0, 0, |
2210 |
|
// OSD_X, OSD_Y, OSD_W, OSD_H); |
2211 |
|
} |
2212 |
|
#endif |
2213 |
|
|
2214 |
return FALSE; |
return FALSE; |
2215 |
} |
} |
2216 |
|
|
2233 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
2234 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
2235 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
2236 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
2237 |
|
|
2238 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2239 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
2271 |
PROP_REPO_URI, |
PROP_REPO_URI, |
2272 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
2273 |
"repo uri", |
"repo uri", |
2274 |
"osm repo uri", |
"map source tile repository uri", |
2275 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
2276 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2277 |
|
|
2278 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2279 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
2280 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
2281 |
"proxy uri", |
"proxy uri", |
2288 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
2289 |
"tile cache", |
"tile cache", |
2290 |
"osm local tile cache dir", |
"osm local tile cache dir", |
2291 |
"/tmp/Maps", |
NULL, |
2292 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2293 |
|
|
2294 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2316 |
"maximum zoom level", |
"maximum zoom level", |
2317 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2318 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2319 |
17, |
OSM_MAX_ZOOM, |
2320 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2321 |
|
|
2322 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2326 |
"minimum zoom level", |
"minimum zoom level", |
2327 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2328 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2329 |
1, |
OSM_MIN_ZOOM, |
2330 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2331 |
|
|
2332 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2409 |
20, |
20, |
2410 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2411 |
|
|
2412 |
|
g_object_class_install_property (object_class, |
2413 |
|
PROP_MAP_SOURCE, |
2414 |
|
g_param_spec_int ("map-source", |
2415 |
|
"map source", |
2416 |
|
"map source ID", |
2417 |
|
-1, /* minimum property value */ |
2418 |
|
G_MAXINT, /* maximum property value */ |
2419 |
|
-1, |
2420 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2421 |
|
|
2422 |
|
g_object_class_install_property (object_class, |
2423 |
|
PROP_IMAGE_FORMAT, |
2424 |
|
g_param_spec_string ("image-format", |
2425 |
|
"image format", |
2426 |
|
"map source tile repository image format (jpg, png)", |
2427 |
|
OSM_IMAGE_FORMAT, |
2428 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2429 |
|
} |
2430 |
|
|
2431 |
|
const char* |
2432 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2433 |
|
{ |
2434 |
|
switch(source) |
2435 |
|
{ |
2436 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2437 |
|
return "None"; |
2438 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2439 |
|
return "OpenStreetMap"; |
2440 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2441 |
|
return "OpenStreetMap Renderer"; |
2442 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2443 |
|
return "OpenAerialMap"; |
2444 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2445 |
|
return "Maps-For-Free"; |
2446 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2447 |
|
return "Google Maps"; |
2448 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2449 |
|
return "Google Satellite"; |
2450 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2451 |
|
return "Google Hybrid"; |
2452 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2453 |
|
return "Virtual Earth"; |
2454 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2455 |
|
return "Virtual Earth Satellite"; |
2456 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2457 |
|
return "Virtual Earth Hybrid"; |
2458 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2459 |
|
return "Yahoo Maps"; |
2460 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2461 |
|
return "Yahoo Satellite"; |
2462 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2463 |
|
return "Yahoo Hybrid"; |
2464 |
|
default: |
2465 |
|
return NULL; |
2466 |
|
} |
2467 |
|
return NULL; |
2468 |
|
} |
2469 |
|
|
2470 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2471 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2472 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2473 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2474 |
|
const char* |
2475 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2476 |
|
{ |
2477 |
|
switch(source) |
2478 |
|
{ |
2479 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2480 |
|
return "none://"; |
2481 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2482 |
|
return OSM_REPO_URI; |
2483 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2484 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2485 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2486 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2487 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2488 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2489 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2490 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2491 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2492 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2493 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2494 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2495 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2496 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2497 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2498 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2499 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2500 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2501 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2502 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2503 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2504 |
|
/* TODO: Implement signed Y, aka U |
2505 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2506 |
|
* x = tilex, |
2507 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2508 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2509 |
|
*/ |
2510 |
|
return NULL; |
2511 |
|
default: |
2512 |
|
return NULL; |
2513 |
|
} |
2514 |
|
return NULL; |
2515 |
|
} |
2516 |
|
|
2517 |
|
const char * |
2518 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2519 |
|
{ |
2520 |
|
switch(source) { |
2521 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2522 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2523 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2524 |
|
return "png"; |
2525 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2526 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2527 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2528 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2529 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2530 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2531 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2532 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2533 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2534 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2535 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2536 |
|
return "jpg"; |
2537 |
|
default: |
2538 |
|
return "bin"; |
2539 |
|
} |
2540 |
|
return "bin"; |
2541 |
|
} |
2542 |
|
|
2543 |
|
|
2544 |
|
int |
2545 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2546 |
|
{ |
2547 |
|
return 1; |
2548 |
|
} |
2549 |
|
|
2550 |
|
int |
2551 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2552 |
|
{ |
2553 |
|
switch(source) { |
2554 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2555 |
|
return 18; |
2556 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2557 |
|
return OSM_MAX_ZOOM; |
2558 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2559 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2560 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2561 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2562 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2563 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2564 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2565 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2566 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2567 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2568 |
|
return 17; |
2569 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2570 |
|
return 11; |
2571 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2572 |
|
return 18; |
2573 |
|
default: |
2574 |
|
return 17; |
2575 |
|
} |
2576 |
|
return 17; |
2577 |
} |
} |
2578 |
|
|
2579 |
void |
void |
2606 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2607 |
{ |
{ |
2608 |
// x = i, y = j |
// x = i, y = j |
2609 |
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", |
2610 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2611 |
|
zoom, G_DIR_SEPARATOR, |
2612 |
|
i, G_DIR_SEPARATOR, |
2613 |
|
j, |
2614 |
|
priv->image_format); |
2615 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2616 |
{ |
{ |
2617 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2618 |
num_tiles++; |
num_tiles++; |
2674 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2675 |
{ |
{ |
2676 |
int zoom_old; |
int zoom_old; |
2677 |
double factor = 1.0; |
double factor = 0.0; |
2678 |
int width_center, height_center; |
int width_center, height_center; |
2679 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2680 |
|
|
2745 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
2746 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
2747 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
2748 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
2749 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
2750 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
2751 |
|
|
2758 |
} |
} |
2759 |
} |
} |
2760 |
|
|
2761 |
|
gboolean |
2762 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
2763 |
|
{ |
2764 |
|
OsmGpsMapPrivate *priv = map->priv; |
2765 |
|
if (priv->images) { |
2766 |
|
GSList *list; |
2767 |
|
for(list = priv->images; list != NULL; list = list->next) |
2768 |
|
{ |
2769 |
|
image_t *im = list->data; |
2770 |
|
if (im->image == image) |
2771 |
|
{ |
2772 |
|
priv->images = g_slist_remove_link(priv->images, list); |
2773 |
|
g_object_unref(im->image); |
2774 |
|
g_free(im); |
2775 |
|
osm_gps_map_map_redraw_idle(map); |
2776 |
|
return TRUE; |
2777 |
|
} |
2778 |
|
} |
2779 |
|
} |
2780 |
|
return FALSE; |
2781 |
|
} |
2782 |
|
|
2783 |
void |
void |
2784 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
2785 |
{ |
{ |
2971 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
2972 |
} |
} |
2973 |
|
|
2974 |
|
float |
2975 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
2976 |
|
{ |
2977 |
|
OsmGpsMapPrivate *priv; |
2978 |
|
|
2979 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
2980 |
|
priv = map->priv; |
2981 |
|
|
2982 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
2983 |
|
} |
2984 |
|
|
2985 |
|
void |
2986 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
2987 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
2988 |
|
{ |
2989 |
|
OsmGpsMapPrivate *priv; |
2990 |
|
|
2991 |
|
/* remove and previously installed balloon */ |
2992 |
|
osm_gps_map_clear_balloon (map); |
2993 |
|
|
2994 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2995 |
|
priv = map->priv; |
2996 |
|
|
2997 |
|
priv->balloon.coo->rlat = deg2rad(latitude); |
2998 |
|
priv->balloon.coo->rlon = deg2rad(longitude); |
2999 |
|
priv->balloon.valid = TRUE; |
3000 |
|
|
3001 |
|
priv->balloon.cb = cb; |
3002 |
|
priv->balloon.data = data; |
3003 |
|
|
3004 |
|
// this redraws the map |
3005 |
|
osm_gps_map_map_redraw_idle(map); |
3006 |
|
} |
3007 |
|
|
3008 |
|
void |
3009 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
3010 |
|
{ |
3011 |
|
OsmGpsMapPrivate *priv; |
3012 |
|
|
3013 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
3014 |
|
priv = map->priv; |
3015 |
|
|
3016 |
|
priv->balloon.valid = FALSE; |
3017 |
|
|
3018 |
|
osm_gps_map_map_redraw_idle(map); |
3019 |
|
} |