Hi - I am using two attribute fields to create a UniqueValueRenderer for my feature layer. I am having trouble with specifying matches if a field has no value but is null. In the example below the first 'infos' object has two values to match the attribute fields being used, but the second info object I am trying match null fields of attribute field 1 and a value of attribute field 2. The second object (null one) is not working and the graphics revert to the default symbol. Any suggestions? I also tried leaving it blank (',Prospect').
var params = { "type" : "uniqueValue", "field1" : "sStatus", "field2" : "iStatus", "fieldDelimiter" : ", ", "defaultLabel" : "Unknown", "defaultSymbol" : { "color" : this.colors.noColor, "type" : "esriSFS", "style" : "esriSFSSolid", "outline" : { "color" : this.colors.opaqueGoldJSON, "type" : "esriSLS", "style" : "esriSLSSolid" } }, "uniqueValueInfos" : [{ "value" : 'In Service, Not Applicable', "label" : "In Service", "symbol" : { "color" : this.colors.lightBlueJSON, "type" : "esriSFS", "style" : "esriSFSSolid", "outline" : { "color" : this.colors.opaqueGoldJSON, "type" : "esriSLS", "style" : "esriSLSSolid" } } }, { "value" : 'null, Prospect', "label" : "Prospect", "symbol" : { "color" : this.colors.goldJSON, "type" : "esriSFS", "style" : "esriSFSSolid", "outline" : { "color" : this.colors.opaqueGoldJSON, "type" : "esriSLS", "style" : "esriSLSSolid" } } }] }; allRenderers.cdbServiceRenderer2 = new UniqueValueRenderer(cdbServiceRendererParams2);
Sarah,
This worked for me (just omitting the null value in the value property):
var params = { "type": "uniqueValue", "field1": "NEIGHBORHOOD", "field2": "NPPIN", "fieldDelimiter": ", ", "defaultLabel": "Unknown", "defaultSymbol": { "color": [0, 0, 0, 128], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [0, 0, 0, 255], "type": "esriSLS", "style": "esriSLSSolid" } }, "uniqueValueInfos": [ { "value": '03-001.0, ', "label": "03-001.0, null", "symbol": { "color": [128, 0, 0, 128], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [128, 0, 0, 255], "type": "esriSLS", "style": "esriSLSSolid" } } }, { "value": '03-001.0, 801', "label": "03-001.0, 801", "symbol": { "color": [0, 0, 128, 128], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [0, 0, 128, 255], "type": "esriSLS", "style": "esriSLSSolid" } } }] };
Hi Robert - Thanks for the input. I did mention I tried that but it did not work for me.
It raises an interesting point though, because I am working with domains. Are you?
Sarah,
In that test I was not using fields that had domains. Are your domains coded value text or integers?
Coded value
Ok text or integer values though?
text
Sarah,
OK, I setup some data with a coded text domain for both sStatus and iStatus in a FGDB and then used this JSON and I still had no issue using the null value.
var params = { "type": "uniqueValue", "field1": "iStatus", "field2": "sStatus", "fieldDelimiter": ", ", "defaultLabel": "Unknown", "defaultSymbol": { "color": [128, 128, 128, 255], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [128, 128, 128, 128], "type": "esriSLS", "style": "esriSLSSolid" } }, "uniqueValueInfos": [ { "value": 'IS, NA', "label": "In Service", "symbol": { "color": [0, 0, 255, 255], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [0, 0, 255, 128], "type": "esriSLS", "style": "esriSLSSolid" } } }, { "value": 'IS, CC', "label": "In Service", "symbol": { "color": [255, 0, 255, 255], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [255, 0, 255, 128], "type": "esriSLS", "style": "esriSLSSolid" } } }, { "value": ', Prospect', "label": "Prospect", "symbol": { "color": [128, 0, 128, 255], "type": "esriSFS", "style": "esriSFSSolid", "outline": { "color": [128, 0, 128, 128], "type": "esriSLS", "style": "esriSLSSolid" } } }] };
This issue reared its head again. I should say I am using SDE databases not FGDB.
The getUniqueValueInfo function of the UniqueValueRenderer takes a graphic, examines its attributes, and returns an info object with the symbol. I've copied that same function and updated it to instead return the index it creates from the graphic's attributes. If you could get a look at these indexes, this information should tell you what values you need to specify when setting up your renderer. I haven't tested this, but here it is:
var featureLayer = map.getLayer("my_layer_id"); var renderer = featureLayer.renderer; var graphics = featureLayer.graphics; renderer.getUniqueValueInfo2 = function(a) { var b = this.attributeField, d = a.attributes, e, f; this._multiple ? (a = this.attributeField2, e = this.attributeField3, f = [], b && f.push(d), a && f.push(d), e && f.push(d), b = f.join(this.fieldDelimiter || "")) : b = c.isFunction(b) ? b(a) : d; return ... for (var x = 0; x < graphics.length; x++) console.info(x.toString() + ": [" + renderer.getUniqueValueInfo2(graphics) + "]");