1

我们试图为特定特征层中的所有特征赋予半透明性,同时保留该层中每个特征的样式。

我们尝试了以下方法: 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();
}

任何帮助将不胜感激。

问候,莫努

4

0 回答 0