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
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"
}
}]
}
Solved! Go to Solution.
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!
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!