shadcn-svelte map
DocsComponentsBlocks
Get Started
  • Introduction
  • Installation
Guides
  • Theming
  • Drawing
  • Accessibility
  • Performance
  • Content Security Policy
Core
  • Map
  • Control Container
Markers
  • Marker
  • Popup
  • Point Layer
Data
  • GeoJSON
  • Shapes
  • Route
  • Arc
  • Cluster Layer
  • Heatmap
Controls
  • Zoom Control
  • Compass Control
  • Scale Control
  • Fullscreen Control
  • Locate Control
  • Basemap Control
  • Search Control
  • Draw Control
More
  • Place Autocomplete
  • Utilities

Zoom Control

Previous Next

Two buttons that zoom the map in and out.

<script lang="ts">
	import { Map, MapControlContainer, MapZoomControl } from '$lib/components/ui/map/index.js';
</script>

<Map class="size-full" viewport={{ center: [2.3522, 48.8566], zoom: 11, bearing: 0, pitch: 0 }}>
	<MapControlContainer position="top-right">
		<MapZoomControl />
	</MapControlContainer>
</Map>

The zoom control is a vertical pair of buttons. Each press zooms by step levels, one by default. A button turns disabled when the map reaches its minimum or maximum zoom, so keyboard and screen reader users know they hit the limit.

Usage

Place the control inside a Control Container. The container pins it to a corner of the map.

<script lang="ts">
	import { Map, MapControlContainer, MapZoomControl } from '$lib/components/ui/map/index.js';
</script>

<Map class="h-96">
	<MapControlContainer position="top-right">
		<MapZoomControl />
	</MapControlContainer>
</Map>

Step size

Set step to zoom further per press. Fractions work too.

<MapZoomControl step={0.5} />

Reduced motion

The zoom eases over a short animation. When the user prefers reduced motion, the map jumps to the new zoom instead.

API Reference

MapZoomControl

Props

NameTypeDescription
step numberZoom levels to move per click. Defaults to 1.

Other attributes go to the underlying <div>.

Heatmap Compass Control

On This Page

UsageStep sizeReduced motionAPI Reference

Handcrafted by Oggy. The source code is on GitHub.