FAQ
グループ エレメントの作成

ナレッジ番号:5277 | 登録日:2023/07/26 | 更新日:2023/12/28

概要

このサンプル コードはグループ エレメントを作成し、マップ上に配置する方法を示しています。

サンプル コード

グループ エレメントを作成してマップ上に配置

ArcMap のマップ上に、ポリゴン エレメント、ライン エレメント、マーカー エレメント から構成されるグループ エレメントを作成し、最後にマップを再描画するサンプル コードです。作成するグループ エレメントはアクティブなビューの約半分の大きさになります。

Image

        //シンボルを作成・定義する。
        ISimpleLineSymbol pLineSym = new SimpleLineSymbolClass();
        ISimpleMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass();

        IRgbColor prgbcolor = new RgbColorClass();
        prgbcolor.Red = 120;
        prgbcolor.Green = 30;
        prgbcolor.Blue = 120;
        pLineSym.Color = prgbcolor;
        pMarkerSym.Color = pLineSym.Color;

        //エレメントを作成する。
        IPolygonElement RectEle = new PolygonElementClass();
        ILineElement LineEle = new LineElementClass();
        IMarkerElement PointEle = new MarkerElementClass();

        IPoint pPointS = new PointClass();
        IPoint pPointE = new PointClass();
        IPoint pPointC = new PointClass();
        IPolyline pLine = new PolylineClass();
        IPolygon pPoly = new PolygonClass();
        Double x, y;
        IEnvelope Env = ArcMap.Document.ActiveView.Extent;
        Env.Expand(0.5, 0.5, true);
        x = Env.LowerLeft.X;
        y = Env.LowerLeft.Y;
        pPointS.PutCoords(x, y);
        x = Env.UpperRight.X;
        y = Env.UpperRight.Y;
        pPointE.PutCoords(x, y);
        pLine.FromPoint = pPointS;
        pLine.ToPoint = pPointE;
        //pPointC を pPointS と pPointE の中点として配置する。
        pPointC.PutCoords((pPointE.X - pPointS.X) / 2 + pPointS.X, (pPointE.Y - pPointS.Y) / 2 + pPointS.Y);

        (LineEle as IElement).Geometry = pLine;
        (PointEle as IElement).Geometry = pPointC;
        (pPoly as ISegmentCollection).SetRectangle(Env);
        (RectEle as IElement).Geometry = pPoly;

        ISimpleFillSymbol currentSym = (RectEle as IFillShapeElement).Symbol as ISimpleFillSymbol;
        currentSym.Style = esriSimpleFillStyle.esriSFSHollow;
        currentSym.Outline = pLineSym;
        (RectEle as IFillShapeElement).Symbol = currentSym;
        LineEle.Symbol = pLineSym;
        PointEle.Symbol = pMarkerSym;

        //グループ エレメントを作成する。
        IGroupElement3 pGroupEle = new GroupElementClass();
        pGroupEle.AddElement(LineEle as IElement);
        pGroupEle.AddElement(PointEle as IElement);
        pGroupEle.AddElement(RectEle as IElement);
        (ArcMap.Document.FocusMap as IGraphicsContainer).AddElement(pGroupEle as IElement, 0);
        ArcMap.Document.ActiveView.Refresh();
        Dim plinesym As ISimpleLineSymbol = New SimpleLineSymbolClass
        Dim pmarkersym As ISimpleMarkerSymbol = New SimpleMarkerSymbolClass

        Dim prgbcolor As IRgbColor = New RgbColorClass
        prgbcolor.Red = 120
        prgbcolor.Green = 30
        prgbcolor.Blue = 120
        plinesym.Color = prgbcolor
        pmarkersym.Color = plinesym.Color

        Dim RectEle As IPolygonElement = New PolygonElementClass
        Dim LineEle As ILineElement = New LineElementClass
        Dim PointEle As IMarkerElement = New MarkerElementClass

        Dim ppointS As IPoint = New PointClass
        Dim ppointE As IPoint = New PointClass
        Dim ppointC As IPoint = New PointClass
        Dim pLine As IPolyline = New Polyline
        Dim pPoly As IPolygon = New Polygon
        Dim x, y As Double
        Dim Env = My.ArcMap.Document.ActiveView.Extent
        Env.Expand(0.5, 0.5, True)
        x = Env.LowerLeft.X
        y = Env.LowerLeft.Y
        ppointS.PutCoords(x, y)
        x = Env.UpperRight.X
        y = Env.UpperRight.Y
        ppointE.PutCoords(x, y)
        pLine.FromPoint = ppointS
        pLine.ToPoint = ppointE
        ppointC.PutCoords((ppointE.X - ppointS.X) / 2 + ppointS.X, (ppointE.Y - ppointS.Y) / 2 + ppointS.Y)

        CType(LineEle, IElement).Geometry = pLine
        CType(PointEle, IElement).Geometry = ppointC
        CType(pPoly, ISegmentCollection).SetRectangle(Env)
        CType(RectEle, IElement).Geometry = pPoly

        Dim currentSym As ISimpleFillSymbol = CType(RectEle, IFillShapeElement).Symbol
        currentSym.Style = esriSimpleFillStyle.esriSFSHollow
        currentSym.Outline = plinesym
        CType(RectEle, IFillShapeElement).Symbol = currentSym
        LineEle.Symbol = plinesym
        PointEle.Symbol = pmarkersym
       
        Dim pGroupEle As IGroupElement3 = New GroupElementClass
        pGroupEle.AddElement(LineEle)
        pGroupEle.AddElement(PointEle)
        pGroupEle.AddElement(RectEle)
        CType(My.ArcMap.Document.FocusMap, IGraphicsContainer).AddElement(pGroupEle, 0)
        My.ArcMap.Document.ActiveView.Refresh()

メタデータ

種類

製品