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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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