admin管理员组文章数量:1287624
I use global map DataMaps.js. I want to implement Mouse Zoom, when mouse wheel moves. There is a example of static zoom:
var zoom = new Datamap({
element: document.getElementById("zoom_map"),
scope: 'world',
// Zoom in on Africa
setProjection: function(element) {
var projection = d3.geo.equirectangular()
.center([23, -3])
.rotate([4.4, 0])
.scale(400)
.translate([element.offsetWidth / 2, element.offsetHeight / 2]);
var path = d3.geo.path()
.projection(projection);
return {path: path, projection: projection};
}
});
Also, I have event Mouse Wheel:
$('#zoom_map').bind('DOMMouseScroll mousewheel', function(e){
if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
console.log("+");
e.preventDefault();
}
else{
console.log("-");
e.preventDefault();
}
});
I tried to concatenate these parts. Also, I tried to change datamaps.js. But, unfortunately, I get fail.
I use global map DataMaps.js. I want to implement Mouse Zoom, when mouse wheel moves. There is a example of static zoom:
var zoom = new Datamap({
element: document.getElementById("zoom_map"),
scope: 'world',
// Zoom in on Africa
setProjection: function(element) {
var projection = d3.geo.equirectangular()
.center([23, -3])
.rotate([4.4, 0])
.scale(400)
.translate([element.offsetWidth / 2, element.offsetHeight / 2]);
var path = d3.geo.path()
.projection(projection);
return {path: path, projection: projection};
}
});
Also, I have event Mouse Wheel:
$('#zoom_map').bind('DOMMouseScroll mousewheel', function(e){
if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
console.log("+");
e.preventDefault();
}
else{
console.log("-");
e.preventDefault();
}
});
I tried to concatenate these parts. Also, I tried to change datamaps.js. But, unfortunately, I get fail.
Share Improve this question asked Nov 7, 2014 at 22:44 DenisDenis 3,70713 gold badges57 silver badges88 bronze badges1 Answer
Reset to default 13you can use done
option to make a callback to the zoom function
done: function(datamap){
datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
function redraw() {
datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
}
本文标签: javascriptMouse Wheel Zoom MapDataMapsjsStack Overflow
版权声明:本文标题:javascript - Mouse Wheel Zoom Map - DataMaps.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315554a2371892.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论