6

I want to detect the onClick & onHover on different parts of a image.

<img src={physicalimage} id="physicalimage" usemap="#image-map"/>
   <map name="image-map">
   <area target="" onClick={this.consoleMessage("bpleft")} alt="bpleft" title="bpleft"  coords="223,201,269,254" shape="rect" />
   <area target="" onClick={this.consoleMessage("bpright")} alt="bpright" title="bpright" coords="60,199,101,259" shape="rect" />
   <area target="" onClick={this.consoleMessage("heart")} alt="heartrate"  title="heartrate" coords="169,124,219,183" shape="rect" />
</map>

I use react library for developing my website. I am not able to detect the onClick event. Are there any other alternative?

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166

2 Answers2

4

I suggested you to use a maintained library with the all feature of react-image-mapper with extra functionality like responsive

https://github.com/NishargShah/react-img-mapper

https://www.npmjs.com/package/react-img-mapper

Nisharg Shah
  • 16,638
  • 10
  • 62
  • 73
2

I'm currently doing exactly the same myself and have stumbled across this Package: React Image Mapper

So far, it seems to do everything I need. Hopefully it's of use to someone else in the future.

Stu1986C
  • 1,452
  • 1
  • 18
  • 34