The parameters for the constructor for the Legend digit says, in relevant part, as follows:
<Boolean > respectCurrentMapScale | Optional | When true the legend will update with every scale change and displays only the layers and sub layers that are visible in the current map scale. When false, the legend does not update on every scale change and all layers and sub layers will be displayed. The default value is true. |
and
<Boolean > autoUpdate | Optional | When false, the legend will not automatically update if the map changes scale or when layers are added are removed from the map. Call refresh to force a legend update. The default value is true. Added at v3.10 |
I have the following constructor for a legend digit:
var legend = new Legend({
map: map,
autoUpdate: true,
layerInfos: legendLayers
},'LegendDiv');
Legend appears. And, the title of the Legend digit autoupdates as I switch between viewable layers (I have four layers, only one is viewable at once.) However, the contents of the legend digit do not change, no matter whether I switch between layers, pan or zoom on the map, nothing.
I would think there's some bug in my code. However, this sample code on the Esri website doesn't work either. You can try the live version. The legend constructor code is:
var legendDijit = new Legend({
map: map,
layerInfos: layerInfo
}, "legendDiv");
legendDijit.startup();
The front of the sample code page says "You can also set the respectCurrentMapScale parameter to true if you want the legend to only display layers that are visible in the current map scale." That shouldn't be necessary because respectCurrentMapScale should default to true. However, even if you change the code in the sandbox to explicitly set it to true, it still doesn't automatically update based on the map scale.
What's going on here? Is it broken? Am I fundamentally misunderstanding something? I'm still pretty new to using the ArcGIS Javascript API, but it's driving me a bit bonkers.
Thanks.
- geoff