Reputation: 301
I need to deserialize a serialized canvas to another canvas which is bigger, how do I manage to move all the elements from the serialized JSON so I can fix the position on the new canvas?
Upvotes: 0
Views: 236
Reputation: 301
I ended using this, passing the json objects that FabricJs generate
fabric.util.enlivenObjects()
then i fixed the positon of the elements and added to the new canvas
var iOCanvasJSON = JSON.stringify(baseCanvas);
var jsonO = JSON.parse(iOCanvasJSON);
fabric.util.enlivenObjects(jsonO.objects, function (enlivenedObjects) {
for (var i = 0; i < enlivenedObjects.length; i++) {
var oldTop = enlivenedObjects[i].top ;
enlivenedObjects[i].top = oldTop + 100;
canvasO.add(enlivenedObjects[i]);
}
canvasO.renderAll();
});
Upvotes: 1