ToJson issue with outline of a symbol

797
1
Jump to solution
07-14-2014 07:17 AM
AdrianMarsden
Occasional Contributor III

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"

                    }

                }]

            }

0 Kudos
1 Solution

Accepted Solutions
AdrianMarsden
Occasional Contributor III

Sorted

I hadn't converted the outline colour using the same function I used for fill colour

function hexToRgb(hex, alpha) {

    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);

    return result ? {

        r: parseInt(result[1], 16),

        g: parseInt(result[2], 16),

        b: parseInt(result[3], 16),

        a: alpha

    } : null;

}

this gets it into the correct format for saving a retrieving - I can't remember why!

View solution in original post

0 Kudos
1 Reply
AdrianMarsden
Occasional Contributor III

Sorted

I hadn't converted the outline colour using the same function I used for fill colour

function hexToRgb(hex, alpha) {

    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);

    return result ? {

        r: parseInt(result[1], 16),

        g: parseInt(result[2], 16),

        b: parseInt(result[3], 16),

        a: alpha

    } : null;

}

this gets it into the correct format for saving a retrieving - I can't remember why!

0 Kudos