2017-02-15 69 views
0

我對React很新穎。 我在我的反應web應用程序中有d3地圖。我需要在地圖上附加一個點擊事件。任何人都可以讓我知道我該如何在此地圖上添加點擊?將事件監聽器附加到反應中的svg元素


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

    } 
+0

你嘗試加入'onClick'爲''屬性 – DroidNoob

回答

0
<County geoPath={this.geoPath} 
      onClick={someHandleClickFunc} 
      feature={feature} 
      key={feature.id} 
      quantize={this.quantize} /> 
相關問題