我想点击一个圆圈并收到我点击的元素。但我无法执行此触发器。我该如何解决?
https://plnkr.co/edit/keLfbZ13wz8h9nMHp8pN?p=preview
var coordenadas=map.latLngToLayerPoint([coordinates[0].lat,coordinates[0].long]);
svg.append('circle').attr("cx",coordenadas.x)
.attr("cy", coordenadas.y)
.attr("r", 30)
.style("fill",'red')
.attr("class",'circulo_mapa')
.on("click", function(element){
console.log('this is the element', element);
alert("click")
})
答案 0 :(得分:1)
我forked your plunk添加两件事:
this
而不是element
(这是您可能想要选择的)以下是上传的方法:
var coordenadas = map.latLngToLayerPoint([coordinates[0].lat,coordinates[0].long]);
//add circle on map
var coordenadas=map.latLngToLayerPoint([coordinates[0].lat,coordinates[0].long]);
svg.selectAll('circle').data(new Array(3))
.enter()
.append('circle')
.attr("cx",function(d,i){return coordenadas.x+i*10})
.attr("cy", function(d,i){return coordenadas.y+i*20})
.attr("r", 30)
.style("fill",'red')
.style('stroke', 'black')
.style('pointer-events', 'all')
.style('cursor', 'pointer')
.attr("class",'circulo_mapa')
.on("click", function(d,i){
console.log('this is the element', this);
alert("click on " + i)
})