Get started
Tile API

Your content as tiles

Your content as tiles

Draw the itineraries, collections, and zones you made in Mountaya on your own map. It works like an overlay: fetch a specification, then add its sources and layers.

The samples read a publishable key with the tiles scope from MOUNTAYA_PUBLISHABLE_KEY. Replace the ids with your own.

Draw one itinerary

Fetch the specification of one itinerary, here the Tour du Mont-Blanc.

curl https://tiles.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/specification \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY"
Response
{
  "data": {
    "sources": [
      {
        "attribution": "<a href=\"https://mountaya.com/\" target=\"_blank\">&copy; Mountaya</a>",
        "id": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
        "layers": [
          {
            "id": "itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/lines-casing",
            "key": "",
            "layout": {
              "line-cap": "round",
              "line-join": "round"
            },
            "paint": {
              "line-color": "#ffffff",
              "line-opacity": 0.9,
              "line-width": ["interpolate", ["linear"], ["zoom"], 7, 4, 10, 4, 13, 5, 16, 7]
            },
            "source": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
            "source_layer": "itinerary_lines",
            "type": "line",
            "zoom_max": 18,
            "zoom_min": 8
          },
          {
            "filter": ["!=", ["get", "dashed"], true],
            "id": "itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/lines",
            "key": "",
            "layout": {
              "line-cap": "round",
              "line-join": "round"
            },
            "paint": {
              "line-color": ["coalesce", ["get", "color"], "#1c7ed6"],
              "line-width": ["interpolate", ["linear"], ["zoom"], 7, 2, 10, 2, 13, 3, 16, 5]
            },
            "source": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
            "source_layer": "itinerary_lines",
            "type": "line",
            "zoom_max": 18,
            "zoom_min": 8
          },
          {
            "filter": ["==", ["get", "dashed"], true],
            "id": "itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/lines-dashed",
            "key": "",
            "layout": {
              "line-cap": "round",
              "line-join": "round"
            },
            "paint": {
              "line-color": ["coalesce", ["get", "color"], "#1c7ed6"],
              "line-dasharray": [2, 2],
              "line-width": ["interpolate", ["linear"], ["zoom"], 7, 2, 10, 2, 13, 3, 16, 5]
            },
            "source": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
            "source_layer": "itinerary_lines",
            "type": "line",
            "zoom_max": 18,
            "zoom_min": 8
          },
          {
            "id": "itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/points",
            "key": "",
            "layout": {
              "icon-allow-overlap": true,
              "icon-anchor": "center",
              "icon-image": [
                "concat",
                "section-icon-",
                ["coalesce", ["get", "icon"], "map-pin"],
                "-",
                ["downcase", ["slice", ["coalesce", ["get", "color"], "#3b82f6"], 1]]
              ],
              "icon-size": 0.7
            },
            "paint": null,
            "source": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
            "source_layer": "itinerary_points",
            "type": "symbol",
            "zoom_max": 18,
            "zoom_min": 9
          }
        ],
        "tiles": [
          "https://tiles.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/{z}/{x}/{y}"
        ],
        "type": "vector",
        "zoom_max": 18,
        "zoom_min": 8
      }
    ]
  }
}

The itinerary is one vector source with four layers: a white casing, the line, its dashed parts, and the waypoints. Add them as for an overlay, passing each layer's filter:

const KEY = "pk_your_publishable_key";
const withKey = (url) => `${url}${url.includes("?") ? "&" : "?"}publishable_key=${KEY}`;

const response = await fetch(
  "https://tiles.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/specification",
  { headers: { "X-API-Key": KEY } },
);
const { data } = await response.json();

for (const source of data.sources) {
  map.addSource(source.id, {
    type: source.type,
    tiles: source.tiles.map(withKey),
    minzoom: source.zoom_min,
    maxzoom: source.zoom_max,
    attribution: source.attribution,
  });

  for (const layer of source.layers) {
    map.addLayer({
      id: layer.id,
      type: layer.type,
      source: source.id,
      "source-layer": layer.source_layer,
      ...(layer.filter ? { filter: layer.filter } : {}),
      minzoom: layer.zoom_min,
      maxzoom: layer.zoom_max,
      paint: layer.paint ?? {},
      layout: layer.layout ?? {},
    });
  }
}

The waypoint layer names icons that your map's style does not hold. Register them when your map asks for a missing image, or leave the symbol layer out.

From zoom 9, the zoom the waypoints appear at, the tiles also carry the restricted stretches of each route, the parts that follow a way restricting who may pass, in the itinerary_restrictions source layer. No layer of the specification draws them: add one of your own over the line, keyed on each stretch's kind, to show a hiker where a way is private or closed.

Published or draft

What a tile draws depends on the credential your map sends:

Your map sendsIt draws
A publishable keyWhat you published. The organization-wide tiles hold public content only.
A key and a session token for a memberThe drafts, private content included
A key, a member's token, and surface=publishedWhat you published
A share tokenThe one itinerary or collection it opens, as published

A map for the public sends the key alone. A map for your team adds a member's session token to see work in progress.

A share link opens one itinerary or collection to anyone who holds it, in Mountaya's own viewer. Its token (share_…) also opens that resource's tiles, but only from Mountaya's pages or from a server: a request from your own web page is refused. On your own map, send your publishable key.

Create and rotate share links with the Map Studio API.

Collections and zones

A collection's specification also carries bbox, the extent of its itineraries. Fit your map to it once the sources are added.

curl -s https://tiles.mountaya.com/v1/collections/3f1b9c42-8a6e-4d55-9f1a-2c7e5b0d4a13/specification \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" | jq '.data.bbox'
Response
[
  6.72422,
  45.82115,
  6.79898,
  45.89152
]

Pass it to map.fitBounds(). A collection draws its zones and itineraries together. To draw all your organization's zones, use GET /v1/zones/specification.

Next steps

Last updated