Fabric.js: Object visibility properties are not serialized with canvas.toJSON method

Created on 13 Nov 2013  路  2Comments  路  Source: fabricjs/fabric.js

I'm using the new setControlsVisibility to remove the rotation point of an object. When exporting to JSON and loading a new canvas from the serialized JSON string, the rotation point is back.

http://jsfiddle.net/7ScM7/1/

It looks like there's no controls visibility information at all in the serialized data:

{
  "objects":[
    {
      "type":"rect",
      "originX":"left",
      "originY":"top",
      "left":10,
      "top":10,
      "width":50,
      "height":50,
      "fill":"rgb(0,0,0)",
      "stroke":null,
      "strokeWidth":1,
      "strokeDashArray":null,
      "strokeLineCap":"butt",
      "strokeLineJoin":"miter",
      "strokeMiterLimit":10,
      "scaleX":1,
      "scaleY":1,
      "angle":0,
      "flipX":false,
      "flipY":false,
      "opacity":1,
      "shadow":null,
      "visible":true,
      "clipTo":null,
      "backgroundColor":"",
      "rx":0,
      "ry":0,
      "x":0,
      "y":0
    }
  ],
  "background":""
}

Most helpful comment

You need to specify what are the properties you want saved when exporting. For example :

//will save properties set through setControlsVisibility
var json = canvas.toJSON(['_controlsVisibility']);

This is done to optimize the amount of data saved when serializing objects.
I'm not sure if we're supposed to add private properties through the functionality though.

All 2 comments

You need to specify what are the properties you want saved when exporting. For example :

//will save properties set through setControlsVisibility
var json = canvas.toJSON(['_controlsVisibility']);

This is done to optimize the amount of data saved when serializing objects.
I'm not sure if we're supposed to add private properties through the functionality though.

Ahh, my bad.

Since this feature is quite new, I didn't find any information on it.

Thanks for pointing out a solution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medialwerk picture medialwerk  路  5Comments

eddieyangtx picture eddieyangtx  路  5Comments

mlev picture mlev  路  3Comments

raichu picture raichu  路  4Comments

lyzs90 picture lyzs90  路  3Comments