jquery - How to select shape on canvas and return its name? -
i draw several shapes on canvas using jcanvas library function:
var factorycounter = 1; $(".atom").click(function() { //get element 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 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 need return "name", don't know how. } }); factorycounter++; as can see each shape has own unique name. i'd create function returns name of selected shape after click on mouse. can successful edit attributes of shape name known, this:
$("canvas").setlayer("myatom" + 2, { fillstyle: "#36b", width: 100, height: 200, rotate: 30 }) .drawlayers(); }); but have no idea how implement shapeselect() function returns name of existing shape clicking on it.
alright asked guy did library , showed me right answer. in case need it, here is:
well, rather having click event bound canvas element, set click event each new jcanvas layer. when click 1 of layers, have callback function switch between it's going do, based on layer property create (such layer.selected). here's basic idea:
$("canvas").drawimage({ // image properties here... layer: true, name: "somelayer", selected: false, click: function(layer) { if (layer.selected === false) { layer.selected = true; // layer name } else if (layer.selected === true) { layer.selected = false; // deselect layer } } }); -caleb
Comments
Post a Comment