Select to view content in your preferred language

Incorrect sample code for labelling

191
4
Jump to solution
01-13-2025 12:39 PM
TedZhou
Occasional Contributor

The sample code 

https://developers.arcgis.com/javascript/latest/sample-code/layers-subtypegrouplayer/

seems to be incorrect.

If we change :

  item.layer.labelsVisible = true;
 
the labels are shown as below:
 
TedZhou_0-1736800464112.png

 

 ArcGIS users as us intend to learn what the following expression exactly means from ArcGIS team actually.
 
        labelExpression: "$feature.assetgroup"
 
The sample code just confused me.
 
ArcGIS team did great work.
 

 

 

 

 

Tags (1)
0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

I think what the sample is doing is showing how to do different things with the layers. If you click the gear icon on a layer, the "Labels" button will show or hide the labels and the "unique" button will symbolize the data with a simple renderer or a unique-value renderer.

The labelExpression seems to be a mistake. If you replace that line with

 

labelExpressionInfo: {
  expression: "$feature.assetgroup"
}

 

the labels show unique information

Snag_1b43a60.png

If you find errors in the sample code, it's more helpful to give feedback directly to Esri about this. To do that, scroll to the bottom of the page and click the thumbs down icon. This will bring up a dialog to send a message to the team.

Snag_1b63fc5.png

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

After a little more testing, you can also change it to this to get the same result

labelExpression: "[assetgroup]"

 

 

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

I think what the sample is doing is showing how to do different things with the layers. If you click the gear icon on a layer, the "Labels" button will show or hide the labels and the "unique" button will symbolize the data with a simple renderer or a unique-value renderer.

The labelExpression seems to be a mistake. If you replace that line with

 

labelExpressionInfo: {
  expression: "$feature.assetgroup"
}

 

the labels show unique information

Snag_1b43a60.png

If you find errors in the sample code, it's more helpful to give feedback directly to Esri about this. To do that, scroll to the bottom of the page and click the thumbs down icon. This will bring up a dialog to send a message to the team.

Snag_1b63fc5.png

0 Kudos
TedZhou
Occasional Contributor

 

Thanks for your time and kind efforts.

0 Kudos
KenBuja
MVP Esteemed Contributor

After a little more testing, you can also change it to this to get the same result

labelExpression: "[assetgroup]"

 

 

TedZhou
Occasional Contributor

That is a reasonable design. Thanks for your great assistance. 

0 Kudos