1

I'm starting to develop GIS applications using ArcObjects for c# and WPF.

I'm trying to migrate a legacy ArcObjects application to the newest version. I'm simply adding a map control with its legend, using the Esri.ArcGISRuntime.Toolkit. Nothing special here. So I followed the examples, put the map and bind the legend to the map like this:

<esri:MapView x:Name="MyMapView" Margin="47,0,40,48" Grid.ColumnSpan="3" Grid.Column="1" >
 <esri:Map x:Name="MyMap">
 <esri:ArcGISTiledMapServiceLayer ID="BaseMap" 
 ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
 </esri:Map>
 </esri:MapView>
<esri:Legend x:Name="MyLegend" Grid.Row="1" Layers="{Binding Map.Layers, ElementName=MyMapView}" > </esri:Legend>

Then I add a GraphicsLayer programmatically:

 GraphicsLayer pointLayer = new GraphicsLayer();
 pointLayer.DisplayName = "My Layer Name ";
 pointLayer.ShowLegend = true;
 pointLayer.Graphics.Add(CreateMapPoint()); // Adds a simple marker
 pointLayer.ID = "SimpleGraphicsLayer";
 MyMap.Layers.Add(pointLayer);

But when I execute the application, the legend is blank. No layer information is shown. In the legacy application, where we used and older version of ArcObjects worked fine.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 12, 2015 at 18:07

1 Answer 1

1

I found why. While in the old API the previous code works, here you have to add data attributes to your layers as indicate in the "Render graphics layer" example of the documentation in this page:

https://developers.arcgis.com/net/desktop/guide/add-graphics-and-text.htm

In order to do that Define a UniqueValueRenderer for a GraphicsLayer using code, that will set the right icon for each point in your layer based on a information field defined in the code.

Then when adding MapPoint objects be sure to assign information attributes:

 Dictionary<string,object> attributes = new Dictionary<string, object>();
 attributes.Add("Name", dataRow["NAME"].ToString());
 attributes.Add("Type", dataRow["TYPE"].ToString());
 Graphic markerGraphic = new Graphic(newMapPoint, attributes);

In the XAML definition, link the objects as follow:

<esri:Legend x:Name="MyLegend" Grid.Row="1"
 Layers="{Binding Map.Layers, ElementName=MyMapView}"
 Scale="{Binding Scale, ElementName=MyMapView}" 
 ScrollViewer.HorizontalScrollBarVisibility="Auto" Height="Auto"
 IsManipulationEnabled="True" 
 UseLayoutRounding="True" Width="228" 
 ScrollViewer.CanContentScroll="True" 
 ScrollViewer.VerticalScrollBarVisibility="Auto" 
 IsTabStop="True" ClipToBounds="True" />

See the previous ESRI link for further information.

answered Jan 22, 2015 at 15:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.