The math for zooming in to the center of the screen, and not towards the top-left corner or 0lat/0lon, is fairly tricky to get right. I'm copying it from Wil Linssen's example and grafting it on to Mike Bostock's Map Pan & Zoom I. Importantly, that example uses SVG transforms to rerender the map, rather than recomputing the projection constantly. There are a few ways you might want the buttons to work:
Zoom Buttons I - Pressing a button causes a transition to the new view. Holding the button down does not restart the transition.
Zoom Buttons II - Pressing and holding the button causes the new view to be updated immediately, every 40ms. This leads to unpleasant jumps, especially when clicking the button repeatedly.
Zoom Buttons III - 100ms chained transitions that continue until the button is no longer held or the scaleExtent is met. Control logic prevents any undesirable instant panning. This is the one to use.
Again, getting the details right is tricky, which is why I'm providing full examples. But satisfyingly, the core logic does make sense. You're zeroing a vector, stretching it, and unzeroing it:
x = (x - center) * factor + center; y = (y - center) * factor + center;
- D3.js - how to add zoom button with the default wheelmouse zoom behavior
- D3.js v4 - how to add zoom button with the default wheelmouse zoom behavior
- How to add the filter or ScaleExtent in d3 v4 in Timeline with Zoom functionality
- How to use D3 zoom behavior with ViewBox instead of transform
- Binding to zoom ending with the zoom behavior
- how do i add a zoom in and zoom out button in a graph on d3
- How do you change the interpolation for a zoom behavior in d3.js
- Button with text label: How do I keep the hover color even when over text label?
- How can I add a label with value to every point of the chart?
- How can I bring a circle to the front with d3?
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- How to add more metrics on the country_map in Apache-superset?
- how to know the current Zoom level in D3.js
- How do I specify the initial zoom level in D3?
- D3js: How do I clear the zoom scale set by the d3.zoom event?
- How to update the fill color on existing svg elements with d3.js?
- How can I start with all the nodes collapsed in d3js?
- How to add a simple arc with D3
- How to create a reusable component in D3 with an API that manipulates each instance of the component?
- D3.js - How can I add a new line to the text in this Collapsible Tree?
- How to show the total per column in tooltip title with c3.js?
- how to add legend to a pie chart using D3js? And how to centralise the pie chart?
- how to integrate D3.js with the Renderer API's with Angular 2
- How can I add zooming to the d3 collapsible tree example?
- How can I add graphs/data to Rickshaw with d3.js?
- How to add a legend and labels to the pie chart?
- How to limit the zoom of a time scale in d3.js to the minute?
- How to "dump" points selected with the LinkedBrush plugin for mpld3?
- How can I set the position of a drop down list with D3.js?
More Query from same tag
- Aster Plot legend labels along with the arc
- Enable mouseup / mousedown but prevent click behavior
- D3 Topojson Circle with Radius Scaled in Miles
- Can not perform a class transition in d3.js
- 3djs, force diagram. How to preserve zoom level
- Ploting Scales and Axes using d3.js code in Google Datastudio for scatter plot
- d3 importing csv file to array
- SVG <image> elements not displaying on Firefox, Safari, iOS
- D3 data not showing all the elements
- How to draw line plus bar chart using highcharts/d3.js or any other chart library?
- How can I put circles at each point of the x and y coordinate of my line chart?
- D3 matrix of circles iterating over colors
- How to make unselected part of pie chart and bar grayed out?
- D3.js transition callback on frame
- How to smooth/reduce/filter large amounts of sensor data?
- D3 apply conditional formatting to Line element
- Points on a map with D3.js
- Appending Stacked Bar and Another Bar Chart in D3
- Load Big Data using D3 without performance degradation
- Refresh div on each submit without ajax
- Trouble creating a bar chart in d3 from an array
- d3.js Line chart tooltip content not showing
- D3 DataMaps: OnClick Events on Bubbles
- Jekyll ruining JSON file. Arrows ("=>") instead of ":"
- d3.js dynamic text wrapping
- are there any way to change c3js stacked area chart opacity on mouse hover
- how to add and remove css class on svg element
- IOS app webview SVG ClipPath Issue
- d3.js choropleth map --How do I map more than one property from CSV to JSON, so I can use it in a tooltip?