Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have published a mapserver on my ArcGIS Server 9.3. I am developing a silverlight application using ArcGIS Silverlight API. Now I can load my map into my application and also the list of my layers that I can toggle their visibility. I just want to load my map legend in order to know the legend of each layer. The solution which I find in arcgis silverlight example is just as follow:

<esri:Legend Map="{Binding ElementName=Map}" 
    LayerIDs="BaseLayer"
    LayerItemsMode="Tree"
    />

In visual studio 2010, I have an error for LayerIDs part which says that "Unable to cast from....". The definition of my map is also:

<esri:Map x:Name="Map"  Background="White" MouseClick="QueryPoint_MouseClick" IsLogoVisible="False">
    <esri:OpenStreetMapLayer ID="OpenStreetMap" Style="Mapnik">
    </esri:OpenStreetMapLayer>

    <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"   
            Url="http://sina-pc/ArcGIS/rest/services/Test/MapServer"
    Initialized="ArcGISDynamicMapServiceLayer_Initialized" />            
</esri:Map>

It also doesn't show any of my legends for BaseLayer map. Am I missing something or is there any problem with my map? Thanks for your helps.

share|improve this question
add comment

2 Answers 2

Crazy, but nevertheless... I was using AGS 10 sp1 and could not get a legend to show up from an internal test server (it could not connect to internet). For AGS below 10 sp2, AGS must be able to connect to ESRI servers to generate a legend. Upgrading to sp2 solved the problem because the legends are created on your own server. So crazy and unexpected...

From jsapi (but would apply to all) --

"If the layers are version 10 or lower the legend is created using the ArcGIS.com legend service. In order to use the ArcGIS.com legend service your map service needs to be publicly accessible and your application must be able to access ArcGIS.com."

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm

share|improve this answer
add comment

It looks like you can't bind the Legend layer in XAML. Either bind it in the MainPage (or whatever your .XAML file is) constructor, or the Map loaded event. This works for me:

XAML:

<esri:Map Name="Map" >
    <esri:OpenStreetMapLayer ID="OpenStreetMap" Style="Mapnik">
    </esri:OpenStreetMapLayer>
    <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"   
        Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/RecentEarthquakesRendered/MapServer" />
</esri:Map>
<StackPanel>
    <esri:Legend  Map="{Binding ElementName=Map}" Name="Legend1" LayerItemsMode="Tree"/>
</StackPanel>

C#:

public MainPage()
    {
        InitializeComponent();
        Legend1.LayerIDs = new[] {"BaseLayer"};
        Legend1.ShowOnlyVisibleLayers = false;
    }

enter image description here

share|improve this answer
    
Thanks for your reply. Actually I used exactly your code and your map server, but again I got nothing. Is there any problem in config or something like that? –  Sina M Jan 26 '12 at 7:14
    
In order to proceed you'll need to provide some information as to debug, errors, warnings etc. –  valveLondon Jan 26 '12 at 16:43
    
You'll need ArcGIS Server 10 SP2 to generate legends in-house. Otherwise, see awesomo's answer. –  mwalker Feb 29 '12 at 0:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.