[英]DataMap/D3 - how to reset zoom?
I have a DataMaps map, which is based on D3.js (version 3), and I've added a zoom on scroll to it. 我有一个基于D3.js(第3版)的DataMaps地图,并且在滚动条上添加了缩放比例 。 The only problem is that I haven't found a way how to reset it.
唯一的问题是我还没有找到一种方法来重置它。
var reset = document.getElementById('reset-map');
var map = new Datamap({
element: document.getElementById('world-map'),
responsive: true,
});
map.svg.call(d3.behavior.zoom().on('zoom', function () {
reset.style.display = 'block';
map.svg.selectAll('g').attr('transform', 'translate(' + d3.event.translate + ')' + ' scale(' + d3.event.scale + ')')
}));
reset.addEventListener('click', function (e) {
e.preventDefault();
// TODO remove zoom
reset.style.display = 'none';
} );
Found these two, but I have no idea how to apply it in my case, could you help, please? 找到了这两个,但是我不知道如何在我的情况下应用它,请您能帮忙吗?
Thanks a lot! 非常感谢!
Try this: 尝试这个:
var zoom = d3.behavior.zoom().on('zoom', function () {...});
map.svg.call(zoom);
On reset (it's a V4 code, not sure it works with V3): 重置时(这是V4代码,不确定是否可以在V3中使用):
var transform = d3.zoomIdentity.translate(0, 0).scale(1);
map.svg.call(zoom.transform, transform);
Let us know if it works for you 让我们知道它是否对您有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.