Zoomable Group
Interactive component to allow for easy mouse and gesture zooming and panning for mapcharts. Wrap geographies, markers, annnotations, and lines with a zoomable group component to allow your users to easily zoom and pan around your mapcharts.
import { ZoomableGroup } from "react-simple-maps"
js
Example
The following example shows a simple world map with zooming and panning enabled via ZoomableGroup
.
Positioning
You can set the center for your map using the center
prop. This prop will then act as the starting point for the mapchart. You can also control this center value from the outside (e.g. via buttons or scroll events).
Note that the center prop is different from the rotate property in the projection config. Changing the center prop will not recompute the projection, but merely center the map on a specific coordinate while retaining the projection rotation.
Events
You can hook into a number of events in order to create a better user experience when panning and zooming around the map. You can use the custom onMoveStart
, onMove
, and onMoveEnd
events to do so.
onMoveStart()
This event is triggered whenever the map starts moving. This applies to drag motions triggered by the user, as well as controlled movement via the center
prop.
<ZoomableGroup
onMoveStart={({ coordinates, zoom }) => {
console.log(coordinates, zoom)
}}
>
jsx
onMove()
This event is triggered on every increment of movement. Avoid any kind of heavy calculations to avoid performance issues here.
<ZoomableGroup
onMove={({ x, y, k, dragging }) => {
console.log(x, y, k, dragging)
}}
>
jsx
onMoveEnd()
This event is triggered when the map stops moving.
<ZoomableGroup
onMoveEnd={({ coordinates, zoom }) => {
console.log(coordinates, zoom)
}}
>
jsx
The following is an example of using onMoveEnd
to enable external zoom controls for the map:
Zoomable Group props
Name | Type | Default |
---|---|---|
center | Array | [0, 0] |
zoom | Number | 1 |
minZoom | Number | 1 |
maxZoom | Number | 8 |
translateExtent | Array | [[-∞, -∞], [∞, ∞]] |
filterZoomEvent | Function | |
onMoveStart | Function | |
onMove | Function | |
onMoveEnd | Function |