Requirements
- SvelteKit 2 or 3 with Svelte 5.40 or newer.
- Tailwind CSS v4.
- shadcn-svelte, set up with
init. If you have not done that yet:
pnpm dlx shadcn-svelte@latest initnpx shadcn-svelte@latest inityarn dlx shadcn-svelte@latest initbunx --bun shadcn-svelte@latest initAdd the map
pnpm dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map.jsonnpx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map.jsonyarn dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map.jsonbunx --bun shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map.jsonThis copies the map components into src/lib/components/ui/map, adds the shadcn items they use (button, button group, dropdown menu, spinner) and installs these packages:
maplibre-glrenders the map.@lucide/svelteprovides the icons.
The MapLibre worker is bundled with your app through Vite, so the map loads nothing from a CDN.
Your first map
Give the map a height. It fills its parent’s width.
<script lang="ts">
import { Map, MapMarker } from '$lib/components/ui/map/index.js';
</script>
<Map
class="h-96 rounded-lg border"
viewport={{ center: [13.405, 52.52], zoom: 11, bearing: 0, pitch: 0 }}
>
<MapMarker lngLat={[13.405, 52.52]} aria-label="Berlin" />
</Map>The map renders in the browser only. On the server it renders an empty frame, so it works with server-side rendering and prerendering without extra checks.
Optional: skip the first reload in dev
The map loads maplibre-gl only in the browser, so Vite finds it the first time a page with a map opens. It then bundles it and reloads the page once, and the console shows a 504 (Outdated Optimize Dep) error for that first load. The map works after the reload.
To avoid this, tell Vite about maplibre-gl up front in vite.config.ts:
export default defineConfig({
optimizeDeps: { include: ['maplibre-gl'] },
plugins: [tailwindcss(), sveltekit()]
});This only changes the dev server. Production builds work the same either way.
Add a block
Blocks are complete examples, such as a store locator. Each one installs into its own folder and pulls in the map if you do not have it yet.
pnpm dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/store-locator.jsonnpx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/store-locator.jsonyarn dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/store-locator.jsonbunx --bun shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/store-locator.jsonBrowse them all in the block gallery.
Drawing and place search
The drawing toolbar and the map search box are separate items, so a plain map does not install a drawing engine or a geocoder. Add them when you need them:
pnpm dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-draw.jsonnpx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-draw.jsonyarn dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-draw.jsonbunx --bun shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-draw.jsonpnpm dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-search.jsonnpx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-search.jsonyarn dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-search.jsonbunx --bun shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/map-search.jsonmap-draw goes into src/lib/components/ui/map-draw and installs terra-draw and its MapLibre adapter. map-search goes into src/lib/components/ui/map-search and adds the place search box. Blocks that use them pull them in for you.
Place search on its own
The search box behind the map search control is its own item. Add it if you want place search without a map:
pnpm dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/place-autocomplete.jsonnpx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/place-autocomplete.jsonyarn dlx shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/place-autocomplete.jsonbunx --bun shadcn-svelte@latest add https://shadcn-svelte-map.vercel.app/r/place-autocomplete.jsonUpdating
Run the same add command again. The CLI asks before it overwrites files you changed.