Map Tiles

Working example of interacting with the Map Tiles marine weather endpoint.

Example Map

Use Mapbox GL JS to display model data served by the Sofar Ocean Map Tile API. The example features a dropdown menu that allows you to select from several of the supported marine weather data variables. You can run this example either by using the embedded demo or opening the code below in a local browser.



<!DOCTYPE html>

    <meta charset="utf-8" />
    <title>Sofar Tile Server Demo</title>

    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>

    <link href="" rel="stylesheet" />

        body { margin: 0; padding: 0; font-family: sans-serif; }
        #map { position: absolute; top: 0; bottom: 0; width: 100%; }
        #model-info {
            position: relative;
            background-color: #eee;
            margin: 5px;
            padding: 5px;
            display: inline-block;
        #map-overlay {
            position: relative;
            margin: 5px;
            padding: 5px;
            display: inline-block;


<div id="map"></div>
<div id="model-info">
    <b>Sofar Model:</b> <label id="model-name"></label> <br>
        <select name="variables" id="variable-name">
            <option value="">-- select a variable --</option>

    // This particular demo accesses four variables' data from the Sofar Wave Model
    const modelName     = "Wave";
    const cmap          = "turbo";
    const sofarApiToken = "383d59964809ca8c6438867e590f16";

    // update info box
    document.getElementById("model-name").textContent = modelName;

    mapboxgl.accessToken = 'pk.eyJ1Ijoiam9uc2VuIiwiYSI6IkR6UU9oMDQifQ.dymRIgqv-UV6oz0-HCFx1w'
    let map = new mapboxgl.Map({
      container: "map", // container id
      style: "mapbox://styles/jonsen/ck8i301kh0cy31ipfi7y8j6bb",
      center: [-74.5, 40], // starting position
      zoom: 2, // starting zoom

    // Function that updates the map data based on the current slider timestamp
    function addSofarTiles(variableID) {
      const sofarTileURL = 
        "" +
        modelName +
        + cmap + 
        "&token=" +
        sofarApiToken +   
        "&variableID=" +
      map.addSource("sofar-tiles", {
        type: "raster",
        tiles: [sofarTileURL],
        tileSize: 256,
        attribution: "Sofar Ocean Technologies"

        id: "sofar-tiles",
        type: "raster",
        source: "sofar-tiles",
        minzoom: 0,
        maxzoon: 10

    // add a listener to update the map whenever a new
    // variable is selected from the HTML element
    document.getElementById("variable-name").addEventListener("change", (e) => {
      const newVariable =;

      if (map.getLayer("sofar-tiles")) map.removeLayer("sofar-tiles");
      if (map.getSource("sofar-tiles")) map.removeSource("sofar-tiles");




Last updated