The Traveller Map site works by having a browser-based client application written in JavaScript call various APIs provided by the web site to render map tiles, provide search results, look up coordinates, and so forth. The browser provides the HTML+CSS rendering, layout and interaction engine, the web site provides the content, and the script glues it together.
All of these APIs may be called by other applications. In addition, several other APIs have been exposed specifically for external applications or users to take advantage of.
If you start developing against these APIs in any form, please let me know! Email me at inexorabletash@gmail.com. In addition, the blog is a good source of news and discussion around the site and APIs.
NOTE: Many APIs take x and y parameters.
The coordinate system for those values varies depending on the API. See the
Coordinate Systems documentation for more details.
All of the APIs that produce images (Poster, JumpMap,
Tile) as well as the site itself (including IFRAME) take
an options parameter that is a bit-map of rendering style options and a style
parameter that names a visual style/color scheme for the map.
The options are canonically defined in the script as flags that can
be combined by adding the values together. The options parameter must
be specified in decimal.
| Option | Hexadecimal | Decimal | Notes |
|---|---|---|---|
| SectorGrid | 0x0001 | 1 | |
| SubsectorGrid | 0x0002 | 2 | |
| SectorsSelected | 0x0004 | 4 | At low scales, show only some sector names |
| SectorsAll | 0x0008 | 8 | Show all sector names |
| BordersMajor | 0x0010 | 16 | |
| BordersMinor | 0x0020 | 32 | No longer used |
| NamesMajor | 0x0040 | 64 | |
| NamesMinor | 0x0080 | 128 | No longer used |
| WorldsCapitals | 0x0100 | 256 | |
| WorldsHomeworlds | 0x0200 | 512 | |
| RoutesSelected | 0x0400 | 1024 | No longer used |
| PrintStyle | 0x0800 | 2048 | No longer used |
| CandyStyle | 0x1000 | 4096 | No longer used |
| ForceHexes | 0x2000 | 8192 | Beta Feature |
| WorldColors | 0x4000 | 16384 | Beta Feature |
| FilledBorders | 0x8000 | 32768 | Beta Feature |
Style values include:
posterprintatlascandy
The easiest way to determine the options is to use the main map page, select map options
using the controls on the right, then click Permalink on the bottom - this will reload
the page with the current view coordinates and options in the URL. Then copy the options
and style parameters from the URL.
These options are available when calling rendering APIs, but not the main page or IFRAME API.
sscoords=1routes=0
NOTE: APIs on this site output CORS headers so if you know your users
will be accessing your site using reasonably up-to-date browsers you can call the APIs directly via
XMLHttpRequest rather than using JSONP trick described below.
Web browsers enforce a Same Origin Policy on content, to stop a page on evilhacker.com from scripting access to your bank account with your stored credentials. This is a good thing! Unfortunately, it also means that sites that want to cooperate have to jump through some hurdles. For example, you can't have a web page on your site that calls directly into one of the APIs on this site (via XMLHttpRequest) from JavaScript. Either the the sites need to have server-to-server communication (which is troublesome to set up, impractical in some circumstances, and introduces its own security issues) or they can play some tricks. JSONP is one of those tricks.
Web browsers allow pages to dynamically add content via script. They can even add references to additional script files, and those files can come from different sites. While a script cannot make AJAX calls to another site to retrieve data, it can cause a script from that site to be loaded just like a local script. The loaded script doesn't have any special abilities - it's still running within the domain of the page. The trick is to request a script with dynamically generated content - the data you wanted to request from the remote site in the first place!
The following APIs on this site support JSONP requests:
To get a JSONP response, append &jsonp=callbackfn to your query string,
where callbackfn is the name of the function you'd like the script to call. This is
a function that should be pre-existing in your page, that takes an argument. The argument is
the JavaScript value (usually an object with properties, sub-objects, arrays, etc).
Here's how you'd have your page make one of these requests
function jsonp_example(q)
{
// This is the function you call to make the JSONP request,
// for example when the user clicks a link
var url = 'http://www.travellermap.com/Search.aspx' +
'?q=' + encodeURIComponent(q) +
'&jsonp=cbfn';
var script_tag = document.createElement('script');
script_tag.setAttribute('src',url);
document.body.appendChild(script_tag);
}
function cbfn(data)
{
// This is called automatically with the results
window.alert('Callback, got ' + data.Results.Count + ' results.');
}
Different APIs use different coordinate systems. Future API updates may attempt to unify them, but the different coordinate systems will always be required, as different APIs provide different views on the site dataset.
Some APIs support simple named locations, namely the name of a sector followed by a four-digit hex number (in xxyy form). This is inefficient, as the sector must be looked up by name, but is supported for convenience in APIs likely to be specified as URLs directly by humans rather than automatically generated.
The Traveller Map database of sector names accepts multiple spellings and languages for sector
names ("Far Frontiers"/"Afachtiabr", "Dagudashaag"/"Dagudashag", etc) and is case-insensitive.
Remember to URL-encode non-alphanumeric characters (e.g. spaces are %20 or
+).
The Coordinates API will look up a sector/hex location and produce sector/hex
coordinates suitible for further calculations. For convenience, the JumpMap API,
Credits API, IFRAME API, and Permalinks all accept named locations using
sector and hex parameters.
Example: Regina is "Spinward Marches" "1910"
Sector/Hex are the simplest numeric coordinates. These must be specified as a quartet of (sx, sy, hx, hy).
The Core sector is at (0,0), with positive x being Trailing and positive y being Rimward.
Hex coordinates are 1...32 and 1...40. Note that hx and hy must be specified separately. Developers should
be aware that many languages (C/C++, JavaScript, etc) will parse numbers with leading 0's as octal, so
08 and 09 are treated as erroneous and gives bogus results.
Use an appropriate parsing function with an explicit radix.
The Coordinates API will map a sector/hex name (such as "Spinward Marches", "1910")
to the numeric quartet in this coordinate space.
The JumpMap API and Credits API accept these coordinates using
sx, sy, hx and
hy parameters. The Coordinates API can also accept
these coordinates using those parameters to map to World-Space coordinates.
Example: Regina (Spinward Marches 1910) is (sx=-4, sy=-1, hx=19, hy=10)
World-space coordinates are more compact than Sector/Hex coordinates, requiring just two numbers. The transformation is simple, and based around Reference (Core 0140). In this scheme, Reference is at 0,0, positive x is Trailing and positive Y is Rimward. To convert Sector/Hex to world-space coordinates, simply compute the distance to Reference:
This scheme is roughly comparable to the canonical Traveller ring/ray system, but
is far more convenient given that the origin is within charted space. This coordinate system is used by the
Credits API and the JumpMap API, which require selection of a
specific hex. The coordinates are specified as x and y parameters
The Coordinates API will map a sector name (such as "Spinward Marches") with optional hex
(e.g. "1910"), or Sector/Hex coordinates (sx, sy, hx,
hy) to world-space coordinates.
Example: Regina is (x=-110, y=-70)
While world-space coordinates make a lot of sense for describing hexes, the fractional positioning required for precisely positioning the map dictates an additional map-space coordinate system. The conversion from world-space to map-space coordinates requires two steps:
This coordinate system is used by Permalinks and the IFRAME API when a precise view
point is required. The coordinates are specified as x and y parameters.
Example: Regina is (x=-95.914, y=70.5)
Coordinates used by Tile API are designed so that the basic operations of dragging the map around and requesting new tiles are as simple as possible. If the tile scale, width and height remain constant, the tiles at (0,0) and (0,1) are adjacent, and the origin is the same as map-space coordinates. Positive x is Trailing, positive y is Rimward.
NOTE: since this is effectively an image-space coordinate system, standard graphics tricks
can be used. For example, to center a tile rendering on a map-space coordinate, use:
x = ( map_x * scale - ( width / 2 ) ) / width and
y = ( -map_y * scale - ( height / 2 ) ) / height
This coordinate system is only used by the Tile API
Example: Regina would be centered in a 512x384, 48px/pc tile at (x=-9.4919375, y=-9.3125)
<iframe src="URL" style="STYLE" frameborder="0" scrolling="no"></iframe>
Where URL is one of:
And STYLE is something like:
width: 200px; height: 200px; border: solid 1px black;
Beta API features may be revoked or changed at any time, but I'll post updates to the blog first.
ah_sx, sah_sy, yah_hx, yah_hy
parameters in Sector/Hex coordinates to place a "You Are Here" graphical
marker. example
ox, oy, ow, oh parameters for the
left, top, width and height (in Map-space coordinates to overlay
a highlight rectangle over the map. To specify additional overlay rectangles, include
ox1 (etc) for the first additional overlay, ox2 (etc) for the
second additional overlay, and so on. For example, here's the
Atlas of the Imperium coverage area.
/iframe.htm rather than just /
<iframe src="http://www.travellermap.com/iframe.htm?x=-95.914&y=70.5&scale=48&options=887&style=poster" style="width: 200px; height: 200px; border: solid 1px black;" frameborder="0" scrolling="no"></iframe>
http://www.travellermap.com/Coordinates.aspx?sector=SECTORNAME[&hex=XXYY]
http://www.travellermap.com/Coordinates.aspx?sx=SECXCOORD&sy=SECYCOORD[&hx=HEXXCOORD&hy=HEXYCOORD]
sector - specify the sector location by name (URL encoded), e.g. "Spinward%20Marches"
hex - specify hex location within the named sector
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
hx - hex x in sector/hex-space coordinates
hy - hex y in sector/hex-space coordinates
sector and optional hex in classic Traveller nomenclature
sx and sy and optional hx and hy in sector/hex coordinates
Accept: application/json is specified
or if accept=application/json is included in the query string, or if the JSONP parameter is specified.
http://www.travellermap.com/Credits.aspx?x=XCOORD&y=YCOORD
http://www.travellermap.com/Credits.aspx?sx=SECXCOORD&sy=SECYCOORD&hx=HEXXCOORD&hy=HEXYCOORD
http://www.travellermap.com/Credits.aspx?sector=SECTORNAME&hex=XXYY
sector - specify the sector location by name (URL encoded), e.g. "Spinward%20Marches"
hex - specify hex location within the named sector (defaults to 1620 if unspecified)
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
hx - hex x in sector/hex-space coordinates
hy - hex y in sector/hex-space coordinates
x - location x in world-space coordinates
y - location y in world-space coordinates
sector and hex in classic Traveller nomenclature
sx, sy, hx and hy in sector/hex coordinates
x and y in world-space coordinates
Accept: application/json is specified
or if accept=application/json is included in the query string
or if the JSONP parameter is specified.
http://www.travellermap.com/SEC.aspx?sector=SECTORNAME
http://www.travellermap.com/SEC.aspx?sx=SECXCOORD&sy=SECYCOORD
sector - sector name, URL encoded
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
sector sector name
sx, sy in sector coordinates
^(.{15,}) +(\d\d\d\d) +(\w\w\w\w\w\w\w-\w) +(\w| ) +(.{15,}) +(\w| ) +([0-9][0-9A-F][0-9A-F]) +(\w\w) (.*)
http://www.travellermap.com/SectorMetaData.aspx?sector=SECTORNAME
sector - sector name, URL encoded (required)
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
sector sector name
sx, sy in sector coordinates
http://www.travellermap.com/MSEC.aspx?sector=SECTORNAME
sector - sector name, URL encoded (required)
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
sector sector name
sx, sy in sector coordinates
http://www.travellermap.com/Poster.aspx?sector=SECTORNAME[&subsector=X][&scale=N][&rotation=R][&options=O][&sscoords=1]
http://www.travellermap.com/Poster.aspx?sector=SECTORNAME[&x1=N][&y1=N][&x2=N][&y2=N][&scale=N][&subsector=X][&rotation=R][&options=O][&sscoords=1]
sector - sector name, URL encoded (required)
subsector - subsector index (A-P) (optional; if not specified, whole sector is rendered)
x1 - left hex (inclusive) of the rectangle in World-Space Coordinates (required)
y1 - top hex (inclusive) of the rectangle in World-Space Coordinates (required)
x2 - right hex (inclusive) of the rectangle in World-Space Coordinates (required)
y2 - bottom hex (inclusive) of the rectangle in World-Space Coordinates (required)
scale - scale in pixels/parsec (default is 64)
rotation - rotate the image, 1 for 90° clockwise, 2 for 180°, 3 for 90° counterclockwise
options - rendering options
style - rendering style
accept - specify application/pdf for PDF output
sscoords - specify 1 to clamp hex coords to subsector (0101-0810)
Accept header can be used to specify application/pdf instead of the query parameter.
<img src="http://www.travellermap.com/Poster.aspx?sector=Spinward+Marches&subsector=C&options=2928&scale=48" style="border: solid 4px black;" />
http://www.travellermap.com/JumpMap.aspx?x=XCOORD&y=YCOORD[&scale=N][&options=O][&border=0]
http://www.travellermap.com/JumpMap.aspx?sx=SECXCOORD&sy=SECYCOORD&hx=HEXXCOORD&hy=HEXYCOORD[&scale=N][&options=O][&border=0]
http://www.travellermap.com/JumpMap.aspx?sector=SECTORNAME&hex=XXYY[&scale=N][&options=O][&border=0]
jump - jump distance to render (1 through 12, default is 6)
sector - specify the sector location by name (URL encoded), e.g. "Spinward%20Marches"
hex - specify hex location within the named sector (required if sector is specified)
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
hx - hex x in sector/hex-space coordinates
hy - hex y in sector/hex-space coordinates
x - location x in world-space coordinates
y - location y in world-space coordinates
scale - scale in pixels/parsec (default is 64)
options - rendering options
style - rendering style
border - whether or not to render a thick border; specify 1 (yes, the default) or 0 (no)
accept - specify application/pdf for PDF output
sector and hex in classic Traveller nomenclature
sx, sy, hx and hy in sector/hex coordinates
x and y in world-space coordinates
Accept header can be used to specify application/pdf instead of the query parameter.
<img src="http://www.travellermap.com/JumpMap.aspx?sector=Spinward+Marches&hex=1910&jump=4&scale=48&options=2096" />
http://www.travellermap.com/JumpWorlds.aspx?x=XCOORD&y=YCOORD
http://www.travellermap.com/JumpWorlds.aspx?sx=SECXCOORD&sy=SECYCOORD&hx=HEXXCOORD&hy=HEXYCOORD
http://www.travellermap.com/JumpWorlds.aspx?sector=SECTORNAME&hex=XXYY
jump - jump distance to include (1 through 6, default is 6)
sector - specify the sector location by name (URL encoded), e.g. "Spinward%20Marches"
hex - specify hex location within the named sector (required if sector is specified)
sx - sector x in sector/hex-space coordinates
sy - sector y in sector/hex-space coordinates
hx - hex x in sector/hex-space coordinates
hy - hex y in sector/hex-space coordinates
x - location x in world-space coordinates
y - location y in world-space coordinates
Name
Hex
Uwp
Base
Zone
Allegiance
Pbg
Stellar
Accept: application/json is specified
or if accept=application/json is included in the query string
or if the JSONP parameter is specified.
http://www.travellermap.com/Search.aspx?q=QUERY
q - query string, URL encode (required)
uwp: as a prefix to a word to search the UWP field. Examples:
uwp:a* - find worlds with class A starports
t* uwp:*f - find worlds with names beginning with T that are tech level F
exact: as a prefix to a word force an exact name.
uwp:
Accept: application/json is specified
or if accept=application/json is included in the query string
or if the JSONP parameter is specified.
http://www.travellermap.com/Tile.aspx?x=XCOORD&y=YCOORD&scale=N&options=O[&w=WIDTH][&h=HEIGHT]
x - tile-space coordinate (required)
y - tile-space coordinate (required)
scale - scale in pixels/parsec (required)
options - rendering options
style - rendering style
w - width of image to generate (pixels, default 256)
h - height of image to generate (pixels, default 256)
accept - specify application/pdf for PDF output; otherwise output depends on options
Accept header can be used to specify application/pdf instead of the query parameter.
http://www.travellermap.com/Universe.aspx[?era=YEAR]
era - year, e.g. 0, 1110, 1248 (optional)
era parameter filters on an exact match only; the tagging of sectors with a precise year is sparse
Accept: application/json is specified
or if accept=application/json is included in the query string
or if the JSONP parameter is specified.
The script file that implements the site logic is full of goodies, such as the mechanism to convert coordinate spaces between the map's internal format and Traveller parsec numbering, and the definitions of the options that are referenced in various APIs.
Specifically, the following scripts are used: