Use Arcade with Pro SDK

246
2
04-03-2018 11:48 PM
Highlighted
Esri Contributor

Is there an example of sample code and usage in Pro SDK?
Is it possible to change the renderer using Arcade?

Examples of this profile in context

https://developers.arcgis.com/arcade/guide/profiles/

Tags (1)
Reply
0 Kudos
2 Replies
Highlighted
Esri Regular Contributor

Hi,

The SDK Documentation will soon include a few snippets that modify the renderer and create labeling expressions using Arcade.  Here are a couple of snippets:

Modify renderer using Arcade

var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
if (lyr == null) return;
QueuedTask.Run(() => {
    // GetRenderer from Layer (assumes it is a unique value renderer)
    var uvRenderer = lyr.GetRenderer() as CIMUniqueValueRenderer;
    if (uvRenderer == null) return;
    //layer has STATE_NAME field
    //community sample Data\Admin\AdminSample.aprx
    string expression = "if ($view.scale > 21000000) { return $feature.STATE_NAME } else { return 'All' }";
    CIMExpressionInfo updatedExpressionInfo = new CIMExpressionInfo
    {
        Expression = expression,
        Title = "Custom" // can be any string used for UI purpose.
    };
    //set the renderer's expression
    uvRenderer.ValueExpressionInfo = updatedExpressionInfo;

    //SetRenderer on Layer
    lyr.SetRenderer(uvRenderer);
});

Modify label expression using Arcade

var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
if (lyr == null) return;
QueuedTask.Run(() => {
    //Get the layer's definition
    //community sample Data\Admin\AdminSample.aprx
    var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
    if (lyrDefn == null) return;
    //Get the label classes - we need the first one
    var listLabelClasses = lyrDefn.LabelClasses.ToList();
    var theLabelClass = listLabelClasses.FirstOrDefault();
    //set the label class Expression to use the Arcade expression
    theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;";
    //Set the label definition back to the layer.
    lyr.SetDefinition(lyrDefn);
});

Thanks

Uma

Highlighted
Esri Contributor

Thanks Uma, 

I will check about operation.

Regards,

Takahiro Kamiya

Reply
0 Kudos