Select to view content in your preferred language

legendElements is empty for FeatureLayers

914
7
Jump to solution
10-21-2024 12:57 AM
LittleTurtle
Occasional Contributor

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?

0 Kudos
2 Solutions

Accepted Solutions
JoelBennett
MVP Regular Contributor

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."

View solution in original post

JoelBennett
MVP Regular Contributor

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.

View solution in original post

7 Replies
Sage_Wall
Esri Regular Contributor

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.

0 Kudos
LittleTurtle
Occasional Contributor

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.

0 Kudos
JoelBennett
MVP Regular Contributor

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."

Sage_Wall
Esri Regular Contributor

👍 to unique value groups.  Sorry about the confusion around legendElements, I guess that is documented... 

LittleTurtle
Occasional Contributor

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

0 Kudos
JoelBennett
MVP Regular Contributor

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.

LittleTurtle
Occasional Contributor

Yes it is what I was looking for, it is working fine now, thank you for your help 🙂

0 Kudos