Here is my label definition
public LabelDefinition GetLabelDefinition()
{
var textSymbol = new TextSymbol
{
Color = System.Drawing.Color.Black,
Size = 40,
FontWeight = FontWeight.Bold,
HaloColor = System.Drawing.Color.White,
HaloWidth = 3,
};
var def = new LabelDefinition(new SimpleLabelExpression("Ahoj"), textSymbol)
{
Placement = Esri.ArcGISRuntime.ArcGISServices.LabelingPlacement.PointCenterRight,
MinScale = 0,
MaxScale = double.MaxValue,
};
return def;
}
Here is my overlay
_workOrdersOverlay = new GraphicsOverlay
{
Id = AppConstants.WorkOrdersLayerId,
Renderer = _workOrdersLayerService.GetRenderer(),
LabelsEnabled = true,
};
_workOrdersOverlay.LabelDefinitions.Add(_workOrdersLayerService.GetLabelDefinition());
Here is my overlay with Graphics and no labels.
If I click on one of the symbols and inspect the result of GeoViewController.IdentifyGraphicsOverlaysAsync I can see the overlay labeling is correctly configured
resultsPerOverlay.First().GraphicsOverlay.LabelsEnabled
true
resultsPerOverlay.First().GraphicsOverlay.LabelDefinitions.First().Expression
{Esri.ArcGISRuntime.Mapping.Labeling.SimpleLabelExpression}
Expression: "Ahoj"
What am I missing?
Solved! Go to Solution.
Hi @ViktorSafar,
Thank you for providing the repro.
The issue with labels not displaying in your GraphicsOverlay appears to be related to how the label expression is defined. When using a SimpleLabelExpression with static text like "Ahoj" or "Some text", the labels won't display because the expression isn't properly linked to attributes in your graphics.
For labels to display correctly in a GraphicsOverlay, you need to:
1. Make sure your label expression references an attribute that exists in your graphics. Instead of:
new SimpleLabelExpression("Some text")
Try using:
new SimpleLabelExpression("[name]")
2. Ensure your graphics have the corresponding attribute populated:
var g = new Graphic() { Geometry = new MapPoint(0, 0) };
g.Attributes.Add("name", "Homer");
Hi,
Thank you for your question. I can see a few potential reasons why your labels might not be showing up:
new SimpleLabelExpression("[placeholder]")
myGraphic.Attributes["placeholder"] = "Ahoj";
If you continue to have issues, ensure that your graphics are correctly added to the overlay and that there are no other visual elements obscuring the labels.
Let me know if these changes help!
Regards,
Prathamesh
Hi @pnarkhede
I simplified the code example to use static text after I had struggled with the labels not showing with an ArcadeLabelExpression. But it made no difference, hence this post.
Looking at the docs of LabelDefinition.MaxScale and MinScale, they default to 0 which then does not limit their viewing scale. I therefore removed those assignments.
No change in results, I am afraid.
I made a simple repro (note to use your own API key)
https://github.com/safarviktor/ArcGIS.Net.GraphicsOverlayNotShowingLabels
Hi @ViktorSafar,
Thank you for providing the repro.
The issue with labels not displaying in your GraphicsOverlay appears to be related to how the label expression is defined. When using a SimpleLabelExpression with static text like "Ahoj" or "Some text", the labels won't display because the expression isn't properly linked to attributes in your graphics.
For labels to display correctly in a GraphicsOverlay, you need to:
1. Make sure your label expression references an attribute that exists in your graphics. Instead of:
new SimpleLabelExpression("Some text")
Try using:
new SimpleLabelExpression("[name]")
2. Ensure your graphics have the corresponding attribute populated:
var g = new Graphic() { Geometry = new MapPoint(0, 0) };
g.Attributes.Add("name", "Homer");