v3.0.0
gzip size
Github

Documentation

Getting started
Map files
Projections
Styling



Advanced

useZoomPanContext

The useZoomPanContext hook provides a quick way to access the transform properties applied to the ZoomableGroup component.

import {
  ComposableMap,
  ZoomableGroup,
  useZoomPanContext,
} from "react-simple-maps"

const CustomComponent = () => {
  const ctx = useZoomPanContext()

  // ctx.x
  // ctx.y
  // ctx.k
  // ctx.transformString

  return <circle cx={0} cy={0} r={10} />
}

const ExampleMap = () => {
  return (
    <ComposableMap>
      <ZoomableGroup>
        <CustomComponent />
      </ZoomableGroup>
    </ComposableMap>
  )
}

jsx

Returned values

The useZoomPanContext hook returns the following values:

x

The x value is the x-offset applied to ZoomableGroup.

y

The y value is the y-offset applied to ZoomableGroup.

k

The k value is the scale applied to ZoomableGroup. This value will usually correspond to the zoom-level applied to the map.

transformString

This string value is the value passed to the transform property of the ZoomableGroup component.

Newsletter

Sign up to the React Simple Maps newsletter and be the first one to know when we publish new stuff.

Contact us

React Simple Maps was created by z creative labs. We turn ideas into digital products and specialise in dataviz and data-driven design. Are you looking for someone to create custom mapcharts and data visualisations?

Get in touch

React Simple Maps