Invisible features when add Legend or LayerLegend functionality from runtime toolkit

1885
7
08-24-2018 03:57 AM
GKmieliauskas
Esri Regular Contributor

Hi,

 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
JenniferNery
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="https://www.arcgis.com/home/webmap/viewer.html?webmap=f1ed0d220d6447a586203675ed5ac213"/>
<toolkit:Legend x:Name="MyLegend" 
                BindingContext="{x:Reference MyMapView}"
                    GeoView="{Binding}"
                BackgroundColor="Black"
                HeightRequest="200"
                WidthRequest="200"
                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("https://www.arcgis.com/home/webmap/viewer.html?webmap=f1ed0d220d6447a586203675ed5ac213"))
};
layout.AddView(mapView);
var legend = new Legend(this)
{
    LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent, 1f),
};
layout.AddView(legend);
legend.GeoView = mapView;
SetContentView(layout);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

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}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal">
                    <Switch IsToggled="{Binding IsVisible, Mode=TwoWay}"/>
                    <Label Text="{Binding Name}"/>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
GKmieliauskas
Esri 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
JenniferNery
Esri Regular Contributor

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

<Grid.Resources>
    <local:MapSource x:Key="MapSource"/>
</Grid.Resources>
<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
GKmieliauskas
Esri Regular Contributor

Hi,

I would like to share my code by pieces.

Xaml:

public Map Map

{

get {

if(_map == null)

{

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

AddLayers();

}

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

_map.OperationalLayers.Add(sitesFeatureLayer);

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

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

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
GKmieliauskas
Esri Regular Contributor

Hi,

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

https://developers.arcgis.com/net/latest/wpf/api-reference/html/E_Esri_ArcGISRuntime_UI_Controls_GeoView_LayerViewStateChanged.htm

// Create Uri for feature layer

var featureLayerUri = new Uri(

"http://sampleserver6.arcgisonline.com/arcgis/rest/services/Recreation/FeatureServer/0");

// Create a feature layer using url

FeatureLayer myFeatureLayer = new FeatureLayer(featureLayerUri);

myFeatureLayer.Name = "Feature Layer";

// Add the feature layer to map

myMap.OperationalLayers.Add(myFeatureLayer);

// 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
GKmieliauskas
Esri Regular Contributor

Hi,

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