MapInfo中的FeatureStyleModifier提供半透明效果

时间:2013-07-30 12:05:33

标签: c# mapxtreme

我们尝试为特定要素图层中的所有要素提供半透明效果,同时保留该图层中每个要素的样式。

我们尝试了以下方法:        http://testdrive.mapinfo.com/techsupp/miprod.nsf/59d125f456480edb852562b5004f2c33/00a4a56ebede26ff85256fe30054e255?OpenDocument

在这种方法中,Modify()函数没有受到影响,因此无法正常工作。 Modify()函数中的代码根本没有被执行,因为一旦附加修饰符就应该调用它。

以下是我们使用的代码段:

Internal class SelectedAreaModifier : FeatureStyleModifier
{
    private System.Collections.Hashtable features;
    public SelectedAreaModifier(string name, string alias, IResultSetFeatureCollection irfc) : base(name, alias)
    {
        features = new System.Collections.Hashtable();
        string[] exp = new string[] { "MI_KEY" };
        this.Expressions = exp;

        foreach (Feature f in irfc)
        {            
            features.Add(f.Key.Value, f.Key.Value);
        }
    }

    protected override bool Modify(FeatureStyleStack styles, object[] values)
    {
        MapInfo.Styles.CompositeStyle cs = styles.Current;
        if (features.Contains((values[0] as MapInfo.Data.Key).Value))
        {
            (cs.AreaStyle.Interior as SimpleInterior).ForeColor = Color.FromArgb((int)(255 * .5), (cs.AreaStyle.Interior as SimpleInterior).ForeColor);
            (cs.AreaStyle.Border as SimpleLineStyle).Color = Color.FromArgb((int)(255 * .5),(cs.AreaStyle.Border as SimpleLineStyle).Color);
            (cs.AreaStyle.Border as SimpleLineStyle).Width = (cs.AreaStyle.Border as SimpleLineStyle).Width;
            return true;
        }
        return false;
    }
}

这个类用作:

protected void setTranslucency() 
{
    Map myMap = GetMapObj();
    myMap.DrawingAttributes.EnableTranslucency = true;
    myMap.DrawingAttributes.SmoothingMode = MapInfo.Mapping.SmoothingMode.AntiAlias;
    myMap.DrawingAttributes.SpecialTransparentVectorHandling = false;

    FeatureLayer ftrLyr = myMap.Layers["CELL_2G"] as FeatureLayer;

    if (ftrLyr.Modifiers["CELL_2G_Translucent"] != null)
        ftrLyr.Modifiers.Remove("CELL_2G_Translucent");

    MapInfo.Data.MIConnection connection = new MIConnection();
    connection.Open();
    MapInfo.Data.MICommand command = connection.CreateCommand();
    command.CommandText = "select * from CELL_3G";
    command.Prepare();

    IResultSetFeatureCollection irfc = command.ExecuteFeatureCollection();

    SelectedAreaModifier sam = new SelectedAreaModifier("CELL_2G_Translucent", "CELL_2G_Translucent", irfc);
    sam.Enabled = true;

    ftrLyr.Modifiers.Append(sam);

    irfc.Close();
    command.Dispose();
    connection.Close();
}

任何帮助都将受到高度赞赏。

此致  MONU

0 个答案:

没有答案