AnsweredAssumed Answered

ToJson issue with outline of a symbol

Question asked by amarsden on Jul 14, 2014
Latest reply on Jul 14, 2014 by amarsden

Hi I have the follow routine that takes a newly made graphic and add the details to Local Storage.  The idea is that it is then retrieved the next time the user uses the application

 

    var graphic = new esri.Graphic(geometry, symbol);
    console.debug(graphic)
    // store to local storage  graphic added 
    var now = new Date();
    var n = now.getTime();
    GraphicName = "storedGraphic" + n;
    window.localStorage.setItem(GraphicName, dojo.toJson(graphic.toJson()));
    console.debug(dojo.toJson(graphic.toJson()));
    graphic.setAttributes({
        newID: GraphicName
    });
    userGraphics.add(graphic);

 

It works fine, however I have recently given the users the ability to change outline colour.

 

This then fails.

 

Looking at my debugs - the first one (line 2 - I do like the new code format here, if nothing else ) returns

 

 

Object {geometry: Object, symbol: Object, attributes: undefined, infoTemplate: undefined, declaredClass: "esri.Graphic"…}

 

  1. _extent: Object
  2. _graphicsLayer: Object
  3. _offsets: Array[1]
  4. _shape: Object
  5. attributes: Object
  6. geometry: Object
  7. infoTemplate: undefined
  8. symbol: Object
    1. _inherited: Object
    2. color: b.Color
    3. outline: Object
      1. _inherited: Object
      2. color: "#ff0000"
      3. style: "solid"
      4. width: "2"
      5. __proto__: Object
    4. style: "solid"
    5. __proto__: Object
  9. __proto__: Object

 

Notice the Colour FF0000 - basically pure red.

 

Now my second debug line, echoing out the JSON that I store into Local Storage

 

{"geometry":{"rings":[[[323189.8652275379,87282.84014002334],[326479.760210035,88064.1901983664],[327302.23395565926,84363.05834305717],[323888.9679113185,82430.24504084015],[323189.8652275379,87282.84014002334]]],"spatialReference":{"wkid":27700}},"symbol":{"color":[0,0,0,179],"outline":{"color":[null,null,null,null],"width":1.5,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}}

 

Look at all those nulls !

 

This means that the feature isn't retrieved properly, and I think may be causing issues with my print routine.

 

Any ideas anyone?

 

Cheers


ACM

 

 

Edit - yep this has a similar issue on printing - heres the Json of my print request - the same set of nulls

 

  "featureSet": {
                "geometryType": "esriGeometryPolygon",
                "features": [{
                    "geometry": {
                        "rings": [
                            [
                                [310770.51166861143,
                                    83910.69778296383
                                ],
                                [314677.2619603267,
                                    85473.39789964995
                                ],
                                [315211.8698949825,
                                    81525.52392065345
                                ],
                                [313073.4381563594,
                                    81114.28704784131
                                ],
                                [310770.51166861143,
                                    83910.69778296383
                                ]
                            ]
                        ],
                        "spatialReference": {
                            "wkid": 27700
                        }
                    },
                    "symbol": {
                        "color": [0, 0, 0, 179],
                        "outline": {
                            "color": [null, null, null,
                                null
                            ],
                            "width": 1.5,
                            "type": "esriSLS",
                            "style": "esriSLSSolid"
                        },
                        "type": "esriSFS",
                        "style": "esriSFSSolid"
                    }
                }]
            }

Outcomes