AnsweredAssumed Answered

respectCurrentMapScale for Legend dijit not working?

Question asked by ggreen_triangletransit on May 28, 2015
Latest reply on May 29, 2015 by ggreen_triangletransit

The parameters for the constructor for the Legend digit says, in relevant part, as follows:

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



<Boolean> autoUpdateOptionalWhen 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


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");


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.




- geoff