在传单地图上捕获 d3 中的鼠标悬停
Capture mouseover in d3 on a leaflet map
有没有办法将 OpenStreetmap leaflet.js 地图与 d3.js 对象结合起来,从而捕获 d3 对象上的 "mouseover" 工具提示?在下面的示例中,我想在鼠标经过蓝色圆圈时创建一个控制台 "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: '© ' + 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。感激地收到帮助或建议
对于圈子,包括:
.attr("pointer-events","visible")
有没有办法将 OpenStreetmap leaflet.js 地图与 d3.js 对象结合起来,从而捕获 d3 对象上的 "mouseover" 工具提示?在下面的示例中,我想在鼠标经过蓝色圆圈时创建一个控制台 "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: '© ' + 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。感激地收到帮助或建议
对于圈子,包括:
.attr("pointer-events","visible")