wiki:maestro/MaestroAPI/samples/IterateLayerRules

Iterating styles: examining all styles defined in a layer

This page describes how to use the MaestroAPI from the MapGuide Maestro project in your own application.

The code below can be used as a template for iterating all style items in a LayerDefintion.

The example sets labels on all styles that have a feature label to be "My custom label"

(C#)

ServerConnectionI con; //See other samples on how to get this
LayerDefinition ldef = con.GetLayerDefinition("Library://myLayer.LayerDefinition");
VectorLayerDefinitionType vldef = ldef.Item as VectorLayerDefinitionType; //vldef becomes null, if it is not a vector layer
foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
{
    //The objects have no common base type, so we iterate in an untyped manner
    foreach (object o in vsr.Items)
    {
        if (o is PointTypeStyleType)
        {
            PointTypeStyleType pst = o as PointTypeStyleType;
            if (pst.PointRule != null)
                foreach (PointRuleType pr in pst.PointRule)
                {
                    if (pr.Label != null)
                        pr.Label.Text = "My custom label";
                }
        }
        else if (o is LineTypeStyleType)
        {
            LineTypeStyleType lst = o as LineTypeStyleType;
            if (lst.LineRule != null)
                foreach (LineRuleType lr in lst.LineRule)
                {
                    if (lr.Label != null)
                        lr.Label.Text = "My custom label";
                }
        }
        else if (o is AreaTypeStyleType)         
        {
            AreaTypeStyleType ast = o as AreaTypeStyleType;
            if (ast.AreaRule != null)
                foreach (AreaRuleType ar in ast.AreaRule)
                {
                    if (ar.Label != null)
                        ar.Label.Text = "My custom label";
                }
        }
    }
}
Last modified 12 years ago Last modified on 01/22/13 18:21:37
Note: See TracWiki for help on using the wiki.