Skip to content
Make with

svelte-maplibre-components

Svelte MapLibre plugin collection

Maintained by Water GIS

svelte-maplibre-components provides a comprehensive collection of MapLibre plugins specifically designed for Svelte/SvelteKit integration. It includes various useful plugins such as export, legend, measure, attribute table, and tour functionality.

Quick start

npm install @watergis/svelte-maplibre-share maplibre-gl@5 bulma
<script lang="ts">
  import { ShareURLControl } from '@watergis/svelte-maplibre-share';
  import { Map } from 'maplibre-gl';
  import 'maplibre-gl/dist/maplibre-gl.css';
  import { onMount } from 'svelte';

  let mapContainer: HTMLDivElement | undefined = $state();
  let map: Map | undefined = $state();

  onMount(() => {
    if (!mapContainer) return;
    map = new Map({
      container: mapContainer,
      style: 'https://tiles.openfreemap.org/styles/liberty',
      center: [0, 20],
      zoom: 2
    });
  });
</script>

<div class="map" bind:this={mapContainer}></div>
{#if map}
  <ShareURLControl bind:map />
{/if}

<style>
  .map {
    width: 100%;
    height: 400px;
  }
</style>
Runs this code in your browser, in a new tab.
›Setup noteschecked with v5.0.0

This is a set of Svelte 5 control components (share, legend, measure, search, and more) that attach to a map you create yourself with maplibre-gl; it has no map component. The share control is shown here. All packages depend on maplibre-gl ^5.6.2, so install MapLibre v5 and skip setWorkerUrl. Import maplibre-gl.css and give the container a height. The share control's styles import Bulma's CSS without declaring it, so install bulma as well.

Other platforms are on SDKs.