Renderer fromJson

780
7
Jump to solution
11-05-2019 11:40 PM
ClemensMöller
New Contributor II

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.

var flurLayer = new FeatureLayer({
                url: "...",
                fields: ["art""render_pro", "katalog"],
                title: "Flurstuecke",
                renderer: rendererJsonUtils.fromJSON(sr)
            })
         var sr = {
                "type": "simple",
                "symbol": {
                        "type": "esriSFS",
                        "style": "esriSFSSolid",
                        "color": [25525500.5],

                        "outline": {
                            "type": "esriSLS",
                            "style": "esriSLSSolid",
                            "color": [002551],
                            "width": 1.0
                        }
                    },
                "label": "",
                "description": "",
                "rotationType": "geographic",
                "rotationExpression": ""
            }
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ClemensMöller
New Contributor II

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.

View solution in original post

0 Kudos
7 Replies
BenElan
Esri Contributor

Hi Clemens,

The JSON variable (sr) should be declared before the feature layer (flurLayer)

0 Kudos
ClemensMöller
New Contributor II

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.

0 Kudos
AlexZotos
New Contributor

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)

0 Kudos
ClemensMöller
New Contributor II

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?

0 Kudos
AlexZotos
New Contributor

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

0 Kudos
ClemensMöller
New Contributor II

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 )

0 Kudos
ClemensMöller
New Contributor II

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.

0 Kudos