If a fabric.Path object is cloned with clone() method ,the path object is not duplicated. I have seen this issue here https://github.com/kangax/fabric.js/issues/330 but the Version of Fabric js is different. Could some one please help me on this.
var obj = canvas.getActiveObject();
if (!obj) return;
var clone = obj.clone();
clone.set({
top: clone.get('top') + 150
});
canvas.add(clone);
canvas.renderAll();
Below is the error I am getting.
else {
fabric.util.enlivenObjects(object.paths, function(enlivenedObjects) {
delete object.paths;
callback(new fabric.PathGroup(enlivenedObjects, object));
****Uncaught TypeError: undefined is not a function****
});
}
};
The above code is working well for all the objects but the code is not working for Path Object
fabric.Path and fabric.PathGroup object's are async since fabric.js version 1.2.2 (https://github.com/kangax/fabric.js/commit/c8cab03aace5510554cd02fa143248ab7497f6c2).
So you have to differentiate between async and sync objects.
var obj = canvas.getActiveObject();
if (!obj) return;
if (fabric.util.getKlass(obj.type).async) {
obj.clone(function (clone) {
clone.set({left: 200, top: 100});
canvas.add(clone);
});
}
else {
canvas.add(obj.clone().set({left: 100, top: 100}));
}
Here you can see it in action: http://jsfiddle.net/Kienz/73Cta/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With