(UWP, 100.12 & 100.13)
Some polygons don't display the label that is specified on the overlay.
I have extracted some code to a demo project that shows the problem. I have added three polygons to an overlay and added a symbol renderer and a label definition. The large polygon doesn't show the label.
Code extract (see full demo in attached zip):
testLayer = new GraphicsOverlay
{
Id = "TEST_LAYER",
RenderingMode = GraphicsRenderingMode.Static,
LabelsEnabled = true,
};
//Symbol renderer
testLayer.Renderer = new SimpleRenderer(new SimpleLineSymbol
{
Color = Color.Yellow,
Style = SimpleLineSymbolStyle.Solid,
Width = 2
});
//Label def
var label = new LabelDefinition(new SimpleLabelExpression($"\"Test\""), new TextSymbol
{
BackgroundColor = Color.Aqua,
Color = Color.Black,
Size = 14
});
Solved! Go to Solution.
Calling "poly = GeometryEngine.Simplify(poly);" on your polygon before adding it to the GraphicsOverlay should resolve the issue.
private void addPolygon(string polygonJson)
{
var poly = Geometry.FromJson(polygonJson);
poly = GeometryEngine.Simplify(poly);
var graphic = new Graphic
{
Geometry = GeometryEngine.Project((Polygon)poly, new SpatialReference(3006))
};
testLayer.Graphics.Add(graphic);
}
Have you checked that your geometries are OK? An invalid geometry will display on the map but won't show a label. If this is what's wrong, running the RepairGeometries tool should solve it.
https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/check-geometry.htm
https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/repair-geometry.htm
Calling "poly = GeometryEngine.Simplify(poly);" on your polygon before adding it to the GraphicsOverlay should resolve the issue.
private void addPolygon(string polygonJson)
{
var poly = Geometry.FromJson(polygonJson);
poly = GeometryEngine.Simplify(poly);
var graphic = new Graphic
{
Geometry = GeometryEngine.Project((Polygon)poly, new SpatialReference(3006))
};
testLayer.Graphics.Add(graphic);
}
I know its an old question, but WHY does it work?