在传单地图上的d3中捕获鼠标悬停

时间:2016-08-08 21:08:51

标签: javascript d3.js leaflet mouseover

有没有办法将OpenStreetmap leaflet.js地图与d3.js对象组合在一起,以便在d3对象上捕获“鼠标悬停”工具提示?在下面的示例中,当鼠标经过蓝色圆圈时,我想创建一个控制台“ook”事件:

<!DOCTYPE html>
<html>
    <head>
    <title>d3.js with leaflet.js</title>
    <script src="http://d3js.org/d3.v4.min.js">
</script>
    <script src="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.js">
</script>
    <link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.css">
    </head>
    <body>
    <div id="map" style="width: 1350px; height: 662px"></div>
    <script type="text/javascript">
var radius = 8;
var map = L.map('map').setView([53.69, -1.14], 14);
mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; ' + mapLink + ' Contributors',
    maxZoom: 18,
}).addTo(map);
/* Initialize the SVG layer */
L.svg().addTo(map);
/* We simply pick up the SVG from the map object */
var svg = d3.select("#map").select("svg")
  , g = svg.append("g");
var data = [{
    "node": "interesting",
    "x": 641,
    "y": 295
}]
var feature = g.selectAll("circle").data(data).enter().append("svg:circle").style("fill", "steelblue").attr("r", 20).attr("transform", function(d) {
    return "translate(" + d.x + "," + d.y + ")";
}).on("mouseover", function(d) {
    console.log("ook" + d.node);
});
</script>
    </body>
</html>

在调试中,似乎鼠标事件在传单代码中捕获,而不是传递给d3。感激地收到帮助或建议

1 个答案:

答案 0 :(得分:2)

对于圈子,请包括:

  

.attr(&#34;指针事件&#34;&#34;可见&#34)