SelectFeature for a FeatureCollectionLayer?

343
1
Jump to solution
07-27-2018 12:37 PM
MikeBrown6
New Contributor

I have a collection of features that I create in code to mimic as if my data had a FeatureLayer. I have the Features properly showing up on the map and I can even identify the feature when tapped and output the data from the backing fields. However, I don't see any of the Select methods that are used in FeatureLayers. I prodded around and did find a hack to get to the method call:

var identifyResults = await MyMapView.IdentifyLayerAsync(MyFeatureCollectionLayer, tapScreenPoint, pixelTolerance, onlyReturnPopups, maximumResults);

var fcl = identifyResults.SublayerResults.FirstOrDefault();
if (fcl != null)
{
        foreach (Esri.ArcGISRuntime.Data.GeoElement idElement in fcl.GeoElements)
        {
            Esri.ArcGISRuntime.Data.Feature idFeature = idElement as Esri.ArcGISRuntime.Data.Feature;

            //fcl.SelectFeature(idFeature); // No methods for selection!!!

            MyFeatureCollectionLayer.FeatureCollection.Tables[0].FeatureLayer.SelectFeature(idFeature);

            CalloutDefinition callout = new CalloutDefinition(idFeature.Attributes["Number"].ToString(), idFeature.Attributes["Location"].ToString());
            MyMapView.ShowCalloutAt(e.Location, callout);
        }
}

However, if I get a reference to that FeatureLayer and try to perform the same IdentifyLayerAsync it won't return any results. Should/will FeatureCollectionLayers have a SelectFeature() method?  Am I using the wrong tooling (for adding POCO data to a map)? I had tried doing this with a GraphicsOverlay but ran into issues with interacting with the data -queries, filters, etc.

0 Kudos
1 Solution

Accepted Solutions
MaraStoica4
Occasional Contributor

Hi Mike,

I ran your code with a couple of small modifications on a FeatureCollectionLayer I created and it selects without issues. See below please.

private async void MapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
     // get reference to MapView
     var mapView = sender as MapView;

     // get the first operational layer in the map (I only added one layer so this should find the layer I'm looking for)
     var layer = mapView.Map.OperationalLayers[0] as FeatureCollectionLayer;

     // get the tap location in screen units
     var tapScreenPoint = e.Position;

     // set identify parameters
     var pixelTolerance = 100;
     var returnPopupsOnly = false;
     var maxResultCount = 5;

     if (layer != null)
     {
          // call the identify operation
          var identifyResults = await mapView.IdentifyLayerAsync(layer, tapScreenPoint, pixelTolerance, returnPopupsOnly, maxResultCount);

          // get the layer containing the identify results
          var fcl = identifyResults.SublayerResults.FirstOrDefault();
          if (fcl != null)
          {
               // get every feature that was identified
               foreach (Esri.ArcGISRuntime.Data.GeoElement idElement in fcl.GeoElements)
               {
                    var idFeature = idElement as Feature;

                    // select feature
                    layer.Layers[0].SelectFeature(idFeature);
               }
          }
     }
}

View solution in original post

1 Reply
MaraStoica4
Occasional Contributor

Hi Mike,

I ran your code with a couple of small modifications on a FeatureCollectionLayer I created and it selects without issues. See below please.

private async void MapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
     // get reference to MapView
     var mapView = sender as MapView;

     // get the first operational layer in the map (I only added one layer so this should find the layer I'm looking for)
     var layer = mapView.Map.OperationalLayers[0] as FeatureCollectionLayer;

     // get the tap location in screen units
     var tapScreenPoint = e.Position;

     // set identify parameters
     var pixelTolerance = 100;
     var returnPopupsOnly = false;
     var maxResultCount = 5;

     if (layer != null)
     {
          // call the identify operation
          var identifyResults = await mapView.IdentifyLayerAsync(layer, tapScreenPoint, pixelTolerance, returnPopupsOnly, maxResultCount);

          // get the layer containing the identify results
          var fcl = identifyResults.SublayerResults.FirstOrDefault();
          if (fcl != null)
          {
               // get every feature that was identified
               foreach (Esri.ArcGISRuntime.Data.GeoElement idElement in fcl.GeoElements)
               {
                    var idFeature = idElement as Feature;

                    // select feature
                    layer.Layers[0].SelectFeature(idFeature);
               }
          }
     }
}