简体   繁体   English

鼠标滚轮缩放地图 - DataMaps.js

[英]Mouse Wheel Zoom Map - DataMaps.js

I use global map DataMaps.js . 我使用全局地图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 . 此外,我试图更改datamaps.js But, unfortunately, I get fail. 但是,不幸的是,我失败了。

you can use done option to make a callback to the zoom function 您可以使用done选项对缩放功能进行回调

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 + ")");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM