Select to view content in your preferred language

Changing the Order of Legends

264
1
04-19-2023 08:59 PM
HHAO
by
New Contributor II

When there is already a legend, I will add another layer to show the legend of this layer as the first one instead of the last one.

0 Kudos
1 Reply
Sage_Wall
Esri Contributor

Hi @HHAO ,

Can you please provide more information about how you are adding the layer and observing this behavior?

By default when using the map.add() method the new layer should be added on top of the older layers as shown in this codepen.  The codepen initially loads with a map and one layer, then after a five second delay adds a second layer which appears at the top of the legend and layer list.  You can also set an optional index parameter in the map.add() method to explicitly specify where the new layer is added in the layers collection.  The order of the layers in the layers property on the map object is what determines the order of the layers displayed in the legend.

0 Kudos