How to get SimpleRenderer.ToJson to include Symbol?

439
3
Jump to solution
03-19-2020 04:03 PM
KirkKuykendall2
Occasional Contributor

With a featurelayer created from this:

https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServe... 

featureLayer.Renderer.ToJson() returns json that lacks the symbol:

{
 "symbol": {},
 "type": "simple"
}‍‍‍‍

But ((SimpleRenderer)featureLayer.Renderer).Symbol.ToJson() returns this:

{
  "symbol": {
    "angleAlignment": "Display",
    "symbolLayers": [
      {
        "anchorPoint": {
          "x": 0,
          "y": 0
        },
        "anchorPointUnits": "Relative",
        "billboardMode3D": "FaceNearPlane",
        "dominantSizeAxis3D": "Z",
        "enable": true,
        "frame": {
          "xmax": 2,
          "xmin": -2,
          "ymax": 2,
          "ymin": -2
        },
        "markerGraphics": [
          {
            "geometry": {
              "rings": [
                [
                  [
                    0,
                    2
                  ],
                  [
                    0.35,
                    1.97
                  ],
                  [
                    0.68,
                    1.88
                  ],
                  [
                    1,
                    1.73
                  ],
                  [
                    1.29,
                    1.53
                  ],
                  [
                    1.53,
                    1.29
                  ],
                  [
                    1.73,
                    1
                  ],
                  [
                    1.88,
                    0.68
                  ],
                  [
                    1.97,
                    0.35
                  ],
                  [
                    2,
                    0
                  ],
                  [
                    1.97,
                    -0.35
                  ],
                  [
                    1.88,
                    -0.68
                  ],
                  [
                    1.73,
                    -1
                  ],
                  [
                    1.53,
                    -1.29
                  ],
                  [
                    1.29,
                    -1.53
                  ],
                  [
                    1,
                    -1.73
                  ],
                  [
                    0.68,
                    -1.88
                  ],
                  [
                    0.35,
                    -1.97
                  ],
                  [
                    0,
                    -2
                  ],
                  [
                    -0.35,
                    -1.97
                  ],
                  [
                    -0.68,
                    -1.88
                  ],
                  [
                    -1,
                    -1.73
                  ],
                  [
                    -1.29,
                    -1.53
                  ],
                  [
                    -1.53,
                    -1.29
                  ],
                  [
                    -1.73,
                    -1
                  ],
                  [
                    -1.88,
                    -0.68
                  ],
                  [
                    -1.97,
                    -0.35
                  ],
                  [
                    -2,
                    0
                  ],
                  [
                    -1.97,
                    0.35
                  ],
                  [
                    -1.88,
                    0.68
                  ],
                  [
                    -1.73,
                    1
                  ],
                  [
                    -1.53,
                    1.29
                  ],
                  [
                    -1.29,
                    1.53
                  ],
                  [
                    -1,
                    1.73
                  ],
                  [
                    -0.68,
                    1.88
                  ],
                  [
                    -0.35,
                    1.97
                  ],
                  [
                    0,
                    2
                  ]
                ]
              ]
            },
            "symbol": {
              "symbolLayers": [
                {
                  "capStyle": "Round",
                  "color": [
                    0,
                    0,
                    0,
                    255
                  ],
                  "enable": true,
                  "joinStyle": "Round",
                  "lineStyle3D": "Strip",
                  "miterLimit": 10,
                  "type": "CIMSolidStroke",
                  "width": 0.7
                },
                {
                  "color": [
                    0,
                    0,
                    0,
                    255
                  ],
                  "enable": true,
                  "type": "CIMSolidFill"
                }
              ],
              "type": "CIMPolygonSymbol"
            },
            "type": "CIMMarkerGraphic"
          }
        ],
        "respectFrame": true,
        "size": 4,
        "type": "CIMVectorMarker"
      }
    ],
    "type": "CIMPointSymbol"
  },
  "type": "CIMSymbolReference"
}
0 Kudos
1 Solution

Accepted Solutions
PreetiMaske
Esri Contributor

If feature table has advanced symbology , it is as designed that Renderer.ToJson will return empty symbol info and ((SimpleRenderer)Renderer).Symbol.toJson() will return the json of CIM Symbol.

Since the service you had has AdvancedSymbology enabled, what you are getting is as expected.

If you to access the simple symbol as advertised in layer's metadata you can turn FeatureTable.UseAdvanceSymbology=false before loading the table.

Uri serviceUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0");
var table = new ServiceFeatureTable(serviceUri);
table.UseAdvancedSymbology = false;
await table.LoadAsync();
// Create new FeatureLayer from service uri and
FeatureLayer fLayer = new FeatureLayer(table);
var str = fLayer.Renderer.ToJson();

NOW YOU WILL GET FOLLOWING FROM RENDERER.TOJSON()
{"symbol":{"angle":0,"color":[255,255,115,255],"outline":{"color":[0,0,0,255],"style":"esriSLSSolid","type":"esriSLS","width":1},"size":4,"style":"esriSMSCircle","type":"esriSMS","xoffset":0,"yoffset":0},"type":"simple"}

View solution in original post

0 Kudos
3 Replies
dotMorten_esri
Esri Frequent Contributor

Are you on an older version of runtime? I believe those symbol types weren't fully supported until more recent versions.

0 Kudos
KirkKuykendall2
Occasional Contributor

This is with 100.7 WPF on .NET framework 4.8.

0 Kudos
PreetiMaske
Esri Contributor

If feature table has advanced symbology , it is as designed that Renderer.ToJson will return empty symbol info and ((SimpleRenderer)Renderer).Symbol.toJson() will return the json of CIM Symbol.

Since the service you had has AdvancedSymbology enabled, what you are getting is as expected.

If you to access the simple symbol as advertised in layer's metadata you can turn FeatureTable.UseAdvanceSymbology=false before loading the table.

Uri serviceUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0");
var table = new ServiceFeatureTable(serviceUri);
table.UseAdvancedSymbology = false;
await table.LoadAsync();
// Create new FeatureLayer from service uri and
FeatureLayer fLayer = new FeatureLayer(table);
var str = fLayer.Renderer.ToJson();

NOW YOU WILL GET FOLLOWING FROM RENDERER.TOJSON()
{"symbol":{"angle":0,"color":[255,255,115,255],"outline":{"color":[0,0,0,255],"style":"esriSLSSolid","type":"esriSLS","width":1},"size":4,"style":"esriSMSCircle","type":"esriSMS","xoffset":0,"yoffset":0},"type":"simple"}
0 Kudos