Reactjs 将事件侦听器附加到react中的svg元素
我还没有反应过来。 我的react web应用程序中有d3地图。我需要将单击事件附加到地图上。有人可以告诉我如何将单击附加到此地图上吗Reactjs 将事件侦听器附加到react中的svg元素,reactjs,d3.js,svg,Reactjs,D3.js,Svg,我还没有反应过来。 我的react web应用程序中有d3地图。我需要将单击事件附加到地图上。有人可以告诉我如何将单击附加到此地图上吗 const County=({geoPath,feature})=>( // ); ---------- render(){ 如果(!this.props.usTopoJson){ 返回null; }否则{ 设颜色='rgb(42,73120)'; //让颜色=橙色; const us=this.props.usTopoJson, statesMesh=t
const County=({geoPath,feature})=>(
//
);
----------
render(){
如果(!this.props.usTopoJson){
返回null;
}否则{
设颜色='rgb(42,73120)';
//让颜色=橙色;
const us=this.props.usTopoJson,
statesMesh=topojson.mesh(美国,美国。对象。国家。几何体,(a,b)=>a!==b),
countries=topojson.feature(us,us.objects.countries).features;
返回(
//
{this.myG=g;}}>
{countries.map((功能)=>
)}
);
}
}
是否尝试将
onClick
添加为
const County = ({geoPath,feature}) => (
//<path d={geoPath(feature)} style={{fill: color}} title={feature.id} />
<path d={geoPath(feature)} style={{fill: color(Math.random()*5)}} title={feature.id} />
);
----------
render(){
if(!this.props.usTopoJson){
return null;
}else{
let color = 'rgb(42,73,120)';
//let color = 'orange';
const us = this.props.usTopoJson,
statesMesh=topojson.mesh(us,us.objects.countries.geometries,(a,b) => a !==b),
countries = topojson.feature(us,us.objects.countries).features;
return(
//<g>
<g ref={(g) => { this.myG = g; }}>
{countries.map((feature) =>
<County geoPath={this.geoPath}
feature={feature}
key={feature.id}
quantize={this.quantize} />)}
<path d={this.geoPath(statesMesh)} style={{fill:'color',stroke:'#aaa',
strokeLinejoin:'round'}}/>
</g>
);
}
}
<County geoPath={this.geoPath}
onClick={someHandleClickFunc}
feature={feature}
key={feature.id}
quantize={this.quantize} />