Normally an object\'s position relative to the canvas can be gotten from it\'s .left
and .top
attributes, but these become relative to the group if
Had to solve this issue with another approach... I had to find images in JSON canvas data, so my code is:
let findItemByType = function(source, type, rX, rY)
{
rX = rX ? rX : 0;
rY = rY ? rY : 0;
let objs = [];
source.forEach(function(item){
if (item.type === type){
item.rX = rX + item.left;
item.rY = rY + item.top;
objs.push(item);
}
else {
if (item.objects)
{
item.rX = rX;
item.rY = rY;
let subresult = findItemByType(item.objects,
type,
item.rX + item.left + item.width / 2,
item.rY + item.top + item.height / 2);
if (subresult){
objs = objs.concat(subresult);
}
}
}
});
return objs;
}
let images = findItemByType(canvas.toJSON().objects, "image", 0, 0);
This code should bring an array of all image objects and they should have rX and rY attributes which is relative positions of images.