getImageData() is a Canvas 2D context method for reading pixel data from a rectangular canvas region. In an interaction layer, a 1×1 rectangle at the mouse position reveals the pixel’s color, which can identify the visual object underneath. section 15.4
A Canvas interaction strategy uses getImageData() in a short pipeline:
- Read the first three values of data as RGB components, build the matching color string, and look up the node in the Map. section 15.4
Detecting a hovered painting circle
A hidden canvas duplicates the painting circles with unique colors. When the pointer moves, getImageData() samples one pixel at the pointer location. The resulting RGB color retrieves the corresponding painting, allowing a tooltip to display its title, link, and position. If the canvas was scaled for the screen’s resolution, multiply the event coordinates by window.devicePixelRatio before sampling.
