OsmGpsMap

OsmGpsMap — The map display widget

Stability Level

Stable, unless otherwise indicated

Functions

Properties

gboolean auto-center Read / Write / Construct
gfloat auto-center-threshold Read / Write / Construct
gboolean auto-download Read / Write / Construct
gint drag-limit Read / Write / Construct Only
gint gps-track-highlight-radius Read / Write / Construct
gint gps-track-point-radius Read / Write / Construct
gfloat gps-track-width Read / Write / Construct
gchar * image-format Read / Write / Construct Only
gfloat latitude Read
gfloat longitude Read
gint map-source Read / Write / Construct
gint map-x Read / Write / Construct Only
gint map-y Read / Write / Construct Only
gint max-zoom Read / Write / Construct Only
gint min-zoom Read / Write / Construct Only
gchar * proxy-uri Read / Write / Construct Only
gboolean record-trip-history Read / Write / Construct
gchar * repo-uri Read / Write / Construct Only
gboolean show-gps-point Read / Write / Construct
gboolean show-trip-history Read / Write / Construct
gchar * tile-cache Read / Write / Construct
gchar * tile-cache-base Read / Write / Construct Only
gint tile-zoom-offset Read / Write / Construct Only
gint tiles-queued Read
gint zoom Read / Write / Construct Only

Signals

void changed Run First

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkDrawingArea
                ╰── OsmGpsMap

Implemented Interfaces

OsmGpsMap implements AtkImplementorIface and GtkBuildable.

Includes

#include <osm-gps-map.h>

Description

OsmGpsMap is a widget for displaying a map, optionally overlaid with a track(s) of GPS co-ordinates, images, points of interest or on screen display controls. OsmGpsMap downloads (and caches for offline use) map data from a number of websites, including

OpenStreetMap

Example 1. Showing a map

int main (int argc, char **argv)
{
    g_thread_init(NULL);
    gtk_init (&argc, &argv);

    GtkWidget *map = osm_gps_map_new ();
    GtkWidget *w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_add (GTK_CONTAINER(w), map);
    gtk_widget_show_all (w);

    gtk_main ();
    return 0;
}
 

OsmGpsMap allows great flexibility in customizing how the map tiles are cached, see “tile-cache-base” and “tile-cache” for more information.

A number of different map sources are supported, see OsmGpsMapSource_t. The default source, OSM_GPS_MAP_SOURCE_OPENSTREETMAP always works. Other sources, particular those from proprietary providers may work occasionally, and then cease to work. To check if a source is supported for the given version of this library, call osm_gps_map_source_is_valid().

Example 2. Map with custom source and cache dir

int main (int argc, char **argv)
{
    g_thread_init(NULL);
    gtk_init (&argc, &argv);
    OsmGpsMapSource_t source = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE;

    if ( !osm_gps_map_source_is_valid(source) )
        return 1;

    GtkWidget *map = g_object_new (OSM_TYPE_GPS_MAP,
                     "map-source", source,
                     "tile-cache", "/tmp/",
                      NULL);
    GtkWidget *w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_add (GTK_CONTAINER(w), map);
    gtk_widget_show_all (w);

    gtk_main ();
    return 0;
}
 

Finally, if you wish to use a custom map source not supported by OsmGpsMap, such as a custom map created with

CloudMade

then you can also pass a specially formatted string to “repo-uri”.

Example 3. Map using custom CloudMade map and on screen display

int main (int argc, char **argv)
{
    g_thread_init(NULL);
    gtk_init (&argc, &argv);
    const gchar *cloudmate = "http://a.tile.cloudmade.com/YOUR_API_KEY/1/256/#Z/#X/#Y.png";

    GtkWidget *map = g_object_new (OSM_TYPE_GPS_MAP,
                     "repo-uri", cloudmate,
                      NULL);
    OsmGpsMapOsd *osd = osm_gps_map_osd_new ();
    GtkWidget *w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    osm_gps_map_layer_add (OSM_GPS_MAP(map), OSM_GPS_MAP_LAYER(osd));
    gtk_container_add (GTK_CONTAINER(w), map);
    gtk_widget_show_all (w);

    gtk_main ();
    return 0;
}
 

Functions

OSM_GPS_MAP_INVALID

#define OSM_GPS_MAP_INVALID         (0.0/0.0)


osm_gps_map_get_default_cache_directory ()

gchar *
osm_gps_map_get_default_cache_directory
                               (void);

Returns

the default cache directory for the library, that is the base directory to which the full cache path is appended. If “tile-cache-base” is omitted from the constructor then this value is used.


osm_gps_map_source_get_friendly_name ()

const char *
osm_gps_map_source_get_friendly_name (OsmGpsMapSource_t source);

Returns


osm_gps_map_source_get_repo_uri ()

const char *
osm_gps_map_source_get_repo_uri (OsmGpsMapSource_t source);

Returns


osm_gps_map_source_get_image_format ()

const char *
osm_gps_map_source_get_image_format (OsmGpsMapSource_t source);

Returns


osm_gps_map_source_get_min_zoom ()

int
osm_gps_map_source_get_min_zoom (OsmGpsMapSource_t source);

Returns


osm_gps_map_source_get_max_zoom ()

int
osm_gps_map_source_get_max_zoom (OsmGpsMapSource_t source);

Returns


osm_gps_map_source_is_valid ()

gboolean
osm_gps_map_source_is_valid (OsmGpsMapSource_t source);

Returns


osm_gps_map_new ()

GtkWidget *
osm_gps_map_new (void);

Returns a new OsmGpsMap object, defaults to showing data from

OpenStreetMap

See the properties description for more information about construction parameters than could be passed to g_object_new()

Returns

a newly created OsmGpsMap object.


osm_gps_map_download_maps ()

void
osm_gps_map_download_maps (OsmGpsMap *map,
                           OsmGpsMapPoint *pt1,
                           OsmGpsMapPoint *pt2,
                           int zoom_start,
                           int zoom_end);

Downloads all tiles over the supplied zoom range in the rectangular region specified by pt1 (north west corner) to pt2 (south east corner)


osm_gps_map_download_cancel_all ()

void
osm_gps_map_download_cancel_all (OsmGpsMap *map);

Cancels all tiles currently being downloaded. Typically used if you wish to cacel a large number of tiles queued using osm_gps_map_download_maps()

Since 0.7.0


osm_gps_map_get_bbox ()

void
osm_gps_map_get_bbox (OsmGpsMap *map,
                      OsmGpsMapPoint *pt1,
                      OsmGpsMapPoint *pt2);

Parameters

pt1

point to be filled with the top left location.

[out]

pt2

point to be filled with the bottom right location.

[out]

osm_gps_map_set_center ()

void
osm_gps_map_set_center (OsmGpsMap *map,
                        float latitude,
                        float longitude);

osm_gps_map_set_center_and_zoom ()

void
osm_gps_map_set_center_and_zoom (OsmGpsMap *map,
                                 float latitude,
                                 float longitude,
                                 int zoom);

Since 0.7.0


osm_gps_map_set_zoom ()

int
osm_gps_map_set_zoom (OsmGpsMap *map,
                      int zoom);

Returns


osm_gps_map_zoom_in ()

int
osm_gps_map_zoom_in (OsmGpsMap *map);

Returns


osm_gps_map_zoom_out ()

int
osm_gps_map_zoom_out (OsmGpsMap *map);

Returns


osm_gps_map_scroll ()

void
osm_gps_map_scroll (OsmGpsMap *map,
                    gint dx,
                    gint dy);

Scrolls the map by dx , dy pixels (positive north, east)


osm_gps_map_get_scale ()

float
osm_gps_map_get_scale (OsmGpsMap *map);

Returns

the scale of the map at the center, in meters/pixel.


osm_gps_map_set_keyboard_shortcut ()

void
osm_gps_map_set_keyboard_shortcut (OsmGpsMap *map,
                                   OsmGpsMapKey_t key,
                                   guint keyval);

Associates a keyboard shortcut with the supplied keyval (as returned by gdk_keyval_from_name or simiar). The action given in key will be triggered when the corresponding keyval is pressed. By default no keyboard shortcuts are associated.

Parameters

key

a OsmGpsMapKey_t

 

osm_gps_map_get_event_location ()

OsmGpsMapPoint *
osm_gps_map_get_event_location (OsmGpsMap *map,
                                GdkEventButton *event);

A convenience function for getting the geographic location of events, such as mouse clicks, on the map

Parameters

event

A GtkEventButton that occured on the map

 

Returns

The point on the globe corresponding to the click.

[transfer full]

Since 0.7.0


osm_gps_map_convert_geographic_to_screen ()

void
osm_gps_map_convert_geographic_to_screen
                               (OsmGpsMap *map,
                                OsmGpsMapPoint *pt,
                                gint *pixel_x,
                                gint *pixel_y);

Convert the given location on the globe to the corresponding pixel locations on the map.

Parameters

pt

location

 

pixel_x

pixel location on map, x axis.

[out]

pixel_y

pixel location on map, y axis.

[out]

Since 0.7.0


osm_gps_map_convert_screen_to_geographic ()

void
osm_gps_map_convert_screen_to_geographic
                               (OsmGpsMap *map,
                                gint pixel_x,
                                gint pixel_y,
                                OsmGpsMapPoint *pt);

Convert the given pixel location on the map into corresponding location on the globe

Parameters

pixel_x

pixel location on map, x axis

 

pixel_y

pixel location on map, y axis

 

pt

location.

[out]

Since 0.7.0


osm_gps_map_gps_add ()

void
osm_gps_map_gps_add (OsmGpsMap *map,
                     float latitude,
                     float longitude,
                     float heading);

Parameters

latitude

degrees

 

longitude

degrees

 

heading

degrees or OSM_GPS_MAP_INVALID to disable showing heading

 

Since 0.7.0


osm_gps_map_gps_clear ()

void
osm_gps_map_gps_clear (OsmGpsMap *map);

Since 0.7.0


osm_gps_map_gps_get_track ()

OsmGpsMapTrack *
osm_gps_map_gps_get_track (OsmGpsMap *map);

Returns

The OsmGpsMapTrack of the internal GPS track, i.e. that which is modified when calling osm_gps_map_gps_add(). You must not free this.

[transfer none]

Since 0.7.0


osm_gps_map_track_add ()

void
osm_gps_map_track_add (OsmGpsMap *map,
                       OsmGpsMapTrack *track);

Since 0.7.0


osm_gps_map_track_remove ()

gboolean
osm_gps_map_track_remove (OsmGpsMap *map,
                          OsmGpsMapTrack *track);

Returns

Since 0.7.0


osm_gps_map_track_remove_all ()

void
osm_gps_map_track_remove_all (OsmGpsMap *map);

Since 0.7.0


osm_gps_map_image_add ()

OsmGpsMapImage *
osm_gps_map_image_add (OsmGpsMap *map,
                       float latitude,
                       float longitude,
                       GdkPixbuf *image);

Returns

A OsmGpsMapImage representing the added pixbuf.

[transfer full]

Since 0.7.0


osm_gps_map_image_add_with_alignment ()

OsmGpsMapImage *
osm_gps_map_image_add_with_alignment (OsmGpsMap *map,
                                      float latitude,
                                      float longitude,
                                      GdkPixbuf *image,
                                      float xalign,
                                      float yalign);

Returns

A OsmGpsMapImage representing the added pixbuf.

[transfer full]

Since 0.7.0


osm_gps_map_image_remove ()

gboolean
osm_gps_map_image_remove (OsmGpsMap *map,
                          OsmGpsMapImage *image);

Returns

Since 0.7.0


osm_gps_map_image_remove_all ()

void
osm_gps_map_image_remove_all (OsmGpsMap *map);

Since 0.7.0


osm_gps_map_layer_add ()

void
osm_gps_map_layer_add (OsmGpsMap *map,
                       OsmGpsMapLayer *layer);

Parameters

layer

a OsmGpsMapLayer object

 

Since 0.7.0


osm_gps_map_layer_remove ()

gboolean
osm_gps_map_layer_remove (OsmGpsMap *map,
                          OsmGpsMapLayer *layer);

Parameters

layer

a OsmGpsMapLayer object

 

Returns

Since 0.7.0


osm_gps_map_layer_remove_all ()

void
osm_gps_map_layer_remove_all (OsmGpsMap *map);

Since 0.7.0

Types and Values

struct OsmGpsMap

struct OsmGpsMap;


struct OsmGpsMapClass

struct OsmGpsMapClass {
    GtkDrawingAreaClass parent_class;

    void (*draw_gps_point) (OsmGpsMap *map, cairo_t *cr);
};


OSM_GPS_MAP_CACHE_DISABLED

#define OSM_GPS_MAP_CACHE_DISABLED  "none://"


OSM_GPS_MAP_CACHE_AUTO

#define OSM_GPS_MAP_CACHE_AUTO      "auto://"


OSM_GPS_MAP_CACHE_FRIENDLY

#define OSM_GPS_MAP_CACHE_FRIENDLY  "friendly://"


enum OsmGpsMapSource_t

Members

OSM_GPS_MAP_SOURCE_NULL

   

OSM_GPS_MAP_SOURCE_OPENSTREETMAP

   

OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER

   

OSM_GPS_MAP_SOURCE_OPENAERIALMAP

   

OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE

   

OSM_GPS_MAP_SOURCE_OPENCYCLEMAP

   

OSM_GPS_MAP_SOURCE_OSM_PUBLIC_TRANSPORT

   

OSM_GPS_MAP_SOURCE_GOOGLE_STREET

   

OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE

   

OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID

   

OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET

   

OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE

   

OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID

   

OSM_GPS_MAP_SOURCE_OSMC_TRAILS

   

OSM_GPS_MAP_SOURCE_LAST

   

enum OsmGpsMapKey_t

Members

OSM_GPS_MAP_KEY_FULLSCREEN

   

OSM_GPS_MAP_KEY_ZOOMIN

   

OSM_GPS_MAP_KEY_ZOOMOUT

   

OSM_GPS_MAP_KEY_UP

   

OSM_GPS_MAP_KEY_DOWN

   

OSM_GPS_MAP_KEY_LEFT

   

OSM_GPS_MAP_KEY_RIGHT

   

OSM_GPS_MAP_KEY_MAX

   

Property Details

The “auto-center” property

  “auto-center”              gboolean

map auto center.

Flags: Read / Write / Construct

Default value: TRUE


The “auto-center-threshold” property

  “auto-center-threshold”    gfloat

the amount of the window the gps point must move before auto centering.

Flags: Read / Write / Construct

Allowed values: [0,1]

Default value: 0.25


The “auto-download” property

  “auto-download”            gboolean

map auto download.

Flags: Read / Write / Construct

Default value: TRUE


The “drag-limit” property

  “drag-limit”               gint

The number of pixels the user has to move the pointer in order to start dragging.

Flags: Read / Write / Construct Only

Allowed values: >= 0

Default value: 10


The “gps-track-highlight-radius” property

  “gps-track-highlight-radius” gint

The radius of the gps point highlight circle.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 20


The “gps-track-point-radius” property

  “gps-track-point-radius”   gint

The radius of the gps point inner circle.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 5


The “gps-track-width” property

  “gps-track-width”          gfloat

The width of the lines drawn for the gps track.

Flags: Read / Write / Construct

Allowed values: [1,100]

Default value: 4


The “image-format” property

  “image-format”             gchar *

The map source tile repository image format (jpg, png).

Flags: Read / Write / Construct Only

Default value: "png"


The “latitude” property

  “latitude”                 gfloat

Latitude in degrees.

Flags: Read

Allowed values: [-90,90]

Default value: 0


The “longitude” property

  “longitude”                gfloat

Longitude in degrees.

Flags: Read

Allowed values: [-180,180]

Default value: 0


The “map-source” property

  “map-source”               gint

A OsmGpsMapSource_t representing the tile repository to use

If you do not wish to use the default map tiles (provided by OpenStreeMap) it is recommened that you set this property at construction, instead of setting “repo-uri”.

Flags: Read / Write / Construct

Allowed values: >= -1

Default value: -1


The “map-x” property

  “map-x”                    gint

Initial map x location.

Flags: Read / Write / Construct Only

Default value: 890


The “map-y” property

  “map-y”                    gint

Initial map y location.

Flags: Read / Write / Construct Only

Default value: 515


The “max-zoom” property

  “max-zoom”                 gint

Maximum zoom level.

Flags: Read / Write / Construct Only

Allowed values: [0,20]

Default value: 18


The “min-zoom” property

  “min-zoom”                 gint

Minimum zoom level.

Flags: Read / Write / Construct Only

Allowed values: [0,20]

Default value: 1


The “proxy-uri” property

  “proxy-uri”                gchar *

HTTP proxy uri or NULL.

Flags: Read / Write / Construct Only

Default value: NULL


The “record-trip-history” property

  “record-trip-history”      gboolean

should all gps points be recorded in a trip history.

Flags: Read / Write / Construct

Default value: TRUE


The “repo-uri” property

  “repo-uri”                 gchar *

A URI string which defines the location and format to fetch tiles for the map. The string is of the format "http://tile.openstreetmap.org/#Z/#X/#Y.png". Characters that begin with # are treated as tokens and replaced according to the following rules;

  • #X - X-tile, slippy map format

  • #Y - Y-tile, slippy map format, mercator projection

  • #Z - Zoom level, where min_zoom >= zoom <= max_zoom

  • #S - Zoom level, where -max_zoom >= (zoom-max_zoom) <= min_zoom

  • #Q - Quad tree format, set of "qrts"

  • #Q0 - Quad tree format, set of "0123"

  • #YS - Not Implemented

  • #R - Random integer in range [0,4]

If you do not wish to use the default map tiles (provided by OpenStreeMap) it is recommened that you use one of the predefined map sources, and thus you should construct the map by setting “map-source” and not “repo-uri”. The “repo-uri” property is primarily designed for applications that wish complete control of tile repository management, or wish to use OsmGpsMap with a tile repository it does not explicitly support.

Flags: Read / Write / Construct Only

Default value: "http://tile.openstreetmap.org/#Z/#X/#Y.png"


The “show-gps-point” property

  “show-gps-point”           gboolean

Controls whether the current gps point is shown on the map. Note that for derived classes that implement the draw_gps_point vfunc, if this property is FALSE

Flags: Read / Write / Construct

Default value: TRUE


The “show-trip-history” property

  “show-trip-history”        gboolean

should the recorded trip history be shown on the map.

Flags: Read / Write / Construct

Default value: TRUE


The “tile-cache” property

  “tile-cache”               gchar *

Either a full path or one of the special format URIs OSM_GPS_MAP_CACHE_DISABLED, OSM_GPS_MAP_CACHE_AUTO, OSM_GPS_MAP_CACHE_FRIENDLY. Also see “tile-cache-base” for a full understanding.

OSM_GPS_MAP_CACHE_DISABLED disables the on disk tile cache (so all tiles are fetched from the network. OSM_GPS_MAP_CACHE_AUTO causes the tile cache to be /tile-cache-base/md5(repo-uri), where md5 is the md5sum of “repo-uri”. OSM_GPS_MAP_CACHE_FRIENDLY causes the tile cache to be /tile-cache-base/friendlyname(repo-uri).

Any other string is interpreted as a local path, i.e. /path/to/cache

Flags: Read / Write / Construct

Default value: "auto://"


The “tile-cache-base” property

  “tile-cache-base”          gchar *

The base directory of the tile cache when you have constructed the map with “tile-cache” set to OSM_GPS_MAP_CACHE_AUTO or OSM_GPS_MAP_CACHE_FRIENDLY

The string is interpreted as a local path, i.e. /path/to/cache. If NULL is supplied, map tiles are cached starting in the users cache directory, (as outlined in the

XDG Base Directory Specification). To get the

base directory where map tiles will be cached call osm_gps_map_get_default_cache_directory()

Flags: Read / Write / Construct Only

Default value: NULL


The “tile-zoom-offset” property

  “tile-zoom-offset”         gint

Number of zoom-levels to upsample tiles.

Flags: Read / Write / Construct Only

Allowed values: [0,10]

Default value: 0


The “tiles-queued” property

  “tiles-queued”             gint

The number of tiles currently waiting to download. Connect to ::notify::tiles-queued if you want to be informed when this changes

Flags: Read

Default value: 0


The “zoom” property

  “zoom”                     gint

The map zoom level. Connect to ::notify::zoom if you want to be informed when this changes.

Flags: Read / Write / Construct Only

Allowed values: [0,20]

Default value: 3

Signal Details

The “changed” signal

void
user_function (OsmGpsMap *arg0,
               gpointer   user_data)

The “changed” signal is emitted any time the map zoom or map center is chaged (such as by dragging or zooming).

If you are only interested in the map zoom, then you can simply connect to ::notify::zoom

Parameters

user_data

user data set when the signal handler was connected.

 

Flags: Run First