"No Legend" appears in Legend some ArcGISDynamicMapServiceLayers

1200
16
Jump to solution
05-23-2012 07:32 AM
GregoryDillon
New Contributor III
I'm having an issue with some ArcGISDynamicMapServiceLayers displaying "No Legend" in the legend when there should be one.  

Here is the code for one of the layers I'm having a problem with:

WaterLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://pri-img-rep-web.abcwua.org/ArcGIS/rest/services/WUAGISWater/MapServer");
    WaterLayer.id = "Water";
    map.addLayer(WaterLayer);
    AddLayerToRegistryPendList(WaterLayer);

Here is the code for displaying the legend for this layer:

var LegDiv = dojo.byId("LegendDiv");

      LegendControl = new esri.dijit.Legend({
        map: map,
        layerInfos: [{
            layer: map.getLayer("Water"),
            title: " "
        }]
    }, LegDiv);

    LegendControl.startup();


Attached is a image of the raw dump of the legend in the service.


Help!   What is wrong???  Is there a setting I need to adjust in the service.
0 Kudos
1 Solution

Accepted Solutions
GregoryDillon
New Contributor III
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.


I think the respectCurrentMapScale flag makes sense.   It seems to me the Legend just needs another option to allow it to show layers that are not visible regardless of scale.   In other just the same way the service call to the legend works (http://.../Legend).  

As an example of such a need:

My app is designed for mobile.    I am trying very hard not to display anything like a info window on the map.    This often is annoying to the user and means limited space to touch things.    For that reason when the user selects the legend icon the map disappears and goes to a dedicated screen just for the legend.   I wanted the legend to show every layer the user could turn on in the map.   They select the layer name (this used to be category or dynamic service ID, but the spec changed at the end of this post) and legend is then focus on that layer whether it is turned on or not.    My fix was to add a temporary layer using the url from a layer already retrieved from the map which I look up by the layer name (not the dynamic service's name but the actual name of the layer - ie via layerinfos).   I think had get the layer id and add to the temporary layer's visiblelayers to flip it on.   If the map had been visible (for my app its not) the user would have seen the layer added to the map (really bad).    If the legend just had this new flag I would have just needed to turn it on.

View solution in original post

0 Kudos
16 Replies
derekswingley1
Frequent Contributor
Which version of server are you using (including service pack)? Generating legends via your own AGS instance requires 10.0 sp1 or later.
0 Kudos
GregoryDillon
New Contributor III
Which version of server are you using (including service pack)? Generating legends via your own AGS instance requires 10.0 sp1 or later.


I'm using the following reference to the JS 2.8 API:

script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8compact">
    </script>
<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/claro/claro.css"
        rel="stylesheet" type="text/css" />


This is the PatchFinder info for the server where the web services are hosted (I also just tried hosting the site on the server and have the same issue!😞

ArcGIS Desktop 10
ArcGIS Desktop 10 Service Pack 1

ArcGIS Engine Runtime 10
ArcGIS Engine Runtime 10 Service Pack 1

ArcGIS Server 10 - GIS Services
ArcGIS Server for the Microsoft .NET Framework 10 - GIS Services Service Pack 1


ArcGIS Server 10 - Web Applications
ArcGIS Server for the Microsoft .NET Framework 10 - Web Applications Service Pack 1

ArcGIS Server 10 - Web ADF Runtime

ArcObjects SDK for the Microsoft .NET Framework 10.0
ArcObjects SDK for the Microsoft .NET Framework 10 Service Pack 1

ArcGIS VBA Resources 10.0

Data Interoperability Extension 10.0
Data Interoperability Extension Service Pack 1

This is the PatchFinder info for where the application is running (my dev box):

ArcGIS Desktop 10
ArcGIS Desktop 10 Service Pack 1
ArcGIS Desktop 10 Service Pack 2

ArcGIS Engine Runtime 10
ArcGIS Engine Runtime 10 Service Pack 1
ArcGIS Engine Runtime 10 Service Pack 2

ArcGIS Server 10 - GIS Services
ArcGIS Server for the Microsoft .NET Framework 10 - GIS Services Service Pack 1
ArcGIS Server for the Microsoft .NET Framework 10 - GIS Services Service Pack 2

ArcGIS Server 10 - Web Applications
ArcGIS Server for the Microsoft .NET Framework 10 - Web Applications Service Pack 1
ArcGIS Server for the Microsoft .NET Framework 10 - Web Applications Service Pack 2

ArcGIS Server 10 - Web ADF Runtime
ArcGIS Server for the Microsoft .NET Framework 10 - Web ADF Runtime Service Pack 2

ArcObjects SDK for the Microsoft .NET Framework 10.0
ArcObjects SDK for the Microsoft .NET Framework 10 Service Pack 1

ArcGIS VBA Resources 10.0

Data Interoperability Extension 10.0
Data Interoperability Extension Service Pack 1
Data Interoperability Extension Service Pack 2
0 Kudos
derekswingley1
Frequent Contributor
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/
0 Kudos
GregoryDillon
New Contributor III
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/


Attached are my Chrome Dev Tool outputs for a layer that is working (GoodLegend.png) and one that is bad (BadLegend.png).
0 Kudos
derekswingley1
Frequent Contributor
In BadLegend.png, is your map at a scale where your map service should be visible?
0 Kudos
GregoryDillon
New Contributor III
In BadLegend.png, is your map at a scale where your map service should be visible?



Okay looks like the legend only displays what is visible.   Can't believe I didn't think of that.   How do I tell it to show everything visible or not?
0 Kudos
derekswingley1
Frequent Contributor
By default, the legend only displays info for visible layers. You can override this via a boolean constructor parameter called respectCurrentMapScale.
0 Kudos
GregoryDillon
New Contributor III
By default, the legend only displays info for visible layers. You can override this via a boolean constructor parameter called respectCurrentMapScale.


Yes I tried that, it seems to fix the issue with visibility at scales, but still only displays what is visible.    I want user to the select a category (which is the same name as the "id" on the dynamic layer) and see the legend for all the layers in the dynamic layer - visible or not.   How do I see a legend for everything the same way as "http:/.../Legend".
0 Kudos
derekswingley1
Frequent Contributor
Try calling refresh() and pass in layerInfos for the layers you want to show.
0 Kudos