scottxu

导航

SuperMap iClient for Silverlight开发系列之自定义面风格

SuperMap.Web程序集中提供了点、线、面风格,还提供了默认的风格和预定义的五种点的样式等,如果已经提供的Feature风格不能满足用户的需求,那么也可以自己进行扩展来实现,可以从Style继承,也可以从Style的子类MarkerStyle、LineStyle、FillStyle继承,实现父类的ControlTemplate。

下面就自定义一个面的风格:

<Grid.Resources>
            <icCore:FillStyle x:Name="myCustomFillStyle" >
                <icCore:FillStyle.ControlTemplate >
                    <ControlTemplate>
                        <Grid>
                            <Path x:Name="Element"  StrokeThickness="1" Stroke="Black">
                                <Path.Fill>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,4" MappingMode="Absolute" SpreadMethod="Repeat">
                                        <GradientStop Color="Transparent" Offset="0.8" />
                                        <GradientStop Color="Black" Offset="0.8" />
                                    </LinearGradientBrush>
                                </Path.Fill>
                            </Path>
                        </Grid>
                    </ControlTemplate>
                </icCore:FillStyle.ControlTemplate>
            </icCore:FillStyle>
</Grid.Resources>
在C#代码中直接用就可以了:
            feature = new Feature();
            feature.Geometry = new GeoRegion
            {
                Parts = new ObservableCollection<Point2DCollection>
                {
                    new Point2DCollection()
                        {
                            new Point2D(0,0),
                            new Point2D(10000000,0),
                            new Point2D(10000000,10000000),
                            new Point2D(0,10000000),
                            new Point2D(0,0)
                        },
                    new Point2DCollection()
                        {
                            new Point2D(-10000000,0),
                            new Point2D(0,-10000000),
                            new Point2D(-10000000,-10000000),
                            new Point2D(-10000000,0)
                        }
                 }
            };
            feature.Style = myCustomFillStyle;

效果(黑色的面就是想要的效果):

         

posted on 2011-02-12 15:22  scottxu  阅读(738)  评论(0编辑  收藏  举报