# Extending &appname;

## Overview

Currently, &appname; has some extension points based on configuration files. The file format is heavily inspired by the GtkBuilder file format: you specify the class of the GObject to build and set its properties. Technically, it is a XML file containing a "objects" root element. Inside this element, you set a collection of "object".

Here is an example:

    <objects>
      <object class="ClassName">
        <property name="property_name1">Property value</property>
        <property name="property_name2">Property value</property>
      </object>
      ...
    <objects>

You can find more examples as installed on your system and in the documentation part of the distribution. Typically these will be installed into one of the $XDG_DATA_DIR locations, such as `/usr/share/viking/` or `C:\Program Files\Viking\data` depending on the Operating System.

It is also possible to override the internal defaults e.g. to update any parameters should they change over time, by adding the values into your configuration file. When you define object group that already exists (and for Maps this means by a repeated Id key, but you may have to examine the source code to work out what the relevant Id values are) then you need to define all the other keys as well, otherwise they will be reset to the defaults.

## Map Sources

It is possible to add new map sources. The file is `maps.xml` placed in your .

An example of the file is in the distribution `doc/examples/maps.xml`. Further examples and values are online in the Maps Wiki

The VikSlippyMapSource allows declaration of any map source working like OpenStreetMap. It supports the following properties:

id

  this is an integer and should be unique as it used to identify the map source

name

  a string (should be unique) that is used for the OSM style cache directory name when the Map Cache directory is the default (`~/.viking-maps`)

label

  the text displayed in the map's source selection dialog

hostname

  the server's hostname (eg. "tile.openstreetmap.org")

url

  the parameterised address of the tile, in the spirit of C printf format, with 3 "%d" fields for Z, X and Y (in that order) (eg. "/%d/%d/%d.png")

  The full parameterised address can just be put in the URL field and the hostname field doesn't need specifying.

  e.g. "https://tile.openstreetmap.org/%d/%d/%d.png"

user-agent (optional)

  Override the default user-agent used in the HTTP request.

custom-http-headers (optional)

  Custom HTTP headers to be added to the download request. The default is none.

  Multiple headers can be specified by separating each part with an '\n'.

  The header allows of substitutions of values of the positional Z, X and Y (in that order) values, as per the url option above. Using multiple and/or different ordered values can be acheived via printf() positional argument specifiers. For example:

  `DNT: 1\nLine2: %d %d %d\nReordered: %3$d %1$d %2$d`

copyright (optional)

  The copyright of the map source.

license (optional)

  The license of the map source.

license-url (optional)

  The URL of the license of the map source.

zoom-min (optional)

  The minimum Tiled Web Map zoom value supported by the tile server. The Default is 0 if not specified.

zoom-max (optional)

  The maximum Tiled Web Map zoom value supported by the tile server. The Default is 18 if not specified.

lat-min (optional)

  The minimum latitude value in degrees supported by the tile server. The Default is -90 degrees if not specified.

lat-max (optional)

  The maximum latitude value in degrees supported by the tile server. The Default is 90 degrees if not specified.

lon-min (optional)

  The minimum longitude value in degrees supported by the tile server. The Default is -180 degrees if not specified.

lon-max (optional)

  The maximum longitude value in degrees supported by the tile server. The Default is 180 degrees if not specified.

file-extension (optional)

  The file extension of the files on disk. The default is .png

  If the tile source is not a PNG file, then this parameter can be used to specify the naming to give consistent extension filenames on disk.

  This can also be useful in reading a tileset from other software which may name tiles in an alternative form, e.g. for Mobile Atlas creator it names them .png.tile

  The file types actually usable are those supported by GDK Pixbuf Library, which includes at least PNG and JPEG.

  Remember to include the beginning '.' when specifying this parameter.

use-direct-file-access (optional)

  Only use files on disk. The default is FALSE

  This can also be useful for tilesets already on disk as it will avoid attempting to download any tiles.

  Thus with this type the hostname and url parameters are not necessary and are ignored.

offset-x (optional)

  The offset of the map in the x plane (towards east) in metres. The default is 0.0 if not specified.

  Use negative numbers to adjust in a westerly direction.

  Typical usage would be aligning differing maps, e.g. aerial imagery may be offset from cadastral maps.

  Currently this is a single value that applies to all zoom levels.

offset-y (optional)

  The offset of the map in the y plane (towards north) in metres. The default is 0.0 if not specified.

  Use negative numbers to adjust in a southerly direction.

switch-xy (optional)

  Swap the X,Y values around in the URL parameterised ordering.

  The default is false.

check-file-server-time (optional)

  Sends the timestamp of the tile to the server, so the server can decide whether it should send a new tile or not.

  The default is true.

use-etag (optional)

  Use and compare the ETag value in determining whether to download a newer tile. The default is false.

  The ETag value is stored in a separate file in the same directory as the tile to enable checking the value across multiple runs of the program.

referer (optional)

  A URL to serve as referrer for the HTTP request (eg. "http://hostname/")

follow-location (optional)

  The maximum number of redirects allowed. The default is -1 for an unlimited number of redirects. Use 0 if you do not want to follow redirects.

tilesize-x (optional)

  The tile x size. The default is 256 pixels if not specified.

tilesize-y (optional)

  The tile y size. The default is 256 pixels if not specified.

scale (optional)

  The tile scale. The scale is 1 if not specified.

  Use a value of 2 to represent high res tiles. Don't change the tilesize as the internal display size is still based on 256 pixels.

The VikTmsMapSource allows declaration of any TMS service. A TMS (Tile Map Service) is defined in Tile Map Service Specification. The configuration supports the following properties (as per VikSlippyMapSource above):

- id
- label
- hostname
- url
- custom-http-headers (optional)
- copyright (optional)
- license (optional)
- license-url (optional)
- check-file-server-time (optional)
- follow-location (optional)
- referer (optional)
- user-agent (optional)
- zoom-min (optional)
- zoom-max (optional)
- lat-min (optional)
- lat-max (optional)
- lon-min (optional)
- lon-max (optional)
- file-extension (optional)
- scale (optional)
- tilesize-x (optional)
- tilesize-y (optional)
- offset-x (optional)
- offset-y (optional)

The VikWmscMapSource allows declaration of any WMS or WMS-C service. A WMS (Web Map Service) is defined in WMS Tile Caching. The configuration supports the following properties (as per VikSlippyMapSource above):

- id
- label
- hostname
- url
- custom-http-headers (optional)
- copyright (optional)
- license (optional)
- license-url (optional)
- check-file-server-time (optional)
- follow-location (optional)
- referer (optional)
- user-agent (optional)
- zoom-min (optional)
- zoom-max (optional)
- lat-min (optional)
- lat-max (optional)
- lon-min (optional)
- lon-max (optional)
- file-extension (optional)
- scale (optional)
- tilesize-x (optional)
- tilesize-y (optional)
- offset-x (optional)
- offset-y (optional)

## Go-to Search Engines

It is possible to add new new search engines for the "Go-To" feature. The file is `goto_tools.xml` placed in your .

An example of the file in the distribution `doc/examples/goto_tools.xml`.

Currently, there is a single object class available: VikGotoXmlTool. This feature allows one to declare any search engine using a XML format as result.

The related properties are:

label

  the text displayed in the Go-To dialog

url-format

  the parameterised address of the query, in the spirit of C `printf` format, with a single "%s" field (replaced by the query string)

lat-path

  XML path of the latitude (eg. `/root/parent/elem`)

lat-attr (optional)

  name of the attribute (of previous element) containing the latitude

lon-path

  XML path of the longitude (eg. `/root/parent/elem`)

lon-attr (optional)

  name of the attribute (of previous element) containing the longiude

referer (optional)

  A URL to serve as referer for the HTTP request (eg. "http://hostname/")

follow-location (optional)

  The maximum number of redirects allowed. The default is -1 for an unlimited number of redirects. Use 0 if you do not want to follow redirects.

user-agent (optional)

  Override the default user-agent used in the HTTP request.

custom-http-headers (optional)

  Custom HTTP headers to be added to the HTTP request. The default is none.

  Note that unlike custom-http-headers for Tile download requests, it does not perform any value substitions in this string.

As a facility (or readability) it is possible to set both path and attribute name in a single property, like an XPath expression. To do so, simply set both info in lat-path (or lon-path) in the following format: `/root/parent/elem@attribute`.

## External Tools

It is possible to add new external tools. The file is `external_tools.xml` placed in your .

An example of the file in the distribution `doc/examples/external_tools.xml`.

The VikWebtoolCenter allows one to declare any Webtool using a logic based on center coordinates and zoom level value.

The related properties are:

label

  the text displayed in the menu entry

url

  the parametrized URL to open, in the spirit of C printf format, with 2 "%s" and a "%d" fields for X, Y and Z (zoom level) (eg. "http://hostname/?lat=%s&lon=%s&zoom=%d")

The VikWebtoolBounds allows one to declare any Webtool using a logic based on bounds coordinates.

The related properties are:

label

  the text displayed in the menu entry

url

  the parametrized address of the tile, in the spirit of C printf format, with 4 "%s" fields for left, right, bottom and top (eg. "http://hostname:8111/load_and_zoom?left=%s&right=%s&bottom=%s&top=%s")

## Routing Engines

It is possible to declare new routing engines. The file is `routing.xml` placed in your .

An example of the file in the distribution `doc/examples/routing.xml`.

The VikRoutingWebEngine allows one to declare a routing engine available via HTTP.

The related properties are:

id

  a string, should be unique as it used to identify the routing engine

label

  the text displayed in the menu entry

format

  The GPSBabel format code to interpret the service response. By default a GPX response is expected and processed internally. However if the service returns a different format then GPSBabel is used to transform the text into something that &appname; can understand. Only formats that GPSBabel supports can be used: e.g. gtrnctr (for Garmin Training Center .tcx files), etc...

  Use `gpsbabel --help` on the command line to find out the supported file types and their codes to process them.

  Some format codes are handled natively by &appname; such as gpx and kml.

  A special format code of viking-geojson-osrm is available for handling responses by OSRM route servers.

url-base

  the base URL of the web service (eg. "http://hostname/service?")

url-start-ll

  the part of the URL setting the starting point location, parameterised in the spirit of C printf format, with 2 "%s" for coordinates (eg. "&start=%s,%s")

url-stop-ll

  the part of the URL setting the end point location, parameterised in the spirit of C printf format, with 2 "%s" for coordinates (eg. "&stop=%s,%s")

url-via-ll (optional)

  the part of the URL setting via point location, parameterised in the spirit of C printf format, with 2 "%s" for coordinates (eg. "&via=%s,%s")

url-start-dir (optional)

  the part of the URL setting the starting point location for direction based routing, parameterised in the spirit of C printf format, with one "%s" for direction (eg. "&start=%s")

url-stop-dir (optional)

  the part of the URL setting the end point location for direction based routing, parameterised in the spirit of C printf format, with one "%s" for direction (eg. "&stop=%s")

url-ll-lat-first (optional)

  The ordering of the lat/long terms in the Start, Stop and Via URL settings. By default this is TRUE.

  For instance using Brouter services, the URL uses a pair of values which is longitude and then latitude. Thus setting this value to FALSE ensures the value substitution is performed in the necessary order.

referer (optional)

  A URL to serve as referer for the HTTP request (eg. "http://hostname/")

follow-location (optional)

  The maximum number of redirects allowed. The default is -1 for an unlimited number of redirects. Use 0 if you do not want to follow redirects.

user-agent (optional)

  Override the default user-agent used in the HTTP request.

custom-http-headers (optional)

  Custom HTTP headers to be added to the HTTP request. The default is none.

  Note that unlike custom-http-headers for Tile download requests, it does not perform any value substitutions in this string.

## Remote File Datasources

It is possible to add web references expected to return a file which can then be opened directly or converted via GPSBabel.

The file is `datasources.xml` placed in your .

An example of the file is in the source distribution `doc/examples/datasources.xml`.

The VikWebtoolDatasource allows one to declare any URL using logic based on coordinates.

The related properties are:

label

  the text displayed in the menu entry

url

  the parameterised URL to open in the spirit of C printf format, with up to 9 "%s" values. e.g. `http://hostname/getfile?lat=%s&lon=%s`

  The order and meaning of these parameters is given by the url_format_code below

url_format_code

  A string describing the parameterised URL substitution parameters, each character represents how to translate each term.

  B = Bottom of the current view i.e. minimum latitude

  L = Left of the current view i.e. minimum longitude

  T = Top of the current view i.e. maximum latitude

  R = Right of the current view i.e. maximum longitude

  A = center lAtitude of the current view

  O = center lOngitude of the current view

  Z = OSM Zoom value of the current view. See Zoom Levels

  P = selected Point's latitude

  N = selected poiNt's longitude

  S = A user specified input string requested from the user via a dialog box

  Thus for the url example above then the format code should be AO

file_type

  This value is passed on for the -i parameter in interfacing with GPSBabel.

  If it is not defined then the returned file is interpreted internally as a GPX file.

  Possible values such as 'kml', 'mapsource' etc.. can be used. See GPSBabel File Formats for the full list.

babel_filter_args

  This value is passed on for the filter arguments interfacing with GPSBabel.

  E.g. "-x nuketypes,routes" can be used to filter all routes from the results.

input_label

  This value is used when requesting input from the user.

  It is the label of the text input box.

referer (optional)

  A URL to serve as referrer for the HTTP request (eg. "http://hostname/")

follow-location (optional)

  The maximum number of redirects allowed. The default is -1 for an unlimited number of redirects. Use 0 if you do not want to follow redirects.

user-agent (optional)

  Override the default user-agent used in the HTTP request.

custom-http-headers (optional)

  Custom HTTP headers to be added to the HTTP request. The default is none.

## System Extension File Locations

Note that, on UNIX like systems, the extension files (&extfiles;) are also searched in `/etc/viking` and `/usr/share/viking` directories (or related in your system).

The `$XDG_DATA_DIRS` environment variable can be used to change these directories.

The `$XDG_DATA_HOME` environment variable is also used (if set) to look for these extension files.