In the context of a layer object, layer visibility and the visible scale range for a layer are mutually exclusive. This is not intuitive. We've discussed this internally but have not come up with a cleaner implementation for the API. A layer's visible property can be true (and when it is, it should be included in the legend), but if you're outside the visible scale range for the layer, you do not see it on the map. This is what I was suggesting. If it's not what you're seeing, please contact support and log a bug.
So in other words the legend doesn't work on invisible layer period!
Using refresh() might not be the best way to do this. Apologies for sending you down that road. The legend respects layer visibility so if you're using respectCurrentMapScale: false, and you toggle your layer's visibility, the legend should update correctly. Instead of trying to manually refresh the legend, can your event handler that fires when your drop-down changes update a layer's visibility? That would look something like: var layer = map.getLayer(layerId); layer.setVisibility(!layer.visible);
var layer = map.getLayer(layerId); layer.setVisibility(!layer.visible);
Does LoadLegend run throughout the life of your app or is RecreateLegend called from other places?
Try calling refresh() and pass in layerInfos for the layers you want to show.
By default, the legend only displays info for visible layers. You can override this via a boolean constructor parameter called respectCurrentMapScale.
In BadLegend.png, is your map at a scale where your map service should be visible?
Do you see a request going to your legend endpoint when your app loads? I've attached a screen shot of what this looks like in chrome dev tools' network tab. Also, here's a working sample of using a dynamic layer and a legend: http://jsfiddle.net/kq6bx/
Which version of server are you using (including service pack)? Generating legends via your own AGS instance requires 10.0 sp1 or later.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.