レイヤ改


あまりにサンプルがありそうな内容は書く気がなくなるが、とりあえずこれをベースに発展させていくので書いとく
ArcObjectsレイヤ実装
Comクラス登録とか永続化を除いた本当に素の実装。


続きは下記

レイヤ改に永続化機能を付与

ESRI.ArcGIS.Carto.ILayerの実装クラスを作成 (と言っても元のレイヤとの仲介をしてるだけ)

using System;
using System.Diagnostics;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;

/// <summary>
/// デバッグ用のレイヤ
/// </summary>
public class DebugLayer : ILayer
{
    private ILayer m_Layer = null;

    public DebugLayer(ILayer layer)
    {
        this.m_Layer = layer;
    }

    public void Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase DrawPhase, ESRI.ArcGIS.Display.IDisplay Display, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel)
    {
        DateTime preTime = DateTime.Now;

        this.m_Layer.Draw(DrawPhase, Display, TrackCancel);

        Debug.Print("描画:{1}:{2}:{0} ミリ秒" ,
            (DateTime.Now - preTime).TotalMilliseconds, 
            this.Name,
            DrawPhase.ToString("G"));
    }

    public IEnvelope AreaOfInterest
    {
        get { return this.m_Layer.AreaOfInterest; }
    }

    public bool Cached
    {
        get
        {
            return this.m_Layer.Cached;
        }
        set
        {
            this.m_Layer.Cached = value;
        }
    }

    public double MaximumScale
    {
        get
        {
            return this.m_Layer.MaximumScale;
        }
        set
        {
            this.m_Layer.MaximumScale = value;
        }
    }

    public double MinimumScale
    {
        get
        {
            return this.m_Layer.MinimumScale;
        }
        set
        {
            this.m_Layer.MinimumScale = value;
        }
    }

    public string Name
    {
        get
        {
            return this.m_Layer.Name;
        }
        set
        {
            this.m_Layer.Name = value;
        }
    }

    public bool ShowTips
    {
        get
        {
            return this.m_Layer.ShowTips;
        }
        set
        {
            this.m_Layer.ShowTips = value;
        }
    }

    public ISpatialReference SpatialReference
    {
        set { this.m_Layer.SpatialReference = value; }
    }

    public int SupportedDrawPhases
    {
        get { return this.m_Layer.SupportedDrawPhases; }
    }

    public bool Valid
    {
        get { return this.m_Layer.Valid; }
    }

    public bool Visible
    {
        get
        {
            return this.m_Layer.Visible;
        }
        set
        {
            this.m_Layer.Visible = value;
        }
    }

    public string get_TipText(double x, double y, double Tolerance)
    {
        return this.m_Layer.get_TipText(x, y, Tolerance);
    }//end method
}//end layer

呼び出し,差し替え側


ILayer layer = this.axMapControl1.Map.get_Layer(0);
DebugLayer debugLayer = new DebugLayer(layer);

IMapLayers mapLayer = (IMapLayers)this.axMapControl1.Map;
mapLayer.DeleteLayer(layer);
mapLayer.AddLayer(debugLayer);

this.axMapControl1.ActiveView.Refresh();

これでスタックに処理時間が表示できたり描画にひと手間加えられる。

カテゴリー: 開発 タグ: パーマリンク