respectCurrentMapScale for Legend dijit not working?

3782
3
Jump to solution
05-28-2015 07:18 PM
deleted-user-m6DuRVNpNiGp
New Contributor III

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.

and

<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
},'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

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

I don't find any problem with the sample application, that you have posted above. The legend control seem to work as expected. I can see that the 2 layers are visible on the map and the legends for those 2 layers. And when you zoom out the layers are not visible and there is no legends as well.

What do you find not working in this?

View solution in original post

3 Replies
thejuskambi
Occasional Contributor III

I don't find any problem with the sample application, that you have posted above. The legend control seem to work as expected. I can see that the 2 layers are visible on the map and the legends for those 2 layers. And when you zoom out the layers are not visible and there is no legends as well.

What do you find not working in this?

deleted-user-m6DuRVNpNiGp
New Contributor III

Thank you, your note pointed out that I was misunderstanding how the autoupdate functioned. From reading the description I assumed that by only showing items "that are visible in the current map scale," the legend would change not only as visibility changed by zooming in or out, but also by panning onto an area of the map with no features. Obviously, reading it a bit more closely and in the light of morning, that's not what it means by "current map scale," and it does work as promised when zooming in and out. Thanks for the comment/answer.

0 Kudos
RobertKirkwood
Occasional Contributor III

Is there a way to only show items in the legend that are displayed in the map? For example, I have 4 symbols for a feature. If I zoom in and only 2 symbols are visible can the legend update to show only those 2 symbols? 

0 Kudos