Maps¶
This page shows how a tool on SweatStack Tools draws maps from SweatStack Maps, the one map service a tool can reach.
Beta
SweatStack Tools is in beta and is subject to breaking changes. If you plan to use it in production, email [email protected] before you integrate, so we can tell you about changes in advance and help you migrate.
SweatStack Maps serves an OpenStreetMap basemap and worldwide terrain from https://maps.sweatstack.dev. A tool fetches the style, tiles, fonts and icons from it. Tile hosts of third parties are blocked.
Draw a map¶
- Ship MapLibre GL JS in your tool. Copy its four files from the npm package into
vendor/:Keep the threenpm install [email protected] cp node_modules/maplibre-gl/dist/{maplibre-gl.mjs,maplibre-gl-shared.mjs,maplibre-gl-worker.mjs,maplibre-gl.css} vendor/.mjsfiles in the same folder. MapLibre finds its worker next to its own module. - Load the stylesheet and the module, and use a SweatStack Maps style:
<link rel="stylesheet" href="vendor/maplibre-gl.css"> <div id="map" style="height: 400px"></div> <script type="module"> import * as maplibregl from "./vendor/maplibre-gl.mjs"; const map = new maplibregl.Map({ container: "map", style: "https://maps.sweatstack.dev/v4/styles/light.json", center: [10.75, 59.91], zoom: 11, }); </script>
The styles are light, dark, white, grayscale and black, each at https://maps.sweatstack.dev/v4/styles/{name}.json.
Add terrain¶
Hillshade and 3D terrain come from the same service:
map.on("load", () => {
map.addSource("terrain", { type: "raster-dem", url: "https://maps.sweatstack.dev/terrain/v1.json" });
map.addLayer({ id: "hillshade", type: "hillshade", source: "terrain" }, "water");
// 3D terrain needs a source of its own.
map.addSource("terrain-3d", { type: "raster-dem", url: "https://maps.sweatstack.dev/terrain/v1.json" });
map.setTerrain({ source: "terrain-3d" });
});
Terrain covers the whole world from zoom 0 to 11. For contour lines, ship the maplibre-contour plugin in vendor/ the same way as MapLibre.
Show the attribution¶
The map data is from OpenStreetMap, and its licence requires "© OpenStreetMap" on every map, linked to https://www.openstreetmap.org/copyright. The styles include this text, and MapLibre shows it in its attribution control. Don't hide or remove the control.
If your tool exports a map, as an image or in a PDF, put the same attribution in the export.
Draw your own data¶
Add the person's data as a GeoJSON source, such as the route of an activity from the SweatStack API:
map.addSource("route", {
type: "geojson",
data: { type: "Feature", geometry: { type: "LineString", coordinates: route } },
});
map.addLayer({ id: "route", type: "line", source: "route", paint: { "line-width": 3, "line-color": "#e4572e" } });
route is an array of [longitude, latitude] pairs. The data stays in the browser: only the map's tiles come from SweatStack Maps.