Till innehållet
kart-api.se

The Swedish basemap in MapLibre

One style URL. Vector tiles, fonts, sprites and attribution come with it, and none of it counts against your quota.

<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css">
<script src="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.js"></script>
<div id="map" style="height:420px"></div>
<script>
const map = new maplibregl.Map({
  container: 'map',
  style: 'https://api.kart-api.se/v1/styles/ljus.json',
  center: [15.78, 58.705],
  zoom: 11
});
</script>

Dark mode: morker.json. These are the same styles that drive the maps in 290 Swedish local news sites, so they are tested against real traffic on real phones.

Vector tiles directly

To build your own style on the same data, point at the archive. It is PMTiles — a single file read with range requests, no tile server needed:

maplibregl.addProtocol('pmtiles', new pmtiles.Protocol().tile);
// in your style:
// "sources": { "sverige": { "type": "vector",
//   "url": "pmtiles://https://api.kart-api.se/v1/tiles/sverige-vektor.pmtiles" } }

3D terrain from the 1 m model

One archive per municipality (301 archives), built from national LiDAR and encoded as Terrarium RGB:

map.addSource('terrain', {
  type: 'raster-dem',
  url: 'pmtiles://https://api.kart-api.se/v1/tiles/terrain-rgb-0562-1m.pmtiles',
  encoding: 'terrarium',
  tileSize: 256
});
map.setTerrain({ source: 'terrain', exaggeration: 1.4 });

⚠️ The archive's extent IS the municipality. Zoom out past roughly z11 and the archive edge is drawn as a vertical wall with the basemap smeared down it. Set a zoom floor, or fly in towards the area. That is not a bug in the archive; it is what a municipality-clipped elevation model is.