I want to load a renderer from a JSON-String, but nothing shows. I can't find any error in the JSON-String, so I have no idea what is going wrong.
Solved! Go to Solution.
Found the solution: The color attribute accepts as alpha value values between 0 and 255, not just between 0 and . When I set a to 1, it was (almost) invisible, 255 makes it fully opaque.
Hi Clemens,
The JSON variable (sr) should be declared before the feature layer (flurLayer)
Hi Ben,
thanks for your answer, but it didn't work. Ich put the declaration of the JSON-String before the declaration of the layer, but the map doesn't show the layer. I tested declaring the renderer in javascript and that worked, so the error must be somewhere in the JSON or fromJson, but I don't know where.
If your JSON is a string you should use JSON.parse to make into an object for the feature layer.
Trying modifying this:
renderer: rendererJsonUtils.fromJSON(sr)
into this:
renderer: JSON.parse(sr)
I tried it but it did not work. As I understand it, the fromJSON method is build exactly for what I try to achieve. To create a javascript object for arcgis from a JSON-String. Why should I use JSON.parse instead?
Sometimes using something simpler is the way to go. If you console.log() the JSON.parse result what does it do? It should print a JSON object to the console which should contain the elements that your JSON string contains
While trying to log the JSON-Object to the console, I noticed, that sr is already a JSON object, that's the right input object for fromJSON. JSON.parse creates a JSON-Object from a string, this would be the previous step. The JSON object ist not accepted as a renderer, because some attributes must have different values in the renderer object and in the JSON object (i.e. the symbol type is esriSFS vs. simple-fill). This conversion is made in fromJSON (i think )
Found the solution: The color attribute accepts as alpha value values between 0 and 255, not just between 0 and . When I set a to 1, it was (almost) invisible, 255 makes it fully opaque.