ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMPointGraphic Class / ToJson Method
The JSON serialization settings.
Example

In This Topic
    ToJson Method (CIMPointGraphic)
    In This Topic
    Creates a JSON encoding of the CIMPointGraphic and its current state.
    Syntax
    Public Overrides Function ToJson( _
       Optional ByVal settings As JsonSerializationSettings _
    ) As String
    public override string ToJson( 
       JsonSerializationSettings settings
    )

    Parameters

    settings
    The JSON serialization settings.
    Example
    Create Graphic Element using CIMGraphic
    {
      //Note: on the QueuedTask
      //Place symbol on the layout
      MapPoint location = MapPointBuilderEx.CreateMapPoint(new Coordinate2D(9, 1));
    
      //specify a symbol
      var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                            ColorFactory.Instance.GreenRGB);
    
      //create a CIMGraphic 
      var graphic = new CIMPointGraphic()
      {
        Symbol = pt_symbol.MakeSymbolReference(),
        Location = location //center of map
      };
      //Or use GraphicFactory
      var graphicFactory = GraphicFactory.Instance.CreateSimpleGraphic(location, pt_symbol);
    
      ElementFactory.Instance.CreateGraphicElement(layout, graphic);
      ElementFactory.Instance.CreateGraphicElement(layout, graphicFactory);
    }
    Create Graphic Element using CIMSymbol
    {
      //Note: Must be on QueuedTask.Run
      //Place symbol on the layout
      MapPoint location = MapPointBuilderEx.CreateMapPoint(new Coordinate2D(9, 1));
    
      //specify a symbol
      var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                            ColorFactory.Instance.GreenRGB);
    
      ElementFactory.Instance.CreateGraphicElement(layout, location, pt_symbol);
    }
    Bulk Element creation
    {
      //Note: Must be on QueuedTask.Run
    
      //List of Point graphics
      var listGraphics = new List<CIMPointGraphic>();
      var listGraphicsFactory = new List<CIMPointGraphic>();
      //Symbol
      var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                                          ColorFactory.Instance.BlackRGB);
      //Define size of the array
      int dx = 5;
      int dy = 5;
      MapPoint point = null;
      //Create the List of graphics for the array
      for (int row = 0; row <= dx; ++row)
      {
        for (int col = 0; col <= dy; ++col)
        {
          point = MapPointBuilderEx.CreateMapPoint(col, row);
          //create a CIMGraphic 
          var graphic = new CIMPointGraphic()
          {
            Symbol = pointSymbol.MakeSymbolReference(),
            Location = point
          };
          listGraphics.Add(graphic);
          //Or use GraphicFactory
          var graphicFactory = GraphicFactory.Instance.CreateSimpleGraphic(
                                        point, pointSymbol) as CIMPointGraphic;
          listGraphicsFactory.Add(graphicFactory);
        }
      }
      //Draw the array of graphics
    
      var bulkgraphics = ElementFactory.Instance.CreateGraphicElements(
                                                         layout, listGraphics);
      var bulkgraphicsFactory = ElementFactory.Instance.CreateGraphicElements(
                                                         layout, listGraphicsFactory);
    }
    Create Element using a CIMGraphicElement
    {
      //Note: Must be on QueuedTask.Run
    
      //Place symbol on the layout
      MapPoint point = MapPointBuilderEx.CreateMapPoint(new Coordinate2D(9, 1));
    
      //specify a symbol
      var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                            ColorFactory.Instance.GreenRGB);
    
      //create a CIMGraphic 
      var graphic = new CIMGraphicElement()
      {
        Graphic = new CIMPointGraphic()
        {
          Symbol = pt_symbol.MakeSymbolReference(),
          Location = point //A point in the layout
        }
      };
      ElementFactory.Instance.CreateElement(layout, graphic);
    }
    Create Picture Graphic Element using CIMSymbol
    {
      //Note: Must be on QueuedTask.Run(() => { ...
    
      //Build geometry
      Coordinate2D ll = new Coordinate2D(0.5, 1);
      Coordinate2D ur = new Coordinate2D(2.5, 2);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Create and add element to layout
      string picPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
        "SamplePicture.jpg");
      var pic_gr = ElementFactory.Instance.CreatePictureGraphicElement(
        layout, env.Center, picPath, "New Picture", true, new ElementInfo() { Anchor = Anchor.CenterPoint });
    }
    Point Graphic Element using CIMGraphic
    {
      // Note: must be called on the QueuedTask
      {
        //Place symbol in the center of the map
        var extent = MapView.Active.Extent;
        var location = extent.Center;
    
        //specify a symbol
        var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                              ColorFactory.Instance.GreenRGB);
    
        //create a CIMGraphic 
        var graphic = new CIMPointGraphic()
        {
          Symbol = pt_symbol.MakeSymbolReference(),
          Location = location //center of map
        };
        graphicsLayer.AddElement(graphic);
      }
    }
    Bulk Graphics creation
    {
      //Point Feature layer to convert into graphics
      var lyr = MapView.Active?.Map?.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPoint);
      if (lyr == null) return;
      // Note: must be called on the QueuedTask
      {
        //Point symbol for graphics
        var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(100, 255, 40), 10, SimpleMarkerStyle.Circle);
        //Collection to hold the point graphics
        var listGraphicElements = new List<CIMGraphic>();
        //Iterate through each point feature in the feature layer
        using (RowCursor rows = lyr.Search()) //execute
        {
          int i = 0;
          while (rows.MoveNext())
          {
            using var feature = rows.Current as Feature;
            //Create a point graphic for the feature
            var crimePt = feature.GetShape() as MapPoint;
            if (crimePt != null)
            {
              var cimGraphicElement = new CIMPointGraphic
              {
                Location = crimePt, //MapPoint
                Symbol = pointSymbol.MakeSymbolReference()
              };
              //Add the point feature to the collection
              listGraphicElements.Add(cimGraphicElement);
              i++;
            }
          }
        }
        //Magic happens...Add all the features to the Graphics layer 
        graphicsLayer.AddElements(listGraphicElements);
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also