Missing labels after applying a DefinitionExpression

765
1
03-22-2017 01:23 PM
JeffRogholt
New Contributor II

I'm using the WPF ArcGIS Runtime SDK for .Net v100.0.0.0.  The application is consuming an mmpk.  After a DefinitionExpression is applied to a FeatureLayer, the labels of the features are no longer displayed.  How do I get them back?

0 Kudos
1 Reply
MaraStoica4
Occasional Contributor

Hi Jeff,

This is an issue we're aware of and it is resolved for our next release early this summer. In the meantime, you could use a GraphicsOverlay as a workaround for your labels

// Run query to get all the features in the visible area
var featureLayer = mapView.Map.OperationalLayers[layerIndex] as FeatureLayer;

if (featureLayer != null)
{

     var featureTable = featureLayer.FeatureTable;

     // Set query parameters
     var queryParams = new QueryParameters()
     {
          ReturnGeometry = true,
          Geometry = mapView.VisibleArea
     };

     // Query the feature table 
     var queryResult = await roomsTable.QueryFeaturesAsync(queryParams);

     // Query using the def query expression
     var labelFeatures = queryResult.Where(f => f.Attributes["DefQueryColumn"].ToString() == "QueryExpression");


     if (labelFeatures != null)
     {
          try
          {
               var graphicsOverlay = this.MapView.GraphicsOverlays["LabelsGraphicsOverlay"];
               graphicsOverlay.Graphics.Clear();

               // Run garbage collector manually to prevent System.ArgumentException 
               GC.Collect();
               GC.WaitForPendingFinalizers();

               foreach (var feature in labelFeatures)
               {
                    var centerPoint = feature.Geometry.Extent.GetCenter();
                    var label = feature.Attributes["LabelAttribute"];

                    if (label != null)
                    {
                         // Create graphic
                         var labelText = new TextSymbol(label.ToString(), System.Drawing.Color.Black, 10, HorizontalAlignment.Center, VerticalAlignment.Middle);
                         var labelGraphic = new Graphic(centerPoint, labelText);

                         // Add label to map
                         graphicsOverlay.Graphics.Add(labelGraphic);
                    }
               }
          }
          catch 
          {
          }
     }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos