Invisible features when add Legend or LayerLegend functionality from runtime toolkit

08-24-2018 03:57 AM
Regular Contributor


 I use ArcGIS Runtime for Net with Xamarin. Legend or LayerLegend controls work fine on UWP, but does not work correctly on Android. I can see layers in my application, but all features from all operational layers are hided. If I comment in xaml legend part I can see all features. When I add operational layer I set each layer to be visible in legend and visible itself.

I do not know  is it possible to get checkboxes for visibility in legend controls. Maybe all my layer are invisible?

0 Kudos
7 Replies
Esri Regular Contributor

Are you using Xamarin.Forms? You might have to specify Height/WidthRequest. I just logged an issue for this.

<esri:MapView x:Name="MyMapView" Map=""/>
<toolkit:Legend x:Name="MyLegend" 
                BindingContext="{x:Reference MyMapView}"
                VerticalOptions="StartAndExpand"/> ‍‍‍‍‍‍‍‍

If you are using Xamarin.Android, the following code should just work.

var layout = new LinearLayout(this)
    Orientation = Orientation.Vertical,
    LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent),
var mapView = new MapView(this)
    LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent, 2f),
    Map = new Map(new Uri(""))
var legend = new Legend(this)
    LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent, 1f),
legend.GeoView = mapView;

If you have set Legend.GeoView property before MapView.Map is set, you might be hitting this bug. What you can do is set Legend.GeoView later when map is ready.

LayerLegend only displays symbology and layer name for a given layer. Legend displays LayerLegend for layers contained in the GeoView.

If you are looking to control the visibility of layers/sub-layers, I think you need TableOfContents which is a toolkit currently only available in WPF. You can do something like...

<ListView ItemsSource="{Binding Path=Map.AllLayers}" BindingContext="{x:Reference MyMapView}">
                <StackLayout Orientation="Horizontal">
                    <Switch IsToggled="{Binding IsVisible, Mode=TwoWay}"/>
                    <Label Text="{Binding Name}"/>
0 Kudos
Regular Contributor

Hi Jenifer,

Thank you for your reply.

Yes, I am using Xamarin.Forms. Height/WidthRequest did not solve the problem.

I think that settings can influent legend view, but my problem is that I can’t see features on the MapView when I set legend.GeoView = mapView;

It seems that is the bug which you have mentioned, but I am using MVVM and do not know how to change sequence of map creation and GeoView setting.

0 Kudos
Esri Regular Contributor

I'm not able to reproduce even if I were to change MapView.Map to use MVVM

    <local:MapSource x:Key="MapSource"/>
<esri:MapView x:Name="MyMapView" Map="{Binding Source={StaticResource MapSource}, Path=Map}"/>

I have not seen features disappearing when Legend.GeoView is set, can you share some code to reproduce?

For example, how do you do this? Can you check in your code where IsVisible is set anywhere? 

When I add operational layer I set each layer to be visible in legend and visible itself.

You can check MyMapView.LayerViewStateChanged event and see LayerViewState.Status becomes OutOfScale or NotVisible. 

MyMapView.SpatialReferenceChanged event could also be used to know if Map with layers has been set.

0 Kudos
Regular Contributor


I would like to share my code by pieces.


public Map Map


get {

if(_map == null)


_map = new Map(Basemap.CreateStreets());



return _map;


set {

_map = value;



// Create uri to the used feature service

var serviceUri = new Uri("…");

// Create feature table for the pools feature service

ServiceFeatureTable sitesFeatureTable = new ServiceFeatureTable(serviceUri);

// Define the request mode

sitesFeatureTable.FeatureRequestMode = FeatureRequestMode.OnInteractionNoCache;

// Create FeatureLayer that uses the created table

FeatureLayer sitesFeatureLayer = new FeatureLayer(sitesFeatureTable);

sitesFeatureLayer.Name = "Sites";

sitesFeatureLayer.ShowInLegend = true;

sitesFeatureLayer.IsVisible = true;

// Add created layer to the map


I will try to check events you have mentioned and inform about results later.

0 Kudos
Regular Contributor


I have added LayerViewStateChanged event listening and got 3 events. One of them says that my Sites layer is not visible. Interesting that may background by event is not visible too, but I can see it. I have attached printscreens of event messages.

0 Kudos
Regular Contributor


I have found problem location. I have loaded data from ArcGIS Runtime samples page

// Create Uri for feature layer

var featureLayerUri = new Uri(


// Create a feature layer using url

FeatureLayer myFeatureLayer = new FeatureLayer(featureLayerUri);

myFeatureLayer.Name = "Feature Layer";

// Add the feature layer to map


// Create a map point the map should zoom to

MapPoint mapPoint = new MapPoint(-11000000, 4500000, SpatialReferences.WebMercator);

// Set the initial viewpoint for map

myMap.InitialViewpoint = new Viewpoint(mapPoint, 50000000);

It works without setting visibility for legend and for layer. I have commented my layer visibility setting code, but it not helped.

There are two differences how feature layer is created:

1. Different data source (ArcGIS server data and arcgisonline data)

2. I create FeatureLayer from ServiceFeatureTable, not directly from Uri.

I have tried create FeatureLayer directly from Uri, but it not works. So Legend control does not work with ArcGIS server data

0 Kudos
Regular Contributor


I have tried the legend control with .geodatabase package and it works fine. At this time I found only one type of data which do not wont to work with legend control is ArcGIS server data (FeatureServer)

0 Kudos