Search code examples
canvaskineticjs

canvas or kineticJS elementFromPoint (x,y) equivalent


Can somone help me to find the way how to retrieve canvas element on certain x,y using elementFromPoint (x,y) or some other way? Currently the elementFromPoint (x,y) returns just canvas. I need it for automated test purposes.


Solution

  • A Demo: http://jsfiddle.net/m1erickson/6vRVn/

    You can use layer.getIntersection({x:10,y:10}) to get the shape under the specified position:

    var shape=layer.getIntersection(positionObject);

    This returns the topmost element at that intersection position.

    If your shapes are always rectangular or circular, then math bounds checking is faster.