Skip to content
Make with

Svelte MapLibre

Svelte components for MapLibre GL JS

Maintained by Daniel Imfeld

Svelte MapLibre offers a collection of Svelte components that make it easy to build interactive maps with MapLibre GL JS while leveraging Svelte's reactivity system.

Quick start

npm install svelte-maplibre maplibre-gl
<script module>
  import * as maplibregl from 'maplibre-gl';
  import maplibreWorkerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url';

  // MapLibre GL JS v6 + a bundler: set the worker URL once (Vite shown)
  maplibregl.setWorkerUrl(maplibreWorkerUrl);
</script>

<script>
  import { MapLibre } from 'svelte-maplibre';
</script>

<MapLibre
  center={[0, 20]}
  zoom={2}
  class="map"
  style="https://tiles.openfreemap.org/styles/liberty"
/>

<style>
  :global(.map) {
    height: 400px;
  }
</style>
Runs this code in your browser, in a new tab.
›Setup noteschecked with v2.0.1

Version 2 requires Svelte 5 and depends on maplibre-gl ^6.7.0. The component imports maplibre-gl.css itself, so no CSS import is needed. Install maplibre-gl directly as well, because the snippet imports it to set the worker URL (strict package managers like pnpm need this). Give the map a height through the class, or it renders at zero height.

Other platforms are on SDKs.

Used by 3 products