我使用带有此功能的 jCanvas 库在画布上绘制了几个形状:
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++;
如您所见,每个形状都有自己独特的名称。我想创建一个函数,在我用鼠标单击它后返回所选形状的名称。我可以成功编辑名称已知的形状的属性,如下所示:
$("canvas").setLayer("myAtom" + 2, {
fillStyle: "#36b",
width: 100, height: 200,
rotate: 30
})
.drawLayers();
});
但不知道如何实现 shapeSelect() 函数,该函数通过单击返回现有形状的名称。