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 (if present) |
114 |
|
osm_gps_map_osd_t *osd; |
115 |
|
#endif |
116 |
|
|
117 |
//additional images or tracks added to the map |
//additional images or tracks added to the map |
118 |
GSList *tracks; |
GSList *tracks; |
119 |
GSList *images; |
GSList *images; |
123 |
GdkGC *gc_map; |
GdkGC *gc_map; |
124 |
|
|
125 |
//The tile painted when one cannot be found |
//The tile painted when one cannot be found |
126 |
//GdkPixbuf *missing_tile; |
GdkPixbuf *null_tile; |
127 |
|
|
128 |
//For tracking click and drag |
//For tracking click and drag |
129 |
int drag_counter; |
int drag_counter; |
176 |
PROP_TILES_QUEUED, |
PROP_TILES_QUEUED, |
177 |
PROP_GPS_TRACK_WIDTH, |
PROP_GPS_TRACK_WIDTH, |
178 |
PROP_GPS_POINT_R1, |
PROP_GPS_POINT_R1, |
179 |
PROP_GPS_POINT_R2 |
PROP_GPS_POINT_R2, |
180 |
|
PROP_MAP_SOURCE, |
181 |
|
PROP_IMAGE_FORMAT |
182 |
}; |
}; |
183 |
|
|
184 |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA); |
192 |
static void osm_gps_map_print_images (OsmGpsMap *map); |
static void osm_gps_map_print_images (OsmGpsMap *map); |
193 |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
static void osm_gps_map_draw_gps_point (OsmGpsMap *map); |
194 |
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); |
195 |
|
#ifdef LIBSOUP22 |
196 |
|
static void osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data); |
197 |
|
#else |
198 |
|
static void osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data); |
199 |
|
#endif |
200 |
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); |
201 |
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); |
202 |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
static void osm_gps_map_fill_tiles_pixel (OsmGpsMap *map); |
446 |
g_log_default_handler (log_domain, log_level, message, user_data); |
g_log_default_handler (log_domain, log_level, message, user_data); |
447 |
} |
} |
448 |
|
|
449 |
|
static float |
450 |
|
osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon) |
451 |
|
{ |
452 |
|
/* world at zoom 1 == 512 pixels */ |
453 |
|
return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom)); |
454 |
|
} |
455 |
|
|
456 |
/* clears the trip list and all resources */ |
/* clears the trip list and all resources */ |
457 |
static void |
static void |
458 |
osm_gps_map_free_trip (OsmGpsMap *map) |
osm_gps_map_free_trip (OsmGpsMap *map) |
562 |
int x, y; |
int x, y; |
563 |
int r = priv->ui_gps_point_inner_radius; |
int r = priv->ui_gps_point_inner_radius; |
564 |
int r2 = priv->ui_gps_point_outer_radius; |
int r2 = priv->ui_gps_point_outer_radius; |
565 |
|
// int lw = priv->ui_gps_track_width; |
566 |
int mr = MAX(r,r2); |
int mr = MAX(r,r2); |
567 |
|
|
568 |
map_x0 = priv->map_x - EXTRA_BORDER; |
map_x0 = priv->map_x - EXTRA_BORDER; |
573 |
cairo_t *cr; |
cairo_t *cr; |
574 |
cairo_pattern_t *pat; |
cairo_pattern_t *pat; |
575 |
#else |
#else |
|
int lw = priv->ui_gps_track_width; |
|
576 |
GdkColor color; |
GdkColor color; |
577 |
GdkGC *marker; |
GdkGC *marker; |
578 |
#endif |
#endif |
647 |
(mr*2)+lw+lw); |
(mr*2)+lw+lw); |
648 |
#endif |
#endif |
649 |
} |
} |
650 |
|
} |
651 |
|
|
652 |
|
#ifdef ENABLE_BALLOON |
653 |
|
/* most visual effects are hardcoded by now, but may be made */ |
654 |
|
/* available via properties later */ |
655 |
|
#ifndef BALLOON_AREA_WIDTH |
656 |
|
#define BALLOON_AREA_WIDTH 290 |
657 |
|
#endif |
658 |
|
#ifndef BALLOON_AREA_HEIGHT |
659 |
|
#define BALLOON_AREA_HEIGHT 75 |
660 |
|
#endif |
661 |
|
#ifndef BALLOON_CORNER_RADIUS |
662 |
|
#define BALLOON_CORNER_RADIUS 10 |
663 |
|
#endif |
664 |
|
|
665 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
666 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
667 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
668 |
|
#define BALLOON_TRANSPARENCY 0.8 |
669 |
|
#define POINTER_HEIGHT 20 |
670 |
|
#define POINTER_FOOT_WIDTH 20 |
671 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
672 |
|
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
673 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
674 |
|
|
675 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
676 |
|
|
677 |
|
|
678 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
679 |
|
/* for the shadow */ |
680 |
|
static void |
681 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
682 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
683 |
|
|
684 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
685 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
686 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
687 |
|
if(!bottom) { |
688 |
|
/* insert top pointer */ |
689 |
|
cairo_line_to (cr, px1, y0); |
690 |
|
cairo_line_to (cr, px, py); |
691 |
|
cairo_line_to (cr, px0, y0); |
692 |
|
} |
693 |
|
|
694 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
695 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
696 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
697 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
698 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
699 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
700 |
|
if(bottom) { |
701 |
|
/* insert bottom pointer */ |
702 |
|
cairo_line_to (cr, px0, y1); |
703 |
|
cairo_line_to (cr, px, py); |
704 |
|
cairo_line_to (cr, px1, y1); |
705 |
|
} |
706 |
|
|
707 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
708 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
709 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
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, BALLOON_CORNER_RADIUS/3.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; |
OsmGpsMapPrivate *priv = map->priv; |
1411 |
|
|
1412 |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size) |
1413 |
return; |
return; |
1414 |
|
|
1415 |
/* run through the cache, and remove the tiles which have not been used |
/* run through the cache, and remove the tiles which have not been used |
1416 |
* during the last redraw operation */ |
* during the last redraw operation */ |
1417 |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv); |
1418 |
} |
} |
1419 |
|
|
1420 |
static gboolean |
static gboolean |
1447 |
osm_gps_map_print_tracks(map); |
osm_gps_map_print_tracks(map); |
1448 |
osm_gps_map_draw_gps_point(map); |
osm_gps_map_draw_gps_point(map); |
1449 |
osm_gps_map_print_images(map); |
osm_gps_map_print_images(map); |
1450 |
|
#ifdef ENABLE_BALLOON |
1451 |
|
osm_gps_map_draw_balloon_int(map); |
1452 |
|
#endif |
1453 |
|
|
1454 |
|
#ifdef ENABLE_OSD |
1455 |
|
if(priv->osd) |
1456 |
|
priv->osd->draw(priv->osd, EXTRA_BORDER, EXTRA_BORDER); |
1457 |
|
#endif |
1458 |
|
|
1459 |
//osm_gps_map_osd_speed(map, 1.5); |
//osm_gps_map_osd_speed(map, 1.5); |
1460 |
osm_gps_map_purge_cache(map); |
osm_gps_map_purge_cache(map); |
1486 |
priv->gps = g_new0(coord_t, 1); |
priv->gps = g_new0(coord_t, 1); |
1487 |
priv->gps_valid = FALSE; |
priv->gps_valid = FALSE; |
1488 |
|
|
1489 |
|
#ifdef ENABLE_BALLOON |
1490 |
|
priv->balloon.coo = g_new0(coord_t, 1); |
1491 |
|
priv->balloon.valid = FALSE; |
1492 |
|
priv->balloon.cb = NULL; |
1493 |
|
#endif |
1494 |
|
|
1495 |
|
#ifdef ENABLE_OSD |
1496 |
|
priv->osd = NULL; |
1497 |
|
#endif |
1498 |
|
|
1499 |
priv->tracks = NULL; |
priv->tracks = NULL; |
1500 |
priv->images = NULL; |
priv->images = NULL; |
1501 |
|
|
1508 |
priv->uri_format = 0; |
priv->uri_format = 0; |
1509 |
priv->the_google = FALSE; |
priv->the_google = FALSE; |
1510 |
|
|
1511 |
|
priv->map_source = -1; |
1512 |
|
|
1513 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1514 |
//Change naumber of concurrent connections option? |
//Change naumber of concurrent connections option? |
1515 |
priv->soup_session = soup_session_async_new_with_options( |
priv->soup_session = soup_session_async_new_with_options( |
1563 |
{ |
{ |
1564 |
GObject *object; |
GObject *object; |
1565 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
1566 |
|
OsmGpsMap *map; |
1567 |
|
const char *uri; |
1568 |
|
|
1569 |
//Always chain up to the parent constructor |
//Always chain up to the parent constructor |
1570 |
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); |
1571 |
|
map = OSM_GPS_MAP(object); |
1572 |
priv = OSM_GPS_MAP_PRIVATE(object); |
priv = OSM_GPS_MAP_PRIVATE(object); |
1573 |
|
|
1574 |
|
//user can specify a map source ID, or a repo URI as the map source |
1575 |
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
1576 |
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
1577 |
|
g_debug("Using null source"); |
1578 |
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
1579 |
|
|
1580 |
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
1581 |
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
1582 |
|
} |
1583 |
|
else if (priv->map_source >= 0) { |
1584 |
|
//check if the source given is valid |
1585 |
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
1586 |
|
if (uri) { |
1587 |
|
g_debug("Setting map source from ID"); |
1588 |
|
g_free(priv->repo_uri); |
1589 |
|
|
1590 |
|
priv->repo_uri = g_strdup(uri); |
1591 |
|
priv->image_format = g_strdup( |
1592 |
|
osm_gps_map_source_get_image_format(priv->map_source)); |
1593 |
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
1594 |
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
1595 |
|
} |
1596 |
|
} |
1597 |
|
|
1598 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1599 |
#ifdef G_CHECKSUM_MD5 |
#ifdef G_CHECKSUM_MD5 |
1600 |
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); |
1605 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1606 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1607 |
//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 |
1608 |
priv->cache_dir = g_strdup_printf("%s/%s", old, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
1609 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1610 |
g_free(old); |
g_free(old); |
1611 |
|
} else { |
1612 |
|
//the new cachedir is the current dir + the md5 of the repo_uri |
1613 |
|
priv->cache_dir = g_strdup(md5); |
1614 |
} |
} |
1615 |
|
|
1616 |
g_free(md5); |
g_free(md5); |
1617 |
} |
} |
1618 |
|
|
1619 |
|
inspect_map_uri(map); |
1620 |
|
|
1621 |
return object; |
return object; |
1622 |
} |
} |
1623 |
|
|
1644 |
if(priv->pixmap) |
if(priv->pixmap) |
1645 |
g_object_unref (priv->pixmap); |
g_object_unref (priv->pixmap); |
1646 |
|
|
1647 |
|
if (priv->null_tile) |
1648 |
|
g_object_unref (priv->null_tile); |
1649 |
|
|
1650 |
if(priv->gc_map) |
if(priv->gc_map) |
1651 |
g_object_unref(priv->gc_map); |
g_object_unref(priv->gc_map); |
1652 |
|
|
1653 |
if (priv->idle_map_redraw != 0) |
if (priv->idle_map_redraw != 0) |
1654 |
g_source_remove (priv->idle_map_redraw); |
g_source_remove (priv->idle_map_redraw); |
1655 |
|
|
1656 |
|
g_free(priv->gps); |
1657 |
|
|
1658 |
|
#ifdef ENABLE_BALLOON |
1659 |
|
g_free(priv->balloon.coo); |
1660 |
|
#endif |
1661 |
|
|
1662 |
|
#ifdef ENABLE_OSD |
1663 |
|
if(priv->osd) |
1664 |
|
priv->osd->free(priv->osd); |
1665 |
|
#endif |
1666 |
|
|
1667 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
1668 |
} |
} |
1669 |
|
|
1675 |
|
|
1676 |
g_free(priv->cache_dir); |
g_free(priv->cache_dir); |
1677 |
g_free(priv->repo_uri); |
g_free(priv->repo_uri); |
1678 |
|
g_free(priv->image_format); |
1679 |
|
|
1680 |
osm_gps_map_free_trip(map); |
osm_gps_map_free_trip(map); |
1681 |
osm_gps_map_free_tracks(map); |
osm_gps_map_free_tracks(map); |
1706 |
break; |
break; |
1707 |
case PROP_REPO_URI: |
case PROP_REPO_URI: |
1708 |
priv->repo_uri = g_value_dup_string (value); |
priv->repo_uri = g_value_dup_string (value); |
|
inspect_map_uri(map); |
|
1709 |
break; |
break; |
1710 |
case PROP_PROXY_URI: |
case PROP_PROXY_URI: |
1711 |
if ( g_value_get_string(value) ) { |
if ( g_value_get_string(value) ) { |
|
|
|
1712 |
priv->proxy_uri = g_value_dup_string (value); |
priv->proxy_uri = g_value_dup_string (value); |
1713 |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
g_debug("Setting proxy server: %s", priv->proxy_uri); |
1714 |
|
|
1715 |
#ifndef LIBSOUP22 |
#ifndef LIBSOUP22 |
1716 |
GValue val = {0}; |
GValue val = {0}; |
1717 |
|
|
1718 |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
1719 |
g_value_init(&val, SOUP_TYPE_URI); |
g_value_init(&val, SOUP_TYPE_URI); |
1720 |
g_value_take_boxed(&val, uri); |
g_value_take_boxed(&val, uri); |
1724 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
1725 |
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); |
1726 |
#endif |
#endif |
|
soup_uri_free(uri); |
|
1727 |
} else |
} else |
1728 |
priv->proxy_uri = NULL; |
priv->proxy_uri = NULL; |
1729 |
|
|
1730 |
break; |
break; |
1731 |
case PROP_TILE_CACHE_DIR: |
case PROP_TILE_CACHE_DIR: |
1732 |
priv->cache_dir = g_value_dup_string (value); |
if ( g_value_get_string(value) ) |
1733 |
|
priv->cache_dir = g_value_dup_string (value); |
1734 |
break; |
break; |
1735 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
1736 |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
1761 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1762 |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
1763 |
break; |
break; |
1764 |
|
case PROP_MAP_SOURCE: |
1765 |
|
priv->map_source = g_value_get_int (value); |
1766 |
|
break; |
1767 |
|
case PROP_IMAGE_FORMAT: |
1768 |
|
priv->image_format = g_value_dup_string (value); |
1769 |
|
break; |
1770 |
default: |
default: |
1771 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1772 |
break; |
break; |
1844 |
case PROP_GPS_POINT_R2: |
case PROP_GPS_POINT_R2: |
1845 |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
1846 |
break; |
break; |
1847 |
|
case PROP_MAP_SOURCE: |
1848 |
|
g_value_set_int(value, priv->map_source); |
1849 |
|
break; |
1850 |
|
case PROP_IMAGE_FORMAT: |
1851 |
|
g_value_set_string(value, priv->image_format); |
1852 |
|
break; |
1853 |
default: |
default: |
1854 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1855 |
break; |
break; |
1857 |
} |
} |
1858 |
|
|
1859 |
static gboolean |
static gboolean |
1860 |
_osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll *event) |
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
1861 |
{ |
{ |
1862 |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
OsmGpsMap *map = OSM_GPS_MAP(widget); |
1863 |
OsmGpsMapPrivate *priv = map->priv; |
OsmGpsMapPrivate *priv = map->priv; |
1879 |
{ |
{ |
1880 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
1881 |
|
|
1882 |
|
#ifdef ENABLE_BALLOON |
1883 |
|
/* don't drag if the user clicked within the balloon */ |
1884 |
|
if (osm_gps_map_in_balloon(priv, |
1885 |
|
event->x + EXTRA_BORDER, |
1886 |
|
event->y + EXTRA_BORDER)) |
1887 |
|
{ |
1888 |
|
priv->drag_counter = -1; |
1889 |
|
return FALSE; |
1890 |
|
} |
1891 |
|
#endif |
1892 |
|
|
1893 |
|
#ifdef ENABLE_OSD |
1894 |
|
#define SCROLL_STEP 10 |
1895 |
|
|
1896 |
|
/* pressed inside OSD control? */ |
1897 |
|
if(priv->osd) { |
1898 |
|
osd_button_t but = priv->osd->check(event->x, event->y); |
1899 |
|
if(but != OSD_NONE) |
1900 |
|
{ |
1901 |
|
priv->drag_counter = -1; |
1902 |
|
|
1903 |
|
switch(but) { |
1904 |
|
case OSD_UP: |
1905 |
|
priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
1906 |
|
priv->center_coord_set = FALSE; |
1907 |
|
break; |
1908 |
|
|
1909 |
|
case OSD_DOWN: |
1910 |
|
priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
1911 |
|
priv->center_coord_set = FALSE; |
1912 |
|
break; |
1913 |
|
|
1914 |
|
case OSD_LEFT: |
1915 |
|
priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
1916 |
|
priv->center_coord_set = FALSE; |
1917 |
|
break; |
1918 |
|
|
1919 |
|
case OSD_RIGHT: |
1920 |
|
priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
1921 |
|
priv->center_coord_set = FALSE; |
1922 |
|
break; |
1923 |
|
|
1924 |
|
case OSD_IN: |
1925 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1); |
1926 |
|
break; |
1927 |
|
|
1928 |
|
case OSD_OUT: |
1929 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1); |
1930 |
|
break; |
1931 |
|
|
1932 |
|
default: |
1933 |
|
/* all custom buttons are forwarded to the application */ |
1934 |
|
if(priv->osd->cb) |
1935 |
|
priv->osd->cb(but, priv->osd->data); |
1936 |
|
break; |
1937 |
|
} |
1938 |
|
|
1939 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
1940 |
|
|
1941 |
|
return FALSE; |
1942 |
|
} |
1943 |
|
} |
1944 |
|
#endif |
1945 |
|
|
1946 |
priv->drag_counter = 0; |
priv->drag_counter = 0; |
1947 |
priv->drag_start_mouse_x = (int) event->x; |
priv->drag_start_mouse_x = (int) event->x; |
1948 |
priv->drag_start_mouse_y = (int) event->y; |
priv->drag_start_mouse_y = (int) event->y; |
1957 |
{ |
{ |
1958 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
1959 |
|
|
1960 |
|
#ifdef ENABLE_BALLOON |
1961 |
|
/* released inside the balloon? */ |
1962 |
|
if (osm_gps_map_in_balloon(priv, |
1963 |
|
event->x + EXTRA_BORDER, |
1964 |
|
event->y + EXTRA_BORDER)) |
1965 |
|
{ |
1966 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
1967 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
1968 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
1969 |
|
} |
1970 |
|
#endif |
1971 |
|
|
1972 |
if (priv->dragging) |
if (priv->dragging) |
1973 |
{ |
{ |
1974 |
priv->dragging = FALSE; |
priv->dragging = FALSE; |
1986 |
|
|
1987 |
priv->drag_mouse_dx = 0; |
priv->drag_mouse_dx = 0; |
1988 |
priv->drag_mouse_dy = 0; |
priv->drag_mouse_dy = 0; |
1989 |
priv->drag_counter = 0; |
priv->drag_counter = -1; |
1990 |
|
|
1991 |
return FALSE; |
return FALSE; |
1992 |
} |
} |
1993 |
|
|
1994 |
static gboolean |
static gboolean |
1995 |
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event); |
1996 |
|
|
1997 |
|
static gboolean |
1998 |
osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) |
osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) |
1999 |
{ |
{ |
2000 |
int x, y; |
int x, y; |
2014 |
if (!(state & GDK_BUTTON1_MASK)) |
if (!(state & GDK_BUTTON1_MASK)) |
2015 |
return FALSE; |
return FALSE; |
2016 |
|
|
2017 |
|
if (priv->drag_counter < 0) |
2018 |
|
return FALSE; |
2019 |
|
|
2020 |
priv->drag_counter++; |
priv->drag_counter++; |
2021 |
|
|
2022 |
// we havent dragged more than 6 pixels |
// we havent dragged more than 6 pixels |
2023 |
if (priv->drag_counter < 6) |
if (priv->drag_counter < 6) |
2024 |
return FALSE; |
return FALSE; |
2025 |
|
|
2026 |
|
#ifdef USE_MAEMO |
2027 |
|
/* reduce update frequency on maemo to keep screen update fluid */ |
2028 |
|
static guint32 last_time = 0; |
2029 |
|
|
2030 |
|
if(event->time - last_time < 100) return FALSE; |
2031 |
|
last_time = event->time; |
2032 |
|
#endif |
2033 |
|
|
2034 |
priv->dragging = TRUE; |
priv->dragging = TRUE; |
2035 |
|
|
2036 |
if (priv->map_auto_center) |
if (priv->map_auto_center) |
2039 |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
2040 |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
2041 |
|
|
2042 |
|
#ifdef ENABLE_OSD |
2043 |
|
if(priv->osd) { |
2044 |
|
/* undo OSD */ |
2045 |
|
priv->osd->restore (priv->osd); |
2046 |
|
|
2047 |
|
/* draw new OSD */ |
2048 |
|
priv->osd->draw (priv->osd, |
2049 |
|
EXTRA_BORDER - priv->drag_mouse_dx, |
2050 |
|
EXTRA_BORDER - priv->drag_mouse_dy); |
2051 |
|
} |
2052 |
|
#endif |
2053 |
|
|
2054 |
|
osm_gps_map_expose (widget, NULL); |
2055 |
|
|
2056 |
|
return FALSE; |
2057 |
|
} |
2058 |
|
|
2059 |
|
static gboolean |
2060 |
|
osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event) |
2061 |
|
{ |
2062 |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2063 |
|
|
2064 |
|
/* create pixmap */ |
2065 |
|
if (priv->pixmap) |
2066 |
|
g_object_unref (priv->pixmap); |
2067 |
|
|
2068 |
|
priv->pixmap = gdk_pixmap_new ( |
2069 |
|
widget->window, |
2070 |
|
widget->allocation.width + EXTRA_BORDER * 2, |
2071 |
|
widget->allocation.height + EXTRA_BORDER * 2, |
2072 |
|
-1); |
2073 |
|
|
2074 |
|
#ifdef ENABLE_OSD |
2075 |
|
/* the osd needs some references to map internal objects */ |
2076 |
|
if(priv->osd) |
2077 |
|
{ |
2078 |
|
priv->osd->pixmap = priv->pixmap; |
2079 |
|
priv->osd->widget = widget; |
2080 |
|
} |
2081 |
|
#endif |
2082 |
|
|
2083 |
|
/* and gc, used for clipping (I think......) */ |
2084 |
|
if(priv->gc_map) |
2085 |
|
g_object_unref(priv->gc_map); |
2086 |
|
|
2087 |
|
priv->gc_map = gdk_gc_new(priv->pixmap); |
2088 |
|
|
2089 |
|
osm_gps_map_map_redraw(OSM_GPS_MAP(widget)); |
2090 |
|
|
2091 |
|
return FALSE; |
2092 |
|
} |
2093 |
|
|
2094 |
|
static gboolean |
2095 |
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event) |
2096 |
|
{ |
2097 |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2098 |
|
|
2099 |
gdk_draw_drawable ( |
gdk_draw_drawable ( |
2100 |
widget->window, |
widget->window, |
2101 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2102 |
priv->pixmap, |
priv->pixmap, |
2103 |
0,0, |
0,0, |
2104 |
priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER, |
priv->drag_mouse_dx - EXTRA_BORDER, |
2105 |
|
priv->drag_mouse_dy - EXTRA_BORDER, |
2106 |
-1,-1); |
-1,-1); |
2107 |
|
|
2108 |
//Paint white outside of the map if dragging. Its less |
//Paint white outside of the map if dragging. Its less |
2146 |
widget->allocation.width, |
widget->allocation.width, |
2147 |
-priv->drag_mouse_dy - EXTRA_BORDER); |
-priv->drag_mouse_dy - EXTRA_BORDER); |
2148 |
} |
} |
2149 |
|
#if 0 |
2150 |
return FALSE; |
if(!priv->dragging) |
2151 |
} |
gdk_draw_drawable ( |
|
|
|
|
static gboolean |
|
|
osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
/* create pixmap */ |
|
|
if (priv->pixmap) |
|
|
g_object_unref (priv->pixmap); |
|
|
|
|
|
priv->pixmap = gdk_pixmap_new ( |
|
|
widget->window, |
|
|
widget->allocation.width + EXTRA_BORDER * 2, |
|
|
widget->allocation.height + EXTRA_BORDER * 2, |
|
|
-1); |
|
|
|
|
|
/* and gc, used for clipping (I think......) */ |
|
|
if(priv->gc_map) |
|
|
g_object_unref(priv->gc_map); |
|
|
|
|
|
priv->gc_map = gdk_gc_new(priv->pixmap); |
|
|
|
|
|
osm_gps_map_map_redraw(OSM_GPS_MAP(widget)); |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
gdk_draw_drawable ( |
|
2152 |
widget->window, |
widget->window, |
2153 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2154 |
priv->pixmap, |
priv->pixmap, |
2155 |
event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER, |
event->area.x + EXTRA_BORDER, |
2156 |
|
event->area.y + EXTRA_BORDER, |
2157 |
event->area.x, event->area.y, |
event->area.x, event->area.y, |
2158 |
event->area.width, event->area.height); |
event->area.width, event->area.height); |
2159 |
|
#endif |
2160 |
return FALSE; |
return FALSE; |
2161 |
} |
} |
2162 |
|
|
2179 |
widget_class->button_press_event = osm_gps_map_button_press; |
widget_class->button_press_event = osm_gps_map_button_press; |
2180 |
widget_class->button_release_event = osm_gps_map_button_release; |
widget_class->button_release_event = osm_gps_map_button_release; |
2181 |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
2182 |
widget_class->scroll_event = _osm_gps_map_scroll; |
widget_class->scroll_event = osm_gps_map_scroll_event; |
2183 |
|
|
2184 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2185 |
PROP_AUTO_CENTER, |
PROP_AUTO_CENTER, |
2217 |
PROP_REPO_URI, |
PROP_REPO_URI, |
2218 |
g_param_spec_string ("repo-uri", |
g_param_spec_string ("repo-uri", |
2219 |
"repo uri", |
"repo uri", |
2220 |
"osm repo uri", |
"map source tile repository uri", |
2221 |
"http://tile.openstreetmap.org/#Z/#X/#Y.png", |
OSM_REPO_URI, |
2222 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2223 |
|
|
2224 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2225 |
PROP_PROXY_URI, |
PROP_PROXY_URI, |
2226 |
g_param_spec_string ("proxy-uri", |
g_param_spec_string ("proxy-uri", |
2227 |
"proxy uri", |
"proxy uri", |
2234 |
g_param_spec_string ("tile-cache", |
g_param_spec_string ("tile-cache", |
2235 |
"tile cache", |
"tile cache", |
2236 |
"osm local tile cache dir", |
"osm local tile cache dir", |
2237 |
"/tmp/Maps", |
NULL, |
2238 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2239 |
|
|
2240 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2262 |
"maximum zoom level", |
"maximum zoom level", |
2263 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2264 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2265 |
17, |
OSM_MAX_ZOOM, |
2266 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2267 |
|
|
2268 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2272 |
"minimum zoom level", |
"minimum zoom level", |
2273 |
MIN_ZOOM, /* minimum property value */ |
MIN_ZOOM, /* minimum property value */ |
2274 |
MAX_ZOOM, /* maximum property value */ |
MAX_ZOOM, /* maximum property value */ |
2275 |
1, |
OSM_MIN_ZOOM, |
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, |
2342 |
"radius of the gps point inner circle", |
"radius of the gps point inner circle", |
2343 |
0, /* minimum property value */ |
0, /* minimum property value */ |
2344 |
G_MAXINT, /* maximum property value */ |
G_MAXINT, /* maximum property value */ |
2345 |
5, |
10, |
2346 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2347 |
|
|
2348 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
2355 |
20, |
20, |
2356 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2357 |
|
|
2358 |
|
g_object_class_install_property (object_class, |
2359 |
|
PROP_MAP_SOURCE, |
2360 |
|
g_param_spec_int ("map-source", |
2361 |
|
"map source", |
2362 |
|
"map source ID", |
2363 |
|
-1, /* minimum property value */ |
2364 |
|
G_MAXINT, /* maximum property value */ |
2365 |
|
-1, |
2366 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2367 |
|
|
2368 |
|
g_object_class_install_property (object_class, |
2369 |
|
PROP_IMAGE_FORMAT, |
2370 |
|
g_param_spec_string ("image-format", |
2371 |
|
"image format", |
2372 |
|
"map source tile repository image format (jpg, png)", |
2373 |
|
OSM_IMAGE_FORMAT, |
2374 |
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
2375 |
|
} |
2376 |
|
|
2377 |
|
const char* |
2378 |
|
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
2379 |
|
{ |
2380 |
|
switch(source) |
2381 |
|
{ |
2382 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2383 |
|
return "None"; |
2384 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2385 |
|
return "OpenStreetMap"; |
2386 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2387 |
|
return "OpenStreetMap Renderer"; |
2388 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2389 |
|
return "OpenAerialMap"; |
2390 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2391 |
|
return "Maps-For-Free"; |
2392 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2393 |
|
return "Google Maps"; |
2394 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2395 |
|
return "Google Satellite"; |
2396 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2397 |
|
return "Google Hybrid"; |
2398 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2399 |
|
return "Virtual Earth"; |
2400 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2401 |
|
return "Virtual Earth Satellite"; |
2402 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2403 |
|
return "Virtual Earth Hybrid"; |
2404 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2405 |
|
return "Yahoo Maps"; |
2406 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2407 |
|
return "Yahoo Satellite"; |
2408 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2409 |
|
return "Yahoo Hybrid"; |
2410 |
|
default: |
2411 |
|
return NULL; |
2412 |
|
} |
2413 |
|
return NULL; |
2414 |
|
} |
2415 |
|
|
2416 |
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
2417 |
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
2418 |
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
2419 |
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
2420 |
|
const char* |
2421 |
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
2422 |
|
{ |
2423 |
|
switch(source) |
2424 |
|
{ |
2425 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2426 |
|
return "none://"; |
2427 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2428 |
|
return OSM_REPO_URI; |
2429 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2430 |
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
2431 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2432 |
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
2433 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2434 |
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
2435 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2436 |
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
2437 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2438 |
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
2439 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2440 |
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
2441 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2442 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
2443 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2444 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
2445 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2446 |
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
2447 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2448 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2449 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2450 |
|
/* TODO: Implement signed Y, aka U |
2451 |
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
2452 |
|
* x = tilex, |
2453 |
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
2454 |
|
* z = zoom - (MAX_ZOOM - 17)); |
2455 |
|
*/ |
2456 |
|
return NULL; |
2457 |
|
default: |
2458 |
|
return NULL; |
2459 |
|
} |
2460 |
|
return NULL; |
2461 |
|
} |
2462 |
|
|
2463 |
|
const char * |
2464 |
|
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
2465 |
|
{ |
2466 |
|
switch(source) { |
2467 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2468 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2469 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2470 |
|
return "png"; |
2471 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2472 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2473 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2474 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2475 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2476 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2477 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2478 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2479 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2480 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2481 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2482 |
|
return "jpg"; |
2483 |
|
default: |
2484 |
|
return "bin"; |
2485 |
|
} |
2486 |
|
return "bin"; |
2487 |
|
} |
2488 |
|
|
2489 |
|
|
2490 |
|
int |
2491 |
|
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
2492 |
|
{ |
2493 |
|
return 1; |
2494 |
|
} |
2495 |
|
|
2496 |
|
int |
2497 |
|
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
2498 |
|
{ |
2499 |
|
switch(source) { |
2500 |
|
case OSM_GPS_MAP_SOURCE_NULL: |
2501 |
|
return 18; |
2502 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
2503 |
|
return OSM_MAX_ZOOM; |
2504 |
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
2505 |
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
2506 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
2507 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
2508 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
2509 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
2510 |
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
2511 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
2512 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
2513 |
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
2514 |
|
return 17; |
2515 |
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
2516 |
|
return 11; |
2517 |
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
2518 |
|
return 18; |
2519 |
|
default: |
2520 |
|
return 17; |
2521 |
|
} |
2522 |
|
return 17; |
2523 |
} |
} |
2524 |
|
|
2525 |
void |
void |
2552 |
for(j=y1; j<=y2; j++) |
for(j=y1; j<=y2; j++) |
2553 |
{ |
{ |
2554 |
// x = i, y = j |
// x = i, y = j |
2555 |
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", |
2556 |
if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS)) |
priv->cache_dir, G_DIR_SEPARATOR, |
2557 |
|
zoom, G_DIR_SEPARATOR, |
2558 |
|
i, G_DIR_SEPARATOR, |
2559 |
|
j, |
2560 |
|
priv->image_format); |
2561 |
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
2562 |
{ |
{ |
2563 |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
2564 |
num_tiles++; |
num_tiles++; |
2620 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
2621 |
{ |
{ |
2622 |
int zoom_old; |
int zoom_old; |
2623 |
double factor = 1.0; |
double factor = 0.0; |
2624 |
int width_center, height_center; |
int width_center, height_center; |
2625 |
OsmGpsMapPrivate *priv; |
OsmGpsMapPrivate *priv; |
2626 |
|
|
2691 |
//cache w/h for speed, and add image to list |
//cache w/h for speed, and add image to list |
2692 |
im = g_new0(image_t,1); |
im = g_new0(image_t,1); |
2693 |
im->w = gdk_pixbuf_get_width(image); |
im->w = gdk_pixbuf_get_width(image); |
2694 |
im->h = gdk_pixbuf_get_width(image); |
im->h = gdk_pixbuf_get_height(image); |
2695 |
im->pt.rlat = deg2rad(latitude); |
im->pt.rlat = deg2rad(latitude); |
2696 |
im->pt.rlon = deg2rad(longitude); |
im->pt.rlon = deg2rad(longitude); |
2697 |
|
|
2704 |
} |
} |
2705 |
} |
} |
2706 |
|
|
2707 |
|
gboolean |
2708 |
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
2709 |
|
{ |
2710 |
|
OsmGpsMapPrivate *priv = map->priv; |
2711 |
|
if (priv->images) { |
2712 |
|
GSList *list; |
2713 |
|
for(list = priv->images; list != NULL; list = list->next) |
2714 |
|
{ |
2715 |
|
image_t *im = list->data; |
2716 |
|
if (im->image == image) |
2717 |
|
{ |
2718 |
|
priv->images = g_slist_remove_link(priv->images, list); |
2719 |
|
g_object_unref(im->image); |
2720 |
|
g_free(im); |
2721 |
|
osm_gps_map_map_redraw_idle(map); |
2722 |
|
return TRUE; |
2723 |
|
} |
2724 |
|
} |
2725 |
|
} |
2726 |
|
return FALSE; |
2727 |
|
} |
2728 |
|
|
2729 |
void |
void |
2730 |
osm_gps_map_clear_images (OsmGpsMap *map) |
osm_gps_map_clear_images (OsmGpsMap *map) |
2731 |
{ |
{ |
2917 |
osm_gps_map_map_redraw_idle (map); |
osm_gps_map_map_redraw_idle (map); |
2918 |
} |
} |
2919 |
|
|
2920 |
|
float |
2921 |
|
osm_gps_map_get_scale(OsmGpsMap *map) |
2922 |
|
{ |
2923 |
|
OsmGpsMapPrivate *priv; |
2924 |
|
|
2925 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
2926 |
|
priv = map->priv; |
2927 |
|
|
2928 |
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
2929 |
|
} |
2930 |
|
|
2931 |
|
#ifdef ENABLE_BALLOON |
2932 |
|
void |
2933 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
2934 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
2935 |
|
{ |
2936 |
|
OsmGpsMapPrivate *priv; |
2937 |
|
|
2938 |
|
/* remove and previously installed balloon */ |
2939 |
|
osm_gps_map_clear_balloon (map); |
2940 |
|
|
2941 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2942 |
|
priv = map->priv; |
2943 |
|
|
2944 |
|
priv->balloon.coo->rlat = deg2rad(latitude); |
2945 |
|
priv->balloon.coo->rlon = deg2rad(longitude); |
2946 |
|
priv->balloon.valid = TRUE; |
2947 |
|
|
2948 |
|
priv->balloon.cb = cb; |
2949 |
|
priv->balloon.data = data; |
2950 |
|
|
2951 |
|
// this redraws the map |
2952 |
|
osm_gps_map_map_redraw_idle(map); |
2953 |
|
} |
2954 |
|
|
2955 |
|
void |
2956 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
2957 |
|
{ |
2958 |
|
OsmGpsMapPrivate *priv; |
2959 |
|
|
2960 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2961 |
|
priv = map->priv; |
2962 |
|
|
2963 |
|
priv->balloon.valid = FALSE; |
2964 |
|
|
2965 |
|
osm_gps_map_map_redraw_idle(map); |
2966 |
|
} |
2967 |
|
#endif |
2968 |
|
|
2969 |
|
#ifdef ENABLE_OSD |
2970 |
|
|
2971 |
|
void |
2972 |
|
osm_gps_map_redraw (OsmGpsMap *map) |
2973 |
|
{ |
2974 |
|
osm_gps_map_map_redraw_idle(map); |
2975 |
|
} |
2976 |
|
|
2977 |
|
osm_gps_map_osd_t *osm_gps_map_osd_get(OsmGpsMap *map) { |
2978 |
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL); |
2979 |
|
return map->priv->osd; |
2980 |
|
} |
2981 |
|
|
2982 |
|
void osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd) { |
2983 |
|
OsmGpsMapPrivate *priv; |
2984 |
|
|
2985 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
2986 |
|
|
2987 |
|
priv = map->priv; |
2988 |
|
g_return_if_fail (!priv->osd); |
2989 |
|
|
2990 |
|
priv->osd = osd; |
2991 |
|
} |
2992 |
|
|
2993 |
|
#endif |