Skip to content

ZoomPlugin โ€‹

Built-in plugin for zoom and pan. No external dependencies.

Use Ctrl + scroll to zoom, drag to pan. Or use the programmatic buttons below.

๐Ÿ–ฑ Ctrl + scroll to zoom ย ยทย  drag to pan1ร—
Zoom
Focus room

Setup โ€‹

ts
import { Svgic } from '@svgic/core'
import { ZoomPlugin } from '@svgic/core/plugins/zoom'

const zoom = ZoomPlugin({
  wheelMode: 'ctrl',  // zoom only when Ctrl is held
  minScale: 0.5,
  maxScale: 8,
})

const client = new Svgic('#container', {
  src: '/map.svg',
  plugins: [zoom],
})

Programmatic API โ€‹

ts
zoom.zoomTo(3)                          // zoom to scale 3 (centered on viewBox)
zoom.panTo(100, 200)                    // pan to SVG coordinates
zoom.focusElement('room-101')           // zoom + center on element
zoom.focusElement('room-101', { scale: 3 })
zoom.reset()                            // back to original viewBox
zoom.getState()                         // โ†’ { scale, x, y }

// Animate option per-call
zoom.reset({ animate: false })
zoom.zoomTo(2, { animate: true })

Options โ€‹

OptionTypeDefaultDescription
wheelMode'ctrl' | 'always''ctrl'ctrl โ€” zoom with Ctrl held; always โ€” always zoom
minScalenumber0.5Minimum scale
maxScalenumber10Maximum scale
panbooleantrueAllow mouse pan
touchbooleantrueAllow touch gestures (pinch, swipe)
doubleTapScalenumber2Scale on double tap
panBoundsbooleantrueRestrict pan to SVG bounds
animatebooleantrueAnimate programmatic transitions
animationDurationnumber300Animation duration in ms
focusOnClickbooleanfalseAuto-focus element on click
focusScalenumber2Scale used when auto-focusing

Touch gestures โ€‹

GestureAction
Two fingersPinch-to-zoom
One fingerPan
Double tapZoom in / reset