Select to view content in your preferred language

syntax for JSON uniqueValueRenderer on two fields

3865
3
Jump to solution
08-21-2012 09:58 AM
SteveCole
Honored Contributor
I am working on the code to add a FeatureLayer based on a JSON feed. I'm currently using a unique value renderer based on one field in the data and I'm using the style shown in the API documentation for esri.renderer.uniqueValueRenderer(json).

Let's say the field I'm currently using categorizes damage (Wind, Flood, Fire, etc) but there is an additional field which indicates severity (Low, Medium, High). I want to now incorporate that second field into my renderer. My current renderer code would look something like this:

          "drawingInfo": {      "renderer": {       "type": "uniqueValue",      "field1": "Category",      "defaultSymbol": {        "type": "esriPMS",        "url": "a/url/default.gif",        "contentType": "image/gif",        "width": 18,        "height": 18       },      "uniqueValueInfos":      [{       "value": "Flood",       "symbol": {         "type": "esriPMS",         "url": "a/url/flood.gif",         "contentType": "image/gif",         "width": 18,         "height": 18       }      },


To now incorporate the second field, would I just do the following?
          "drawingInfo": {      "renderer": {       "type": "uniqueValue",      "field1": "Category",                                         "field2": "severity",      "defaultSymbol": {        "type": "esriPMS",        "url": "a/url/default.gif",        "contentType": "image/gif",        "width": 18,        "height": 18       },      "uniqueValueInfos":      [{       "value": "Flood:Low",       "symbol": {         "type": "esriPMS",         "url": "a/url/floodLow.gif",         "contentType": "image/gif",         "width": 18,         "height": 18       }      },{       "value": "Flood:Medium",       "symbol": {         "type": "esriPMS",         "url": "a/url/floodMedium.gif",         "contentType": "image/gif",         "width": 18,         "height": 18       }      }


Thanks again!
Steve
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Deactivated User
i'm pretty sure commas are the appropriate way to separate values from multiple fields.

"value": "Flood, Low",


json example of layer rendered using multiple fields
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServ...

View solution in original post

3 Replies
JohnGravois
Deactivated User
i'm pretty sure commas are the appropriate way to separate values from multiple fields.

"value": "Flood, Low",


json example of layer rendered using multiple fields
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServ...
SteveCole
Honored Contributor
Thanks, John. I marked your response with "answered" since that's an ESRI sample (albeit buried in the hidden corners of ESRIdom).
I did not try a comma specifically but I did add the "fieldDelimiter" parameter like in that example and it wasn't honoring it. I had close to 30 unique values I wanted to symbolize and that was A LOT of formatted code in my function. I ended up dumping all of that in favor of using the renderer.AddValue() method which cleaned things up quite a bit and works for me. So, during the JSON import, I just apply a simple marker symbol to the data and then once the FeatureLayer is created, I overwrite the original renderer with the unique values renderer.

Everyone's happy! 😄

Steve
0 Kudos
JohnGravois
Deactivated User
im glad to hear you have what you need.  🙂
0 Kudos