I'm trying to add paths in a group by id. But it seems to either reversing the positions of the paths or the z-index - like [red,blue,green] goes [green,blue,red]. How do i do this the correct way?
var id_no;
var objList=[];
if (!id_no) { id_no=1; }
canvas.on('path:created',function(e) {
e.path.id=id_no;
objList.push(id_no);
id_no++;
});
$( "#path-group" ).on( "click", function() {
var group = new fabric.Group();
canvas.forEachObject(function(o) {
if (o.id > 0) {
group.addWithUpdate(o);
canvas.remove(o);
}
});
canvas.setActiveObject(group);
canvas.add(group);
});