カスタムシンボル


シンボルのカスタマイズ:例えば波線
wave

シンボル本体

using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;

class WaveLine : ISymbol
{
  private ISymbol m_BaseSymbol = null;

  private double m_Width = 1;

  public double Width
  {
    get { return m_Width; }
    set { m_Width = value; }
  }

  public WaveLine()
  {
    this.m_BaseSymbol = new SimpleLineSymbolClass();

    //this.m_BaseSymbol 
  }


  public void Draw(IGeometry geom)
  {
    if (!(geom is IPolyline))
      return;
    using (ComReleaser com = new ComReleaser())
    {
      com.ManageLifetime(geom);

      IPolyline line = (IPolyline)geom;
      line.Densify(this.m_Width, 0);

      IPoint centerPt = new PointClass();
      com.ManageLifetime(centerPt);

      ISegmentCollection newLine = new PolylineClass();
      com.ManageLifetime(newLine);

      esriArcOrientation orientation = esriArcOrientation.esriArcClockwise;

      IPointCollection pts = (IPointCollection)line;
      for (int i = 1; i < pts.PointCount; i++)
      {
        var inxPrePt = i - 1;
        var prePt = pts.get_Point(inxPrePt);
        var pt = pts.get_Point(i);

        ILine cl = new LineClass();
        com.ManageLifetime(cl);
        cl.PutCoords(prePt, pt);
        cl.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, centerPt);

        ICircularArc cArc = new CircularArcClass();
        com.ManageLifetime(cArc);

        cArc.PutCoords(centerPt, prePt, pt, orientation);
        if (orientation == esriArcOrientation.esriArcClockwise)
          orientation = esriArcOrientation.esriArcCounterClockwise;
        else
          orientation = esriArcOrientation.esriArcClockwise;

        newLine.AddSegment((ISegment)cArc);
      }//end loop

      this.m_BaseSymbol.Draw((IGeometry)newLine);
    }//end com
  }//end method

  public void QueryBoundary(int hDC, ITransformation displayTransform, IGeometry geom, IPolygon boundary)
  {
    this.m_BaseSymbol.QueryBoundary(hDC, displayTransform, geom, boundary);
  }

  public esriRasterOpCode ROP2
  {
    get
    {
      return this.m_BaseSymbol.ROP2;
    }
    set
    {
      this.m_BaseSymbol.ROP2 = value;
    }
  }

  public void ResetDC()
  {
    this.m_BaseSymbol.ResetDC();
  }

  public void SetupDC(int hDC, ITransformation transformation)
  {
    this.m_BaseSymbol.SetupDC(hDC, transformation);
  }//end method
}//end class

使うほう

var scDisplay = this.axMapControl1.ActiveView.ScreenDisplay;
var env = this.axMapControl1.ActiveView.Extent;

using (ComReleaser com = new ComReleaser())
{

  scDisplay.StartDrawing(scDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);

  var fromPt = env.LowerLeft;
  var toPt = env.UpperRight;

  IPointCollection pts = new PolylineClass();
  pts.AddPoint(fromPt);
  pts.AddPoint(toPt);

  ISymbol sym = new WaveLine();
  ((WaveLine)sym).Width = env.Width / 25;


  sym.SetupDC(scDisplay.hDC, scDisplay.DisplayTransformation);

  sym.Draw((IGeometry)pts);
  sym.ResetDC();

  scDisplay.StopRecording();
カテゴリー: 開発 タグ: パーマリンク