2017-02-15 11 views
0

Я довольно новый, чтобы реагировать. У меня есть карта d3 в моем веб-приложении для взаимодействия. Мне нужно прикрепить событие click к карте. Может кто-нибудь, пожалуйста, дайте мне знать, как я могу прикрепить клик к этой карте?Прикрепление слушателя событий к элементу 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} /> 

 Смежные вопросы

  • Нет связанных вопросов^_^