Hello,
I have a Legend in v4.30 which works fine, it is based on a Map with multiple FeatureLayers.
I am trying to modify the Legend by updating the legendElements (I have duplicate symbology with same title and I want to merge them) but when displaying activeLayerInfos I can see my list of layers but legendElements is always empty.
Is this a classic behavior with FeatureLayer or am I missing something?
Solved! Go to Solution.
If I'm understanding this correctly, and you're using a UniqueValueRenderer, then using uniqueValueGroups rather than uniqueValueInfos might solve this problem. This was a fairly recent addition that didn't make it into 3.x at the time. As it says in the documentation, "Unique value groups also allow you to combine or merge multiple unique values to a single class so they are represented by one symbol and one label."
You'll probably have better luck looking at the documentation for UniqueValueRenderer under the Web Map Specification.
This is not the first time this has come up (example)...it would be good if the SDK documentation could link to it or something.
Hi @LittleTurtle,
legendOptions is not part of the public API and shouldn't be used in this way. If you want to control the layer's that are displayed in the Legend take a look at the legendEnabled property on the layer or the layerInfos property on the Legend. They are both part of the public API.
Thank you for your response @Sage_Wall, I saw legendElements in the documentation that's why I thought it could be a solution but it must be readonly only
So my problem is that I am not able to reproduce the behavior I had with the v3 API which is that when the symbol and label are the same for 2 values (for example for a list of UniqueValuInfo) it is only displayed once in the legend, in v4 it is displayed twice.
If I'm understanding this correctly, and you're using a UniqueValueRenderer, then using uniqueValueGroups rather than uniqueValueInfos might solve this problem. This was a fairly recent addition that didn't make it into 3.x at the time. As it says in the documentation, "Unique value groups also allow you to combine or merge multiple unique values to a single class so they are represented by one symbol and one label."
Ok thank you @JoelBennett and @Sage_Wall, I think uniqueValueGroups is indeed the solution.
We are using a JSON config file but I'm having some trouble to make it work ; the legend works great now but my layer does not show on the map (everything shows up as defaultSymbol):
...
"render": {
"type": "uniqueValue",
"field": "FIELD_1",
"field2": "FIELD_2",
"defaultLabel": "Other",
"defaultSymbol": {
"type": "esriSMS",
"style": "esriSMSCircle",
"color": [
2,
2,
2,
255
],
"size": 24,
"outline": {
"color": [
100,
100,
100,
255
],
"width": 1
}
},
"uniqueValueGroups": [
{
"heading": " ",
"classes": [
{
"label": "OK",
"values": [
{
"value": "OK",
"value2": "value1"
},
{
"value": "OK",
"value2": "value2"
}
],
"symbol": {
"type": "esriSMS",
"style": "esriSMSCircle",
"color": [
50,
200,
0,
255
],
"outline": {
"color": [
10,
10,
10,
255
],
"width": 1
},
"size": 24
}
}
]
},
...
I have found this documentation but it does not cover univalueGroups
You'll probably have better luck looking at the documentation for UniqueValueRenderer under the Web Map Specification.
This is not the first time this has come up (example)...it would be good if the SDK documentation could link to it or something.
Yes it is what I was looking for, it is working fine now, thank you for your help 🙂