Labelling all features in a layer

2658
3
03-10-2014 03:32 PM
Labels (1)
SaranPon
New Contributor
Hi all,

So there is no built in support for Labels in WPF. Is there a work around to achieve this? For example, I have a counties layer which I want travel through each county and label it. I could get the currently clicked area using the Geometry however I am not sure how to loop it to add all the county names. Could someone help?

Thanks,
Saran

Code to add Label to the mouse click point

private void AddLabel(ESRI.ArcGIS.Client.Geometry.MapPoint myMapClickPoint)
  ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                    {
                        Geometry = myMapClickPoint,
                        MapExtent = mymap.Extent,
                        Width = (int)mymap.ActualWidth,
                        Height = (int)mymap.ActualHeight,
                        LayerOption = LayerOption.visible
                    };

                    IdentifyTask identifyTask = new IdentifyTask();
                    identifyTask.Url = _arcGISLocalDynamicMapServiceLayer.Url; // localMapService.UrlMapService;
                    identifyTask.ExecuteCompleted += new EventHandler<IdentifyEventArgs>(identifyTask_ExecuteCompleted);
                    identifyTask.ExecuteAsync(identifyParams);
                    graphic = new ESRI.ArcGIS.Client.Graphic()
                    {
                        Geometry = myMapClickPoint,
                        Symbol = gridMain.Resources["labelSymbol"] as ESRI.ArcGIS.Client.Symbols.MarkerSymbol
                    };

}
private void identifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            try
            {
                if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
                {
                   string title = string.Empty;

                    if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
                    {
                        int i, n;
                        n = graphicsLayer.Graphics.Count;
                        foreach (IdentifyResult result in args.IdentifyResults)
                        {
                            Graphic feature = result.Feature;
                            string res = string.Empty;
                            result.DisplayFieldName = "ID";
                            title = result.Value.ToString() + " (" + result.LayerName + ")";
                            graphic.Attributes.Add("NAME", result.Value.ToString());
                            for (i = 0; i < n; i++)
                            {
                                res = graphicsLayer.Graphics.Attributes["NAME"].ToString();
                                if (res == result.Value.ToString())
                                {
                                    graphicsLayer.Graphics.Remove(graphicsLayer.Graphics);
                                    break;
                                }
                            }

                            graphicsLayer.Graphics.Add(graphic);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
0 Kudos
3 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

In the WPF SDK we recommend using the accelerated display mode for the entire Map if possible, particularly when your application makes extensive use Graphics. If you find the performance of the non-accelerated display mode acceptable then for labelling you can work with ControlTemplates and/or CompositeSymbols.

If you are working with the accelerated display mode, as you have noted, there is currently no built in labelling functionality - this is on the roadmap for the new ArcGIS Runtime SDK for .NET (for a preview of the new labelling functionality you can take a look at the ArcGIS Runtime SDK for .NET beta at https://developers.arcgis.com/net/).

In the meantime, in the existing WPF SDK I would suggest you take a look at the GeometryService task which contains a LabelPoints operation (http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli.... You can pass your Graphics / FeatureLayer.Graphics to this operation and it will generate the optimum points for display labels. You can then use the TextSymbol to create a label using each point as the geometry.

Regards

Mike
0 Kudos
SaranPon
New Contributor
Hi,

In the WPF SDK we recommend using the accelerated display mode for the entire Map if possible, particularly when your application makes extensive use Graphics. If you find the performance of the non-accelerated display mode acceptable then for labelling you can work with ControlTemplates and/or CompositeSymbols.

If you are working with the accelerated display mode, as you have noted, there is currently no built in labelling functionality - this is on the roadmap for the new ArcGIS Runtime SDK for .NET (for a preview of the new labelling functionality you can take a look at the ArcGIS Runtime SDK for .NET beta at https://developers.arcgis.com/net/).

In the meantime, in the existing WPF SDK I would suggest you take a look at the GeometryService task which contains a LabelPoints operation (http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli.... You can pass your Graphics / FeatureLayer.Graphics to this operation and it will generate the optimum points for display labels. You can then use the TextSymbol to create a label using each point as the geometry.

Regards

Mike


Thanks Mike for the response. The link appears to be broken. could you provide the correct link?


Thanks,
Saran.
0 Kudos
AnttiKajanus1
Occasional Contributor III
0 Kudos