Select to view content in your preferred language

Conversion from Feature Layer Renderer Object to Javascript API Compatible JSON

628
1
06-12-2019 01:24 AM
VedantBajaj
Esri Contributor

From Pro SDK, I need to pass the rendering information to the JavaScript API. JavaScript API expects the renderer as a JSON. Is there any way to directly convert it to the JS API Compatible JSON. I tried serializing the CIMRenderer but the JS API expects it in a different format.

https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-SimpleRenderer.html

https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-UniqueValueRenderer.htm...

Examples of JS API Compatible renderer JSON:

Eg: Simple Renderer
{
“type”: “simple”,
“symbol”: {
 "type": “point”,
 "style": “circle”,
 "color": [255,244,244,0.6], //rgba 
 "outline": {
                  "width": 1, // in pixels
                  “color”: [255,140,0,0.5] //rgba
            },
 “size”: 4 // radius in pixels
}
}
 
Eg. Unique Value Renderer
{
“type”: “uniqueValue”,
“field1”: “Asset”, //field in layer based on which features are rendered
“uniqueValueInfos”: [
{
  “label”: “Car”,
  “value”: “1”,
  “symbol”: {
                  "type": “point”,
                  "style": “circle”,
                  "color": [255,244,244,0.6]
                  "outline": {
                                 "width": 1,
                                 “color”: [255,140,0,0.5]
                         },
                  “size”: 4 // radius in pixels
          }
},
{
  “label”: “Pool”,
  “value”: “2”,
  “symbol”: {
                  "type": “point”,
                  "style": “circle”,
                  "color": [237, 81, 81, 1]
                  "outline": {
                                 "width": 0.75,
                                 “color”: [153, 153, 153, 1] 
                         },
                  “size”: 3
          }
 
}
0 Kudos
1 Reply
CraigWilliams
Esri Contributor

This type of conversion is typically handled during the sharing process when creating weblayers, webmaps, or when handing out such layers from MapServices. There's not a direct API call to convert between these specifications. ArcGIS Pro uses the CIM specification while the JavaScript API uses the WebMap specification.

Can you explain more about your workflow and what you're looking to create?

0 Kudos