popupdefinition=null ArcGIS Runtime SDK for .NET

939
4
08-25-2017 07:14 AM
RomanBoros
New Contributor III

Hi, I am trying to show popups in ArcGIS Runtime SDK for .NET, but even with defined popup definitions on the portal when I retrieve the feature layer from the portal I get popupdefinition=null. Should I invoke a special method which will pull the popup definitions? I couldn't find anything like that in the documentation.  

0 Kudos
4 Replies
JoeHershman
MVP Regular Contributor

Have you called LoadAsync() on the feature layer?

0 Kudos
RomanBoros
New Contributor III

Yes I am calling it, but anyway I don't get the PopupDefinition, it's null.

Any other ideas? 

0 Kudos
JoeHershman
MVP Regular Contributor

How are you getting to the FeatureLayer?  A FeatureLayer by itself does not have a PopupDefinition.  The only time a FeatureLayer object would have a PopupDefinition is if it is in a WebMap.  You would need to create a WebMap in Portal.  In the application you open the WebMap and then get to the FeatureLayer through the OperationLayers collection.

ArcGISRuntimeEnvironment.Initialize();

Credential credential =
     await AuthenticationManager.Current.GenerateCredentialAsync(
          new Uri("https://server.domain.com/portal/sharing/rest"), "", "");

ArcGISPortal portal =
     await ArcGISPortal.CreateAsync(new Uri("https://server.domain.com/portal"), credential);

PortalItem item = await PortalItem.CreateAsync(portal, "02f85448eb1049228c44065658984a0a");
Map map = new Map(item);
await map.LoadAsync();

foreach (var layer in map.OperationalLayers)
{
     //if configured PopupDefinition is not null here
}

FeatureLayer featureLayer = new FeatureLayer(new Uri("https://server.domain.com/server/rest/services/Mobile/ServiceName/FeatureServer/0"), credential);
await featureLayer.LoadAsync();
//PopupDefinition is null here
JenniferNery
Esri Regular Contributor

As Joe already mentioned, FeatureLayer popup can be configured on the web map. But you can also configure it in the client. For example, try the following code (see current value of popup):

            MyMapView.Map = new Map(new Uri("https://www.arcgis.com/home/webmap/viewer.html?webmap=ff0e158ffb184e41b8cea71ebda3eb67"));
            MyMapView.LayerViewStateChanged += (s, e) =>
              {
                  if (e.Layer is FeatureLayer && e.LayerViewState.Status == LayerViewStatus.Active)
                  {
                      var popup = ((FeatureLayer)e.Layer).PopupDefinition;
                      
                  }
              };
        }

        private void OnLoad(object sender, RoutedEventArgs e)
        {
            var layer = new FeatureLayer(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0"));
            layer.PopupDefinition = new PopupDefinition() { Title = "My Title" };
            layer.PopupDefinition.Fields.Add(new PopupField() { Label = "description", FieldName = "description ", IsEditable = true, IsVisible = true, StringFieldOption = PopupStringFieldOption.SingleLine });
            MyMapView.Map.OperationalLayers.Add(layer);
        }