This application requires JavaScript.
maps for sveltekit

SvelteKit maps, the boring infra part sorted.

SvelteKit universal-loads your routes. Wrap the map mount in <svelte:component> + a browser check so maplibre-gl only executes when running in the browser.

install
pnpm add maplibre-gl
svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import { browser } from '$app/environment';
  import maplibregl, { type Map as MapLibreMap } from 'maplibre-gl';
  import 'maplibre-gl/dist/maplibre-gl.css';

  const MAP_STYLE = 'https://maps.guru/api/v1/styles/standard/light/style.json?key=YOUR_API_KEY';

  let container: HTMLDivElement;
  let map: MapLibreMap | undefined;

  onMount(() => {
    // Critical: SvelteKit may hydrate on the server during prerender.
    // Skip maplibre-gl when browser === false.
    if (!browser) return;

    map = new maplibregl.Map({
      container,
      style: MAP_STYLE,
      center: [77.209, 28.6139],
      zoom: 11,
    });
  });
</script>

<div bind:this={container} class="map-canvas"></div>
live · SvelteKit preview

Why SvelteKit teams ship on maps.guru

Free-tier generous enough for real production traffic. 50,000 tile requests/month , no credit card.

  • Use the `browser` flag from $app/environment to skip maplibre-gl on the server.
  • SvelteKit ships with on-demand rendering, so each map renders server HTML then hydrates.
  • Pair with prerendering for the surrounding layout and client-only loading for the map bundle.

Frequently asked

Ready to build with
beautiful basemaps?

Join developers worldwide who trust maps.guru for their mapping needs. Start free, no credit card required.

Contact us
Free forever plan
5-minute setup
No credit card