Introduction
Map components for shadcn-svelte, built on MapLibre GL. You install the source and own it.
<script lang="ts">
import {
Map,
MapCircle,
MapCompassControl,
MapControlContainer,
MapFullscreenControl,
MapMarker,
MapMarkerLabel,
MapMarkerTooltip,
MapRoute,
MapScaleControl,
MapZoomControl
} from '$lib/components/ui/map/index.js';
const STOPS = [
{ id: 'bakery', name: 'Bakery', lngLat: [2.3417, 48.8606], note: 'Pick up at 8:00' },
{ id: 'market', name: 'Market', lngLat: [2.3622, 48.8641], note: 'Pick up at 8:30' },
{ id: 'studio', name: 'Studio', lngLat: [2.3775, 48.8532], note: 'Drop off by 9:15' }
] satisfies { id: string; name: string; lngLat: [number, number]; note: string }[];
const ROUTE: [number, number][] = [
[2.3417, 48.8606],
[2.3489, 48.8627],
[2.3622, 48.8641],
[2.3701, 48.8589],
[2.3775, 48.8532]
];
</script>
<Map class="size-full" viewport={{ center: [2.3596, 48.8586], zoom: 13.4, bearing: 0, pitch: 0 }}>
<MapCircle center={[2.3622, 48.8641]} radius={350} fillOpacity={0.12} />
<MapRoute positions={ROUTE} progress={0.6} showHead />
{#each STOPS as stop (stop.id)}
<MapMarker lngLat={stop.lngLat} aria-label={stop.name}>
<MapMarkerLabel>{stop.name}</MapMarkerLabel>
<MapMarkerTooltip>{stop.note}</MapMarkerTooltip>
</MapMarker>
{/each}
<MapControlContainer position="top-right">
<MapZoomControl />
<MapCompassControl />
<MapFullscreenControl />
</MapControlContainer>
<MapControlContainer position="bottom-left">
<MapScaleControl />
</MapControlContainer>
</Map>
shadcn-svelte map is a set of Svelte 5 components for interactive maps. You add them to your project with the shadcn-svelte CLI, the same way you add a button. The code lands in your src/lib/components/ui/map folder, so you can read it, change it and keep it.
It is built on MapLibre GL and styled with your shadcn theme. Markers, routes, clusters and controls take their colours from your CSS variables and follow light and dark mode.
What you get
- Markers and popups that work with a keyboard and a screen reader.
- Data layers: GeoJSON, routes with progress, arcs, clusters, heatmaps, and circles, polygons, polylines and rectangles.
- Controls: zoom, compass, scale, fullscreen, locate, basemap switcher and place search.
- Drawing: points, lines, polygons, rectangles, circles and freehand shapes, with editing, delete, undo and redo. You get GeoJSON back.
- Blocks: ten page-sized examples, such as a store locator and a fleet tracker, that you can install and adapt.
Principles
- One engine. MapLibre GL renders everything. The basemaps come from OpenFreeMap and need no API key.
- Theme-aware. Switching the theme or the basemap never remounts markers or closes popups. Your layers stay on the map.
- Accessible. Markers are buttons, popups are dialogs, and every camera move respects reduced motion. See Accessibility.
- CSP-safe. Nothing loads from a CDN at runtime, and the map runs under a strict Content Security Policy. See Content Security Policy.
- Typed. Every prop, event and snippet is typed, and the reference tables on each page come straight from the source.
Next steps
Start with Installation, then read about the Map component. To see the components working together, browse the blocks.