Diff of /trunk/src/osm-gps-map.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 32 by harbaum, Tue Jul 28 13:21:22 2009 UTC revision 57 by harbaum, Sun Aug 16 19:29:01 2009 UTC
# Line 33  Line 33 
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    
# Line 83  struct _OsmGpsMapPrivate Line 84  struct _OsmGpsMapPrivate
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;
# Line 95  struct _OsmGpsMapPrivate Line 98  struct _OsmGpsMapPrivate
98      coord_t *gps;      coord_t *gps;
99      gboolean gps_valid;      gboolean gps_valid;
100    
101        //a balloon with additional info
102        coord_t *balloon;
103        gboolean balloon_valid;
104    
105      //additional images or tracks added to the map      //additional images or tracks added to the map
106      GSList *tracks;      GSList *tracks;
107      GSList *images;      GSList *images;
# Line 104  struct _OsmGpsMapPrivate Line 111  struct _OsmGpsMapPrivate
111      GdkGC *gc_map;      GdkGC *gc_map;
112    
113      //The tile painted when one cannot be found      //The tile painted when one cannot be found
114      //GdkPixbuf *missing_tile;      GdkPixbuf *null_tile;
115    
116      //For tracking click and drag      //For tracking click and drag
117      int drag_counter;      int drag_counter;
# Line 157  enum Line 164  enum
164      PROP_TILES_QUEUED,      PROP_TILES_QUEUED,
165      PROP_GPS_TRACK_WIDTH,      PROP_GPS_TRACK_WIDTH,
166      PROP_GPS_POINT_R1,      PROP_GPS_POINT_R1,
167      PROP_GPS_POINT_R2      PROP_GPS_POINT_R2,
168        PROP_MAP_SOURCE,
169        PROP_IMAGE_FORMAT
170  };  };
171    
172  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);
# Line 171  static gchar    *replace_map_uri(OsmGpsM Line 180  static gchar    *replace_map_uri(OsmGpsM
180  static void     osm_gps_map_print_images (OsmGpsMap *map);  static void     osm_gps_map_print_images (OsmGpsMap *map);
181  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);
182  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);
183    #ifdef LIBSOUP22
184    static void     osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data);
185    #else
186    static void     osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data);
187    #endif
188  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);
189  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);
190  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);
# Line 420  my_log_handler (const gchar * log_domain Line 434  my_log_handler (const gchar * log_domain
434          g_log_default_handler (log_domain, log_level, message, user_data);          g_log_default_handler (log_domain, log_level, message, user_data);
435  }  }
436    
437    static float
438    osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon)
439    {
440        /* world at zoom 1 == 512 pixels */
441        return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom));
442    }
443    
444  /* clears the trip list and all resources */  /* clears the trip list and all resources */
445  static void  static void
446  osm_gps_map_free_trip (OsmGpsMap *map)  osm_gps_map_free_trip (OsmGpsMap *map)
# Line 529  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 550  osm_gps_map_draw_gps_point (OsmGpsMap *m
550          int x, y;          int x, y;
551          int r = priv->ui_gps_point_inner_radius;          int r = priv->ui_gps_point_inner_radius;
552          int r2 = priv->ui_gps_point_outer_radius;          int r2 = priv->ui_gps_point_outer_radius;
553            // int lw = priv->ui_gps_track_width;
554          int mr = MAX(r,r2);          int mr = MAX(r,r2);
555    
556          map_x0 = priv->map_x - EXTRA_BORDER;          map_x0 = priv->map_x - EXTRA_BORDER;
# Line 539  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 561  osm_gps_map_draw_gps_point (OsmGpsMap *m
561          cairo_t *cr;          cairo_t *cr;
562          cairo_pattern_t *pat;          cairo_pattern_t *pat;
563  #else  #else
         int lw = priv->ui_gps_track_width;  
564          GdkColor color;          GdkColor color;
565          GdkGC *marker;          GdkGC *marker;
566  #endif  #endif
# Line 614  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 635  osm_gps_map_draw_gps_point (OsmGpsMap *m
635                                      (mr*2)+lw+lw);                                      (mr*2)+lw+lw);
636  #endif  #endif
637      }      }
638    }
639    
640    /* most visual effects are hardcoded by now, but may be made */
641    /* available via properties later */
642    #define BALLOON_CORNER_RADIUS         20
643    #define BALLOON_WIDTH                150
644    #define BALLOON_HEIGHT                75
645    #define BALLOON_TRANSPARENCY         0.8
646    #define POINTER_HEIGHT                20
647    #define POINTER_FOOT_WIDTH            20
648    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
649    #define BALLOON_SHADOW                5
650    #define BALLOON_SHADOW_TRANSPARENCY  0.2
651    
652    /* draw the bubble shape. this is used twice, once for the shape and once */
653    /* for the shadow */
654    static void
655    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
656           gboolean bottom, int px, int py, int px0, int px1) {
657    
658        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
659        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);
660        if(!bottom) {
661            /* insert bottom/left pointer */
662            cairo_line_to (cr, px1, y0);
663            cairo_line_to (cr, px, py);
664            cairo_line_to (cr, px0, y0);
665        }
666    
667        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
668        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS);
669        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
670        cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);
671        if(bottom) {
672            /* insert bottom/left pointer */
673            cairo_line_to (cr, px0, y1);
674            cairo_line_to (cr, px, py);
675            cairo_line_to (cr, px1, y1);
676        }
677    
678        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
679        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS);
680    
681        cairo_close_path (cr);
682    }
683    
684    /* http://cairographics.org/samples/ */
685    static void
686    osm_gps_map_draw_balloon_int (OsmGpsMap *map)
687    {
688        OsmGpsMapPrivate *priv = map->priv;
689    
690        if (priv->balloon_valid) {
691    
692            /* ------- convert given coordinate into screen position --------- */
693            int x0 = lon2pixel(priv->map_zoom, priv->balloon->rlon) -
694                priv->map_x + EXTRA_BORDER;
695            int y0 = lat2pixel(priv->map_zoom, priv->balloon->rlat) -
696                priv->map_y + EXTRA_BORDER;
697    
698            /* check position of this relative to screen center to determine */
699            /* pointer direction ... */
700            int pointer_x = x0, pointer_x0, pointer_x1;
701            int pointer_y = y0;
702    
703            /* ... and calculate position */
704            if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) {
705                x0 -= BALLOON_WIDTH - POINTER_OFFSET;
706                pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
707                pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
708            } else {
709                x0 -= POINTER_OFFSET;
710                pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
711                pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
712            }
713    
714            gboolean bottom = FALSE;
715            if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) {
716                bottom = TRUE;
717                y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;
718            } else
719                y0 += POINTER_HEIGHT;
720    
721            /* calculate bottom/right of box */
722            int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
723    
724    #ifdef USE_CAIRO
725            cairo_t *cr = gdk_cairo_create(priv->pixmap);
726    
727            /* --------- draw shadow --------------- */
728            osm_gps_map_draw_balloon_shape (cr,
729                        x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
730                        x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
731                        bottom, pointer_x, pointer_y,
732                        pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
733    
734            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
735            cairo_fill_preserve (cr);
736            cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
737            cairo_set_line_width (cr, 0);
738            cairo_stroke (cr);
739    
740            /* --------- draw main shape ----------- */
741            osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
742                        bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
743    
744            cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
745            cairo_fill_preserve (cr);
746            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
747            cairo_set_line_width (cr, 1);
748            cairo_stroke (cr);
749    
750    
751            /* ---------- draw close button --------- */
752    
753            int cx = x1 - BALLOON_CORNER_RADIUS*3/4;
754            int cy = y0 + BALLOON_CORNER_RADIUS*3/4;
755            int crad = BALLOON_CORNER_RADIUS/3;
756    
757            cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
758            cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
759            cairo_fill_preserve (cr);
760            cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
761            cairo_set_line_width (cr, 1);
762            cairo_stroke(cr);
763    
764            int cs = crad/2;
765            cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
766            cairo_set_line_width (cr, 3);
767            cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
768            cairo_move_to (cr, cx - cs, cy - cs);
769            cairo_line_to (cr, cx + cs, cy + cs);
770            cairo_stroke (cr);
771            cairo_move_to (cr, cx + cs, cy - cs);
772            cairo_line_to (cr, cx - cs, cy + cs);
773            cairo_stroke (cr);
774    
775    
776            gtk_widget_queue_draw_area (GTK_WIDGET(map),
777                                        x0, y0, BALLOON_WIDTH,
778                                        BALLOON_HEIGHT + POINTER_HEIGHT);
779    #else
780    #warning "Balloon display lacks a non-cairo implementation!"
781    #endif
782        }
783  }  }
784    
785  static void  static void
# Line 621  osm_gps_map_blit_tile(OsmGpsMap *map, Gd Line 787  osm_gps_map_blit_tile(OsmGpsMap *map, Gd
787  {  {
788      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
789    
790      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);  
791    
792      /* draw pixbuf onto pixmap */      /* draw pixbuf onto pixmap */
793      gdk_draw_pixbuf (priv->pixmap,      gdk_draw_pixbuf (priv->pixmap,
# Line 654  static void Line 819  static void
819  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)
820  #endif  #endif
821  {  {
822      int fd;      FILE *file;
823      tile_download_t *dl = (tile_download_t *)user_data;      tile_download_t *dl = (tile_download_t *)user_data;
824      OsmGpsMap *map = OSM_GPS_MAP(dl->map);      OsmGpsMap *map = OSM_GPS_MAP(dl->map);
825      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 667  osm_gps_map_tile_download_complete (Soup Line 832  osm_gps_map_tile_download_complete (Soup
832          {          {
833              if (g_mkdir_with_parents(dl->folder,0700) == 0)              if (g_mkdir_with_parents(dl->folder,0700) == 0)
834              {              {
835                  fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);                  file = g_fopen(dl->filename, "wb");
836                  if (fd != -1)                  if (file != NULL)
837                  {                  {
838                      write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg));                      fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file);
839                      file_saved = TRUE;                      file_saved = TRUE;
840                        g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);
841                        fclose (file);
842    
                     g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);  
                     close (fd);  
843                  }                  }
844              }              }
845              else              else
# Line 687  osm_gps_map_tile_download_complete (Soup Line 852  osm_gps_map_tile_download_complete (Soup
852          {          {
853              GdkPixbuf *pixbuf = NULL;              GdkPixbuf *pixbuf = NULL;
854    
855                /* if the file was actually stored on disk, we can simply */
856                /* load and decode it from that file */
857              if (priv->cache_dir)              if (priv->cache_dir)
858              {              {
859                  if (file_saved)                  if (file_saved)
# Line 720  osm_gps_map_tile_download_complete (Soup Line 887  osm_gps_map_tile_download_complete (Soup
887                      g_warning("Error: Unable to determine image file format");                      g_warning("Error: Unable to determine image file format");
888                  }                  }
889              }              }
890    
891              /* Store the tile into the cache */              /* Store the tile into the cache */
892              if (G_LIKELY (pixbuf))              if (G_LIKELY (pixbuf))
893              {              {
# Line 735  osm_gps_map_tile_download_complete (Soup Line 902  osm_gps_map_tile_download_complete (Soup
902                   * we are using it as a key in the hash table */                   * we are using it as a key in the hash table */
903                  dl->filename = NULL;                  dl->filename = NULL;
904              }              }
   
905              osm_gps_map_map_redraw_idle (map);              osm_gps_map_map_redraw_idle (map);
906          }          }
907          g_hash_table_remove(priv->tile_queue, dl->uri);          g_hash_table_remove(priv->tile_queue, dl->uri);
# Line 794  osm_gps_map_download_tile (OsmGpsMap *ma Line 960  osm_gps_map_download_tile (OsmGpsMap *ma
960          g_free(dl->uri);          g_free(dl->uri);
961          g_free(dl);          g_free(dl);
962      } else {      } else {
963          dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x);          dl->folder = g_strdup_printf("%s%c%d%c%d%c",
964          dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y);                              priv->cache_dir, G_DIR_SEPARATOR,
965                                zoom, G_DIR_SEPARATOR,
966                                x, G_DIR_SEPARATOR);
967            dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
968                                priv->cache_dir, G_DIR_SEPARATOR,
969                                zoom, G_DIR_SEPARATOR,
970                                x, G_DIR_SEPARATOR,
971                                y,
972                                priv->image_format);
973          dl->map = map;          dl->map = map;
974          dl->redraw = redraw;          dl->redraw = redraw;
975    
# Line 813  osm_gps_map_download_tile (OsmGpsMap *ma Line 987  osm_gps_map_download_tile (OsmGpsMap *ma
987                      if (cookie) {                      if (cookie) {
988                          g_debug("Adding Google Cookie");                          g_debug("Adding Google Cookie");
989                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);
   
990                      }                      }
991                  }                  }
992              }              }
# Line 835  osm_gps_map_load_cached_tile (OsmGpsMap Line 1008  osm_gps_map_load_cached_tile (OsmGpsMap
1008  {  {
1009      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1010      gchar *filename;      gchar *filename;
1011      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf = NULL;
1012      OsmCachedTile *tile;      OsmCachedTile *tile;
1013    
1014      filename = g_strdup_printf("%s/%u/%u/%u.png",      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1015                                 priv->cache_dir,                  priv->cache_dir, G_DIR_SEPARATOR,
1016                                 zoom, x, y);                  zoom, G_DIR_SEPARATOR,
1017                    x, G_DIR_SEPARATOR,
1018                    y,
1019                    priv->image_format);
1020    
1021      tile = g_hash_table_lookup (priv->tile_cache, filename);      tile = g_hash_table_lookup (priv->tile_cache, filename);
1022      if (tile)      if (tile)
1023      {      {
1024          g_free (filename);          g_free (filename);
1025      }      }
1026      else if (priv->cache_dir)      else
1027      {      {
1028          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1029          if (pixbuf)          if (pixbuf)
# Line 863  osm_gps_map_load_cached_tile (OsmGpsMap Line 1039  osm_gps_map_load_cached_tile (OsmGpsMap
1039      {      {
1040          tile->redraw_cycle = priv->redraw_cycle;          tile->redraw_cycle = priv->redraw_cycle;
1041          pixbuf = g_object_ref (tile->pixbuf);          pixbuf = g_object_ref (tile->pixbuf);
1042      } else      }
         pixbuf = NULL;  
1043    
1044      return pixbuf;      return pixbuf;
1045  }  }
# Line 928  static void Line 1103  static void
1103  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)
1104  {  {
1105      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1106        gchar *filename;
1107      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf;
1108    
1109      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);
1110    
1111      /* try to get file from internal cache */      if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) {
1112      pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y);          osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y);
1113            return;
1114        }
1115    
1116      /* 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",
1117      if (priv->cache_dir && !pixbuf)                  priv->cache_dir, G_DIR_SEPARATOR,
1118      {                  zoom, G_DIR_SEPARATOR,
1119          gchar *filename;                  x, G_DIR_SEPARATOR,
1120          filename = g_strdup_printf("%s/%u/%u/%u.png",                  y,
1121                                     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);  
         }  
1122    
1123          g_free(filename);      /* try to get file from internal cache first */
1124      }      if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y)))
1125            pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1126    
1127      if (G_LIKELY(pixbuf))      if(pixbuf)
1128      {      {
1129            g_debug("Found tile %s", filename);
1130          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);
1131          g_object_unref (pixbuf);          g_object_unref (pixbuf);
1132      }      }
# Line 984  osm_gps_map_load_tile (OsmGpsMap *map, i Line 1157  osm_gps_map_load_tile (OsmGpsMap *map, i
1157                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);
1158          }          }
1159      }      }
1160        g_free(filename);
1161  }  }
1162    
1163  static void  static void
# Line 1077  osm_gps_map_print_track (OsmGpsMap *map, Line 1251  osm_gps_map_print_track (OsmGpsMap *map,
1251    
1252      map_x0 = priv->map_x - EXTRA_BORDER;      map_x0 = priv->map_x - EXTRA_BORDER;
1253      map_y0 = priv->map_y - EXTRA_BORDER;      map_y0 = priv->map_y - EXTRA_BORDER;
   
1254      for(list = trackpoint_list; list != NULL; list = list->next)      for(list = trackpoint_list; list != NULL; list = list->next)
1255      {      {
1256          coord_t *tp = list->data;          coord_t *tp = list->data;
# Line 1132  osm_gps_map_print_tracks (OsmGpsMap *map Line 1305  osm_gps_map_print_tracks (OsmGpsMap *map
1305    
1306      if (priv->show_trip_history)      if (priv->show_trip_history)
1307          osm_gps_map_print_track (map, priv->trip_history);          osm_gps_map_print_track (map, priv->trip_history);
1308    
1309      if (priv->tracks)      if (priv->tracks)
1310      {      {
         g_debug("TRACK");  
1311          GSList* tmp = priv->tracks;          GSList* tmp = priv->tracks;
1312          while (tmp != NULL)          while (tmp != NULL)
1313          {          {
# Line 1144  osm_gps_map_print_tracks (OsmGpsMap *map Line 1317  osm_gps_map_print_tracks (OsmGpsMap *map
1317      }      }
1318  }  }
1319    
1320  static gboolean  static gboolean
1321  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)
1322  {  {
1323      return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);     return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);
1324  }  }
1325    
1326  static void  static void
1327  osm_gps_map_purge_cache (OsmGpsMap *map)  osm_gps_map_purge_cache (OsmGpsMap *map)
1328  {  {
1329      OsmGpsMapPrivate *priv = map->priv;     OsmGpsMapPrivate *priv = map->priv;
1330    
1331      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)
1332          return;         return;
1333    
1334      /* 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
1335       * during the last redraw operation */      * during the last redraw operation */
1336      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);
1337  }  }
1338    
1339  static gboolean  static gboolean
# Line 1193  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1366  osm_gps_map_map_redraw (OsmGpsMap *map)
1366      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1367      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1368      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1369        osm_gps_map_draw_balloon_int(map);
1370    
1371      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1372      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1224  osm_gps_map_init (OsmGpsMap *object) Line 1398  osm_gps_map_init (OsmGpsMap *object)
1398      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1399      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1400    
1401        priv->balloon = g_new0(coord_t, 1);
1402        priv->balloon_valid = FALSE;
1403    
1404      priv->tracks = NULL;      priv->tracks = NULL;
1405      priv->images = NULL;      priv->images = NULL;
1406    
# Line 1236  osm_gps_map_init (OsmGpsMap *object) Line 1413  osm_gps_map_init (OsmGpsMap *object)
1413      priv->uri_format = 0;      priv->uri_format = 0;
1414      priv->the_google = FALSE;      priv->the_google = FALSE;
1415    
1416        priv->map_source = -1;
1417    
1418  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1419      //Change naumber of concurrent connections option?      //Change naumber of concurrent connections option?
1420      priv->soup_session = soup_session_async_new_with_options(      priv->soup_session = soup_session_async_new_with_options(
# Line 1289  osm_gps_map_constructor (GType gtype, gu Line 1468  osm_gps_map_constructor (GType gtype, gu
1468  {  {
1469      GObject *object;      GObject *object;
1470      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
1471        OsmGpsMap *map;
1472        const char *uri;
1473    
1474      //Always chain up to the parent constructor      //Always chain up to the parent constructor
1475      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);
1476        map = OSM_GPS_MAP(object);
1477      priv = OSM_GPS_MAP_PRIVATE(object);      priv = OSM_GPS_MAP_PRIVATE(object);
1478    
1479        //user can specify a map source ID, or a repo URI as the map source
1480        uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);
1481        if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {
1482            g_debug("Using null source");
1483            priv->map_source = OSM_GPS_MAP_SOURCE_NULL;
1484    
1485            priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256);
1486            gdk_pixbuf_fill(priv->null_tile, 0xcccccc00);
1487        }
1488        else if (priv->map_source >= 0) {
1489            //check if the source given is valid
1490            uri = osm_gps_map_source_get_repo_uri(priv->map_source);
1491            if (uri) {
1492                g_debug("Setting map source from ID");
1493                g_free(priv->repo_uri);
1494    
1495                priv->repo_uri = g_strdup(uri);
1496                priv->image_format = g_strdup(
1497                    osm_gps_map_source_get_image_format(priv->map_source));
1498                priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source);
1499                priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source);
1500            }
1501        }
1502    
1503      if (!priv->cache_dir_is_full_path) {      if (!priv->cache_dir_is_full_path) {
1504  #ifdef G_CHECKSUM_MD5  #ifdef G_CHECKSUM_MD5
1505          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);
# Line 1304  osm_gps_map_constructor (GType gtype, gu Line 1510  osm_gps_map_constructor (GType gtype, gu
1510          if (priv->cache_dir) {          if (priv->cache_dir) {
1511              char *old = priv->cache_dir;              char *old = priv->cache_dir;
1512              //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
1513              priv->cache_dir = g_strdup_printf("%s/%s", old, md5);              priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5);
1514              g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);              g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);
1515              g_free(old);              g_free(old);
1516            } else {
1517                //the new cachedir is the current dir + the md5 of the repo_uri
1518                priv->cache_dir = g_strdup(md5);
1519          }          }
1520    
1521          g_free(md5);          g_free(md5);
1522      }      }
1523    
1524        inspect_map_uri(map);
1525    
1526      return object;      return object;
1527  }  }
1528    
# Line 1338  osm_gps_map_dispose (GObject *object) Line 1549  osm_gps_map_dispose (GObject *object)
1549      if(priv->pixmap)      if(priv->pixmap)
1550          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
1551    
1552        if (priv->null_tile)
1553            g_object_unref (priv->null_tile);
1554    
1555      if(priv->gc_map)      if(priv->gc_map)
1556          g_object_unref(priv->gc_map);          g_object_unref(priv->gc_map);
1557    
1558      if (priv->idle_map_redraw != 0)      if (priv->idle_map_redraw != 0)
1559          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1560    
1561        g_free(priv->gps);
1562        g_free(priv->balloon);
1563    
1564      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
1565  }  }
1566    
# Line 1355  osm_gps_map_finalize (GObject *object) Line 1572  osm_gps_map_finalize (GObject *object)
1572    
1573      g_free(priv->cache_dir);      g_free(priv->cache_dir);
1574      g_free(priv->repo_uri);      g_free(priv->repo_uri);
1575        g_free(priv->image_format);
1576    
1577      osm_gps_map_free_trip(map);      osm_gps_map_free_trip(map);
1578      osm_gps_map_free_tracks(map);      osm_gps_map_free_tracks(map);
# Line 1385  osm_gps_map_set_property (GObject *objec Line 1603  osm_gps_map_set_property (GObject *objec
1603              break;              break;
1604          case PROP_REPO_URI:          case PROP_REPO_URI:
1605              priv->repo_uri = g_value_dup_string (value);              priv->repo_uri = g_value_dup_string (value);
             inspect_map_uri(map);  
1606              break;              break;
1607          case PROP_PROXY_URI:          case PROP_PROXY_URI:
1608              if ( g_value_get_string(value) ) {              if ( g_value_get_string(value) ) {
   
1609                  priv->proxy_uri = g_value_dup_string (value);                  priv->proxy_uri = g_value_dup_string (value);
1610                  g_debug("Setting proxy server: %s", priv->proxy_uri);                  g_debug("Setting proxy server: %s", priv->proxy_uri);
1611    
1612  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1613                  GValue val = {0};                  GValue val = {0};
1614    
1615                  SoupURI* uri = soup_uri_new(priv->proxy_uri);                  SoupURI* uri = soup_uri_new(priv->proxy_uri);
1616                  g_value_init(&val, SOUP_TYPE_URI);                  g_value_init(&val, SOUP_TYPE_URI);
1617                  g_value_take_boxed(&val, uri);                  g_value_take_boxed(&val, uri);
# Line 1403  osm_gps_map_set_property (GObject *objec Line 1621  osm_gps_map_set_property (GObject *objec
1621                  SoupUri* uri = soup_uri_new(priv->proxy_uri);                  SoupUri* uri = soup_uri_new(priv->proxy_uri);
1622                  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);
1623  #endif  #endif
                 soup_uri_free(uri);  
1624              } else              } else
1625                  priv->proxy_uri = NULL;                  priv->proxy_uri = NULL;
1626    
1627              break;              break;
1628          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1629              priv->cache_dir = g_value_dup_string (value);              if ( g_value_get_string(value) )
1630                    priv->cache_dir = g_value_dup_string (value);
1631              break;              break;
1632          case PROP_TILE_CACHE_DIR_IS_FULL_PATH:          case PROP_TILE_CACHE_DIR_IS_FULL_PATH:
1633              priv->cache_dir_is_full_path = g_value_get_boolean (value);              priv->cache_dir_is_full_path = g_value_get_boolean (value);
# Line 1440  osm_gps_map_set_property (GObject *objec Line 1658  osm_gps_map_set_property (GObject *objec
1658          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1659              priv->ui_gps_point_outer_radius = g_value_get_int (value);              priv->ui_gps_point_outer_radius = g_value_get_int (value);
1660              break;              break;
1661            case PROP_MAP_SOURCE:
1662                priv->map_source = g_value_get_int (value);
1663                break;
1664            case PROP_IMAGE_FORMAT:
1665                priv->image_format = g_value_dup_string (value);
1666                break;
1667          default:          default:
1668              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1669              break;              break;
# Line 1517  osm_gps_map_get_property (GObject *objec Line 1741  osm_gps_map_get_property (GObject *objec
1741          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1742              g_value_set_int(value, priv->ui_gps_point_outer_radius);              g_value_set_int(value, priv->ui_gps_point_outer_radius);
1743              break;              break;
1744            case PROP_MAP_SOURCE:
1745                g_value_set_int(value, priv->map_source);
1746                break;
1747            case PROP_IMAGE_FORMAT:
1748                g_value_set_string(value, priv->image_format);
1749                break;
1750          default:          default:
1751              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1752              break;              break;
# Line 1524  osm_gps_map_get_property (GObject *objec Line 1754  osm_gps_map_get_property (GObject *objec
1754  }  }
1755    
1756  static gboolean  static gboolean
1757  _osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll  *event)  osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll  *event)
1758  {  {
1759      OsmGpsMap *map = OSM_GPS_MAP(widget);      OsmGpsMap *map = OSM_GPS_MAP(widget);
1760      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 1730  osm_gps_map_class_init (OsmGpsMapClass * Line 1960  osm_gps_map_class_init (OsmGpsMapClass *
1960      widget_class->button_press_event = osm_gps_map_button_press;      widget_class->button_press_event = osm_gps_map_button_press;
1961      widget_class->button_release_event = osm_gps_map_button_release;      widget_class->button_release_event = osm_gps_map_button_release;
1962      widget_class->motion_notify_event = osm_gps_map_motion_notify;      widget_class->motion_notify_event = osm_gps_map_motion_notify;
1963      widget_class->scroll_event = _osm_gps_map_scroll;      widget_class->scroll_event = osm_gps_map_scroll_event;
1964    
1965      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
1966                                       PROP_AUTO_CENTER,                                       PROP_AUTO_CENTER,
# Line 1768  osm_gps_map_class_init (OsmGpsMapClass * Line 1998  osm_gps_map_class_init (OsmGpsMapClass *
1998                                       PROP_REPO_URI,                                       PROP_REPO_URI,
1999                                       g_param_spec_string ("repo-uri",                                       g_param_spec_string ("repo-uri",
2000                                                            "repo uri",                                                            "repo uri",
2001                                                            "osm repo uri",                                                            "map source tile repository uri",
2002                                                            "http://tile.openstreetmap.org/#Z/#X/#Y.png",                                                            OSM_REPO_URI,
2003                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2004    
2005      g_object_class_install_property (object_class,       g_object_class_install_property (object_class,
2006                                       PROP_PROXY_URI,                                       PROP_PROXY_URI,
2007                                       g_param_spec_string ("proxy-uri",                                       g_param_spec_string ("proxy-uri",
2008                                                            "proxy uri",                                                            "proxy uri",
# Line 1785  osm_gps_map_class_init (OsmGpsMapClass * Line 2015  osm_gps_map_class_init (OsmGpsMapClass *
2015                                       g_param_spec_string ("tile-cache",                                       g_param_spec_string ("tile-cache",
2016                                                            "tile cache",                                                            "tile cache",
2017                                                            "osm local tile cache dir",                                                            "osm local tile cache dir",
2018                                                            "/tmp/Maps",                                                            NULL,
2019                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2020    
2021      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1813  osm_gps_map_class_init (OsmGpsMapClass * Line 2043  osm_gps_map_class_init (OsmGpsMapClass *
2043                                                         "maximum zoom level",                                                         "maximum zoom level",
2044                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2045                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2046                                                         17,                                                         OSM_MAX_ZOOM,
2047                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2048    
2049      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1823  osm_gps_map_class_init (OsmGpsMapClass * Line 2053  osm_gps_map_class_init (OsmGpsMapClass *
2053                                                         "minimum zoom level",                                                         "minimum zoom level",
2054                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2055                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2056                                                         1,                                                         OSM_MIN_ZOOM,
2057                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2058    
2059      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1906  osm_gps_map_class_init (OsmGpsMapClass * Line 2136  osm_gps_map_class_init (OsmGpsMapClass *
2136                                                         20,                                                         20,
2137                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2138    
2139        g_object_class_install_property (object_class,
2140                                         PROP_MAP_SOURCE,
2141                                         g_param_spec_int ("map-source",
2142                                                           "map source",
2143                                                           "map source ID",
2144                                                           -1,           /* minimum property value */
2145                                                           G_MAXINT,    /* maximum property value */
2146                                                           -1,
2147                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2148    
2149        g_object_class_install_property (object_class,
2150                                         PROP_IMAGE_FORMAT,
2151                                         g_param_spec_string ("image-format",
2152                                                              "image format",
2153                                                              "map source tile repository image format (jpg, png)",
2154                                                              OSM_IMAGE_FORMAT,
2155                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2156    }
2157    
2158    const char*
2159    osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source)
2160    {
2161        switch(source)
2162        {
2163            case OSM_GPS_MAP_SOURCE_NULL:
2164                return "None";
2165            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2166                return "OpenStreetMap";
2167            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2168                return "OpenStreetMap Renderer";
2169            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2170                return "OpenAerialMap";
2171            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2172                return "Maps-For-Free";
2173            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2174                return "Google Maps";
2175            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2176                return "Google Satellite";
2177            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2178                return "Google Hybrid";
2179            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2180                return "Virtual Earth";
2181            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2182                return "Virtual Earth Satellite";
2183            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2184                return "Virtual Earth Hybrid";
2185            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2186                return "Yahoo Maps";
2187            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2188                return "Yahoo Satellite";
2189            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2190                return "Yahoo Hybrid";
2191            default:
2192                return NULL;
2193        }
2194        return NULL;
2195    }
2196    
2197    //http://www.internettablettalk.com/forums/showthread.php?t=5209
2198    //https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup
2199    //http://www.ponies.me.uk/maps/GoogleTileUtils.java
2200    //http://www.mgmaps.com/cache/MapTileCacher.perl
2201    const char*
2202    osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source)
2203    {
2204        switch(source)
2205        {
2206            case OSM_GPS_MAP_SOURCE_NULL:
2207                return "none://";
2208            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2209                return OSM_REPO_URI;
2210            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2211                return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";
2212            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2213                return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg";
2214            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2215                return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";
2216            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2217                return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z";
2218            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2219                return "http://khm#R.google.com/kh?n=404&v=3&t=#Q";
2220            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2221                return NULL; /* No longer working  "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */
2222            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2223                return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50";
2224            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2225                return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50";
2226            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2227                return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50";
2228            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2229            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2230            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2231                /* TODO: Implement signed Y, aka U
2232                 * http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d
2233                 *  x = tilex,
2234                 *  y = (1 << (MAX_ZOOM - zoom)) - tiley - 1,
2235                 *  z = zoom - (MAX_ZOOM - 17));
2236                 */
2237                return NULL;
2238            default:
2239                return NULL;
2240        }
2241        return NULL;
2242    }
2243    
2244    const char *
2245    osm_gps_map_source_get_image_format(OsmGpsMapSource_t source)
2246    {
2247        switch(source) {
2248            case OSM_GPS_MAP_SOURCE_NULL:
2249            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2250            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2251                return "png";
2252            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2253            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2254            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2255            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2256            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2257            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2258            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2259            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2260            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2261            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2262            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2263                return "jpg";
2264            default:
2265                return "bin";
2266        }
2267        return "bin";
2268    }
2269    
2270    
2271    int
2272    osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source)
2273    {
2274        return 1;
2275    }
2276    
2277    int
2278    osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source)
2279    {
2280        switch(source) {
2281            case OSM_GPS_MAP_SOURCE_NULL:
2282                return 18;
2283            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2284                return OSM_MAX_ZOOM;
2285            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2286            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2287            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2288            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2289            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2290            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2291            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2292            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2293            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2294            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2295                return 17;
2296            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2297                return 11;
2298            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2299                return 18;
2300            default:
2301                return 17;
2302        }
2303        return 17;
2304  }  }
2305    
2306  void  void
# Line 1938  osm_gps_map_download_maps (OsmGpsMap *ma Line 2333  osm_gps_map_download_maps (OsmGpsMap *ma
2333                  for(j=y1; j<=y2; j++)                  for(j=y1; j<=y2; j++)
2334                  {                  {
2335                      // x = i, y = j                      // x = i, y = j
2336                      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",
2337                      if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS))                                      priv->cache_dir, G_DIR_SEPARATOR,
2338                                        zoom, G_DIR_SEPARATOR,
2339                                        i, G_DIR_SEPARATOR,
2340                                        j,
2341                                        priv->image_format);
2342                        if (!g_file_test(filename, G_FILE_TEST_EXISTS))
2343                      {                      {
2344                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);
2345                          num_tiles++;                          num_tiles++;
# Line 2001  int Line 2401  int
2401  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)
2402  {  {
2403      int zoom_old;      int zoom_old;
2404      double factor = 1.0;      double factor = 0.0;
2405      int width_center, height_center;      int width_center, height_center;
2406      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
2407    
# Line 2072  osm_gps_map_add_image (OsmGpsMap *map, f Line 2472  osm_gps_map_add_image (OsmGpsMap *map, f
2472          //cache w/h for speed, and add image to list          //cache w/h for speed, and add image to list
2473          im = g_new0(image_t,1);          im = g_new0(image_t,1);
2474          im->w = gdk_pixbuf_get_width(image);          im->w = gdk_pixbuf_get_width(image);
2475          im->h = gdk_pixbuf_get_width(image);          im->h = gdk_pixbuf_get_height(image);
2476          im->pt.rlat = deg2rad(latitude);          im->pt.rlat = deg2rad(latitude);
2477          im->pt.rlon = deg2rad(longitude);          im->pt.rlon = deg2rad(longitude);
2478    
# Line 2085  osm_gps_map_add_image (OsmGpsMap *map, f Line 2485  osm_gps_map_add_image (OsmGpsMap *map, f
2485      }      }
2486  }  }
2487    
2488    gboolean
2489    osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image)
2490    {
2491        OsmGpsMapPrivate *priv = map->priv;
2492        if (priv->images) {
2493            GSList *list;
2494            for(list = priv->images; list != NULL; list = list->next)
2495            {
2496                image_t *im = list->data;
2497                    if (im->image == image)
2498                    {
2499                            priv->images = g_slist_remove_link(priv->images, list);
2500                            g_object_unref(im->image);
2501                            g_free(im);
2502                            osm_gps_map_map_redraw_idle(map);
2503                            return TRUE;
2504                    }
2505            }
2506        }
2507        return FALSE;
2508    }
2509    
2510  void  void
2511  osm_gps_map_clear_images (OsmGpsMap *map)  osm_gps_map_clear_images (OsmGpsMap *map)
2512  {  {
# Line 2276  osm_gps_map_scroll (OsmGpsMap *map, gint Line 2698  osm_gps_map_scroll (OsmGpsMap *map, gint
2698      osm_gps_map_map_redraw_idle (map);      osm_gps_map_map_redraw_idle (map);
2699  }  }
2700    
2701    float
2702    osm_gps_map_get_scale(OsmGpsMap *map)
2703    {
2704        OsmGpsMapPrivate *priv;
2705    
2706        g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN);
2707        priv = map->priv;
2708    
2709        return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);
2710    }
2711    
2712    void
2713    osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude)
2714    {
2715        OsmGpsMapPrivate *priv;
2716    
2717        /* remove and previously installed balloon */
2718        osm_gps_map_clear_balloon (map);
2719    
2720        g_return_if_fail (OSM_IS_GPS_MAP (map));
2721        priv = map->priv;
2722    
2723        priv->balloon->rlat = deg2rad(latitude);
2724        priv->balloon->rlon = deg2rad(longitude);
2725        priv->balloon_valid = TRUE;
2726    
2727        // this redraws the map
2728        osm_gps_map_map_redraw_idle(map);
2729    }
2730    
2731    void
2732    osm_gps_map_clear_balloon (OsmGpsMap *map)
2733    {
2734        OsmGpsMapPrivate *priv;
2735    
2736        g_return_if_fail (OSM_IS_GPS_MAP (map));
2737        priv = map->priv;
2738    
2739        priv->balloon_valid = FALSE;
2740    
2741        osm_gps_map_map_redraw_idle(map);
2742    }

Legend:
Removed from v.32  
changed lines
  Added in v.57