透過可能なグラフィックエレメントをArcObjectsで


ArcGIS10にて確認

描画ツール等で描画可能なエレメントは透過処理ができない

※IGraphicsContainerの追加するエレメント

カスタム透過エレメントを作成
速度は注意!!

[Guid("9df8871c-9849-43d5-b894-bfd2dc0d9e04")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CElem.Class1")]
public class CustomTransElemet : IElement,
IElementProperties,
IElementProperties2,
IElementProperties3,
IBoundsProperties,
ITransform2D,
IGraphicElement,
//IPersistVariant,
IClone
{
private IElement _baseElemnt = null;
private short _transparency = 255;

/// <summary>
///
/// </summary>
/// <param name="elem"></param>
public CustomTransElemet(IElement elem)
{
    if (elem == null)
    {
        throw new NullReferenceException(");
    }

    bool isSupport = elem is IElementProperties &&
                        elem is IElementProperties2 &&
                        elem is IElementProperties3 &&
                        elem is IBoundsProperties &&
                        elem is ITransform2D &&
                        elem is IGraphicElement &&
                        //elem is IPersistVariant &&
                        elem is IClone;

    if (!isSupport)
        throw new NotSupportedException(");

    this._baseElemnt = elem;
}//end method

/// <summary>
///
/// </summary>
public IElement BaseElemnt
{
    get { return this._baseElemnt; }
    set { this._baseElemnt = value; }
}

/// <summary>
/// 0
/// </summary>
public short Transparency
{
    get { return Convert.ToInt16((this._transparency/255.0) * 100.0); }
    set { _transparency = Convert.ToInt16(255.0 * (value / 100.0)); }
}

//IElement
public void Draw(IDisplay display, ITrackCancel trackCancel)
{
    using (ComReleaser comrel = new ComReleaser())
    {
        ITransparencyDisplayFilter displayFilter = new TransparencyDisplayFilterClass();
        comrel.ManageLifetime(displayFilter);

        displayFilter.Transparency = this._transparency;

        display.Filter = displayFilter;

        this._baseElemnt.Draw(display, trackCancel);

        display.Filter = null;
    }//end com
}

#region IElement
public ISelectionTracker SelectionTracker
{
    get { return this._baseElemnt.SelectionTracker; }
}

public bool HitTest(double x, double y, double Tolerance)
{
    return this._baseElemnt.HitTest(x, y, Tolerance);
}

public IGeometry Geometry
{
    get { return this._baseElemnt.Geometry; }
    set { this._baseElemnt.Geometry = value; }
}
public bool Locked
{
    get { return this._baseElemnt.Locked; }

    set { this._baseElemnt.Locked = value; }
}

public void Activate(IDisplay disp)
{
    this._baseElemnt.Activate(disp);
}
public void Deactivate()
{
    this._baseElemnt.Deactivate();
}
public void QueryBounds(IDisplay Display, IEnvelope Bounds)
{
    this._baseElemnt.QueryBounds(Display, Bounds);
}
public void QueryOutline(IDisplay Display, IPolygon Outline)
{
    this._baseElemnt.QueryOutline(Display, Outline);
}//end method

#endregion IElement
#region IBoundsProperties
public bool FixedAspectRatio
{
    get
    {
        return ((IBoundsProperties)this._baseElemnt).FixedAspectRatio;
    }
    set
    {
        ((IBoundsProperties)this._baseElemnt).FixedAspectRatio = value;
    }
}

public bool FixedSize { get { return ((IBoundsProperties)this._baseElemnt).FixedSize;} }

#endregion IBoundsProperties
#region IElementProperties
public bool AutoTransform
{
    get { return ((IElementProperties)this._baseElemnt).AutoTransform; }
    set { ((IElementProperties)this._baseElemnt).AutoTransform = value; }
}

public object CustomProperty
{
    get { return ((IElementProperties)this._baseElemnt).CustomProperty; }
    set { ((IElementProperties)this._baseElemnt).CustomProperty = value; }
}

public string Name
{
    get { return ((IElementProperties)this._baseElemnt).Name; }
    set { ((IElementProperties)this._baseElemnt).Name = value; }
}

public string Type
{
    get { return ((IElementProperties)this._baseElemnt).Type; }
    set { ((IElementProperties)this._baseElemnt).Type = value; }
}

#region IElementProperties2
public bool CanRotate()
{
    return ((IElementProperties2)this._baseElemnt).CanRotate();
}
public double ReferenceScale
{
    get { return ((IElementProperties2)this._baseElemnt).ReferenceScale; }
    set { ((IElementProperties2)this._baseElemnt).ReferenceScale = value; }
}

#endregion IElementProperties2
#region IElementProperties3
public esriAnchorPointEnum AnchorPoint
{
    get { return ((IElementProperties3)this._baseElemnt).AnchorPoint; }
    set { ((IElementProperties3)this._baseElemnt).AnchorPoint = value; }
}

//IGraphicsElement
public ISpatialReference SpatialReference
{
    get { return ((IElementProperties3)this._baseElemnt).SpatialReference; }
    set { ((IElementProperties3)this._baseElemnt).SpatialReference = value; }
}

#endregion IElementProperties3
#endregion IElementProperties
#region ITransform2D
public void Move(double dx, double dy)
{
    ((ITransform2D)this._baseElemnt).Move(dx, dy);
}

public void MoveVector(ILine v)
{
    ((ITransform2D)this._baseElemnt).MoveVector(v);
}

public void Rotate(IPoint Origin, double rotationAngle)
{
    ((ITransform2D)this._baseElemnt).Rotate(Origin, rotationAngle);
}

public void Scale(IPoint Origin, double sx, double sy)
{
    ((ITransform2D)this._baseElemnt).Scale(Origin, sx, sy);
}

public void Transform(esriTransformDirection direction, ITransformation transformation)
{
    ((ITransform2D)this._baseElemnt).Transform(direction, transformation);
}

#endregion ITransform2D
#region IClone
public void Assign(IClone src)
{
    ((IClone)this._baseElemnt).Assign(src);
}

public IClone Clone()
{
    return ((IClone)this._baseElemnt).Clone();
}

public bool IsEqual(IClone other)
{
    return ((IClone)this._baseElemnt).IsEqual(other);
}

public bool IsIdentical(IClone other)
{
    return ((IClone)this._baseElemnt).IsIdentical(other);
}

#endregion IClone
//#region IPersistVariant
//public UID ID
//{
//    get { return ((IPersistVariant)this._baseElemnt).ID; }
//}

//public void Load(IVariantStream Stream)
//{
//    ((IPersistVariant)this._baseElemnt).Load(Stream);
//}

//public void Save(IVariantStream Stream)
//{
//    ((IPersistVariant)this._baseElemnt).Save(Stream);
//}

//#endregion IPersistVariant
}//end class
カテゴリー: 開発 タグ: パーマリンク