Created
October 7, 2017 18:49
-
-
Save mikesurowiec/62ec5e7ad0779260c1953170f5402447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is inside of our React.Component | |
componentDidMount() { | |
// ... the clicking code was up here | |
const zoom = d3.zoom() | |
.scaleExtent([1, 5]) | |
.translateExtent([[-100, -100], [svgViewportWidth-500, svgViewportHeight-500]]) | |
.on('zoom', zoomed); | |
function zoomed() { | |
const {k, x, y} = d3.event.transform; | |
// This moves the map! | |
contentWrap.attr('transform', `translate(${x},${y}) scale(${k})`); | |
} | |
// We turn on pointer events for TWO things | |
// 1. the circles that we click on | |
// 2. the background rectangle (see below) that handles dragging events | |
// And we turn them off for everything else in contentWrap | |
const contentWrap = d3.select('#contentWrap'); | |
contentWrap.attr('pointer-events', 'none'); | |
// It's below the map because our circles from earlier need to be on top! | |
svg.append('rect') | |
.attr('class', 'mouse-capture') | |
.attr('x', -5000) | |
.attr('y', -5000) | |
.attr('width', 15000) | |
.attr('height', 15000) | |
.style('fill', 'white') | |
.lower() // put it below the map | |
.call(zoom); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment