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/
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
<SPAN class="keyword token">var</SPAN> lyr <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>f <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> f<SPAN class="punctuation token">.</SPAN>ShapeType <SPAN class="operator token">==</SPAN> esriGeometryType<SPAN class="punctuation token">.</SPAN>esriGeometryPolygon<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyr <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// GetRenderer from Layer (assumes it is a unique value renderer)</SPAN> <SPAN class="keyword token">var</SPAN> uvRenderer <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetRenderer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> CIMUniqueValueRenderer<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>uvRenderer <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//layer has STATE_NAME field</SPAN> <SPAN class="comment token">//community sample Data\Admin\AdminSample.aprx</SPAN> <SPAN class="keyword token">string</SPAN> expression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"if ($view.scale > 21000000) { return $feature.STATE_NAME } else { return 'All' }"</SPAN><SPAN class="punctuation token">;</SPAN> CIMExpressionInfo updatedExpressionInfo <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">CIMExpressionInfo</SPAN> <SPAN class="punctuation token">{</SPAN> Expression <SPAN class="operator token">=</SPAN> expression<SPAN class="punctuation token">,</SPAN> Title <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Custom"</SPAN> <SPAN class="comment token">// can be any string used for UI purpose.</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//set the renderer's expression</SPAN> uvRenderer<SPAN class="punctuation token">.</SPAN>ValueExpressionInfo <SPAN class="operator token">=</SPAN> updatedExpressionInfo<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//SetRenderer on Layer</SPAN> lyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetRenderer</SPAN><SPAN class="punctuation token">(</SPAN>uvRenderer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Modify label expression using Arcade
<SPAN class="keyword token">var</SPAN> lyr <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>f <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> f<SPAN class="punctuation token">.</SPAN>ShapeType <SPAN class="operator token">==</SPAN> esriGeometryType<SPAN class="punctuation token">.</SPAN>esriGeometryPolygon<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyr <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//Get the layer's definition</SPAN> <SPAN class="comment token">//community sample Data\Admin\AdminSample.aprx</SPAN> <SPAN class="keyword token">var</SPAN> lyrDefn <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> CIMFeatureLayer<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyrDefn <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Get the label classes - we need the first one</SPAN> <SPAN class="keyword token">var</SPAN> listLabelClasses <SPAN class="operator token">=</SPAN> lyrDefn<SPAN class="punctuation token">.</SPAN>LabelClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> theLabelClass <SPAN class="operator token">=</SPAN> listLabelClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//set the label class Expression to use the Arcade expression</SPAN> theLabelClass<SPAN class="punctuation token">.</SPAN>Expression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Set the label definition back to the layer.</SPAN> lyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetDefinition</SPAN><SPAN class="punctuation token">(</SPAN>lyrDefn<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks
Uma
Thanks Uma,
I will check about operation.
Regards,
Takahiro Kamiya
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.