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