Thanks guys.I managed to get something working. Here's my code:
geometryTask.LabelPointsCompleted += delegate(object snd, GraphicsEventArgs le)
{
graphicsLayer.Graphics.Clear();
for (int i = 0; i < le.Results.Count; ++i)
{
var graphic = le.Results;
var feature = features;
if (feature.Geometry != null && feature.Attributes["PROP_ID"] != null && Convert.ToInt32(feature.Attributes["PROP_ID"]) > 0)
{
var extent = feature.Geometry.Extent;
var point1 = MyMap.MapToScreen(new MapPoint(extent.XMin, extent.YMin, extent.ZMin, extent.MMin, extent.SpatialReference));
var point2 = MyMap.MapToScreen(new MapPoint(extent.XMax, extent.YMax, extent.ZMax, extent.MMax, extent.SpatialReference));
if (Point.Subtract(point1, point2).Length > 110)
{
var symbol = new TextSymbol()
{
Text = feature.Attributes["PROP_ID"].ToString(),
ControlTemplate = LayoutRoot.Resources["LabelTemplate"] as ControlTemplate,
FontSize = 12,
OffsetX = 50,
OffsetY = 6
};
graphic.Symbol = symbol;
var mapPoint = graphic.Geometry as MapPoint;
graphic.Attributes.Add("X", mapPoint.X);
graphic.Attributes.Add("Y", mapPoint.Y);
graphicsLayer.Graphics.Add(graphic);
}
}
}
};
This actually makes the labels get hidden when they're too big for the polygon. I'm checking to see if the polygon's extent's diagonal's length is enough to house the label. But this works best (or only) on certain polygons, and doesn't work for others, for obvious reasons.Any pointers on getting it to work with any or most polygons would be appreciated.EDIT: Changing the condition to:if ((point2.X - point1.X) > 110)
seems to approximate it better.