Skip to main content
100%

Constrained Zoom

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Feb 19, 2013

This example displays a world map that users can pan and zoom, with the zoom behavior constrained so the map cannot be moved beyond its edges. The code uses d3.behavior.zoom with a custom zoom event handler that clamps the translation based on the current scale. Geographic data from a TopoJSON file is rendered using d3.geo.path with a Mercator projection, and the map is drawn as SVG paths. The constraint formula adjusts the allowed translation range as the scale changes, preventing the map from leaving the viewport.

AI-generated description

This example demonstrates using the zoom event to constrain the zoom behavior’s translation. This implementation is a bit heavy-handed, as the translate constraint is zoom-dependent.

gpl-3.0 Licensed

Similar vizzes