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);
}
}