Changes between Initial Version and Version 1 of maestro/MaestroAPI/samples/IterateLayerRules


Ignore:
Timestamp:
Mar 4, 2009, 11:40:33 PM (15 years ago)
Author:
ksgeograf
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • maestro/MaestroAPI/samples/IterateLayerRules

    v1 v1  
     1== Iterating styles: examining all styles defined in a layer ==
     2This page describes how to use the MaestroAPI from the [wiki:maestro MapGuide Maestro] project in your own application.
     3
     4The code below can be used as a template for iterating all style items in a LayerDefintion.
     5
     6The example sets labels on all styles that have a feature label to be "My custom label"
     7
     8
     9(C#)
     10{{{
     11ServerConnectionI con; //See other samples on how to get this
     12LayerDefinition ldef = con.GetLayerDefinition("Library://myLayer.LayerDefinition");
     13VectorLayerDefinitionType vldef = ldef.Item as VectorLayerDefinitionType; //vldef becomes null, if it is not a vector layer
     14foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
     15{
     16    //The objects have no common base type, so we iterate in an untyped manner
     17    foreach (object o in vsr.Items)
     18    {
     19        if (o is PointTypeStyleType)
     20        {
     21            PointTypeStyleType pst = o as PointTypeStyleType;
     22            if (pst.PointRule != null)
     23                foreach (PointRuleType pr in pst.PointRule)
     24                {
     25                    if (pr.Label != null)
     26                        pr.Label.Text = "My custom label";
     27                }
     28        }
     29        else if (o is LineTypeStyleType)
     30        {
     31            LineTypeStyleType lst = o as LineTypeStyleType;
     32            if (lst.LineRule != null)
     33                foreach (LineRuleType pr in lst.LineRule)
     34                {
     35                    if (lr.Label != null)
     36                        lr.Label.Text = "My custom label";
     37                }
     38        }
     39        else if (o is AreaTypeStyleType)         
     40        {
     41            AreaTypeStyleType ast = o as AreaTypeStyleType;
     42            if (ast.AreaRule != null)
     43                foreach (AreaRuleType ar in ast.AreaRule)
     44                {
     45                    if (ar.Label != null)
     46                        ar.Label.Text = "My custom label";
     47                }
     48        }
     49    }
     50}
     51}}}