I draw several shapes on a canvas using the jCanvas library with this function:
var factoryCounter = 1;
$(".atom").click(function() {
//get element by tag id
var AtomId = jQuery(this).attr("id");
var elementRef = "#el" + factoryCounter;
$("canvas")
.drawImage({
source:'images/' + AtomId + '.png',
layer: true,
name: "myAtom" + factoryCounter, //I need this value
fillStyle: "#36b",
strokeStyle: '#36b',
strokeWidth: 0.3,
x: 36, y: 28,
width: 45, height: 35,
radius: 100,
ccw: true,
draggable: true,
click: function(layer) {
console.log("name") //here I need to return "name", but don't know how.
}
});
factoryCounter++;
As you can see each shape has its own unique name. I'd like to create a function which returns the name of the selected shape after I click on it with the mouse. I can successful edit the attributes of a shape which NAME is known, like this:
$("canvas").setLayer("myAtom" + 2, {
fillStyle: "#36b",
width: 100, height: 200,
rotate: 30
})
.drawLayers();
});
But have no idea how to implement shapeSelect() function which returns the NAME of an existing shape by clicking on it.