Hello everyone,
I am trying to change the sample codes to run time labeling function, which needs to enable labels to show when you click a button
ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers ---this is the sample I was trying to modify.
and the result I got from step-by-step debugging looks fine. but I don't see any labels show up to my map
here are my codes:
private void Button_Click(object sender, RoutedEventArgs e)
{
ArcGISDynamicMapServiceLayer DLayer = new ArcGISDynamicMapServiceLayer();
DLayer = (ArcGISDynamicMapServiceLayer)MyMap.Layers["PDLayer"];
DLayer.LayerDrawingOptions = new LayerDrawingOptionsCollection();
LayerDrawingOptions layerdrawingoptions = new LayerDrawingOptions()
{
LayerID = 1,
ShowLabels = true,
ScaleSymbols = true
};
LabelClassCollection labelclasscollection = new LabelClassCollection();
LabelClass labelclass1 = new LabelClass()
{
LabelExpression = "[POP2000]",
LabelPlacement = LabelPlacement.LinePlacementAboveAfter,
Where = "[POP2000] <= 61",
MinScale = 5000,
LabelOptions = new LabelOptions()
{
Color = Colors.Red,
FontFamily = new FontFamily("Arial"),
FontSize = 10,
FontWeight = FontWeights.Bold
}
};
LabelClass labelclass2 = new LabelClass()
{
LabelExpression = "[POP2000]",
LabelPlacement = LabelPlacement.LinePlacementAboveAfter,
Where = "[POP2000] > 61 AND [POP2000] <264",
MinScale = 15000,
LabelOptions = new LabelOptions()
{
Color = Colors.Black,
FontFamily = new FontFamily("Arial"),
FontSize = 10,
FontWeight = FontWeights.Bold
}
};
LabelClass labelclass3 = new LabelClass()
{
LabelExpression = "[POP2000]",
LabelPlacement = LabelPlacement.LinePlacementAboveAfter,
Where = "[POP2000] > 264",
MinScale = 30000,
LabelOptions = new LabelOptions()
{
Color = Colors.Blue,
FontFamily = new FontFamily("Arial"),
FontSize = 14,
FontWeight = FontWeights.Bold
}
};
labelclasscollection.Add(labelclass1);
labelclasscollection.Add(labelclass2); //=labeldrawingoptions.labelclass.add()
labelclasscollection.Add(labelclass3);
layerdrawingoptions.LabelClasses = labelclasscollection;
DLayer.LayerDrawingOptions.Add(layerdrawingoptions);
DLayer.Refresh();
MyMap.UpdateLayout();
}