I would like to be able to create a new label class on a featurelayer using the sdk.
Hi Uma,
Is there a way to get at the following:
To enable them through the sdk?
Thank you Michael
Never mind , I was able to get it to work.
Thank you
I tried it and it did not work. It does not create the label class and assign it on any of the layers.
Here is a code snippet to create a new label class and assign it to a feature layer.
Thanks
Uma
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="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">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//get the layer's defintion</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="comment token">//Text symbol to use for labelling</SPAN> <SPAN class="keyword token">var</SPAN> textSymbol <SPAN class="operator token">=</SPAN> SymbolFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ConstructTextSymbol</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Create the new label class and initialize props</SPAN> <SPAN class="keyword token">var</SPAN> newLabelClass <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">CIMLabelClass</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//Define the label expression engine</SPAN> ExpressionEngine <SPAN class="operator token">=</SPAN> LabelExpressionEngine<SPAN class="punctuation token">.</SPAN>Arcade<SPAN class="punctuation token">,</SPAN> <SPAN class="comment token">//Expression to use to label</SPAN> Expression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"$feature.NAME + $feature.Shape_Area"</SPAN><SPAN class="punctuation token">,</SPAN> Visibility <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">,</SPAN> TextSymbol <SPAN class="operator token">=</SPAN> textSymbol<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MakeSymbolReference</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> Name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"MyNewLabelClass"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Most of the Maplex and standard engine placement properties get set automatically.</SPAN> <SPAN class="comment token">//But you have to set the feature type explicitly. Line seems default.</SPAN> <SPAN class="keyword token">var</SPAN> maplexLabelPlacementProps <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">CIMMaplexLabelPlacementProperties</SPAN> <SPAN class="punctuation token">{</SPAN> FeatureType <SPAN class="operator token">=</SPAN> LabelFeatureType<SPAN class="punctuation token">.</SPAN>Polygon <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> standardLabelPlacementProps <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">CIMStandardLabelPlacementProperties</SPAN> <SPAN class="punctuation token">{</SPAN> FeatureType <SPAN class="operator token">=</SPAN> LabelFeatureType<SPAN class="punctuation token">.</SPAN>Polygon <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Set the placement prop defined to the label class.</SPAN> newLabelClass<SPAN class="punctuation token">.</SPAN>MaplexLabelPlacementProperties <SPAN class="operator token">=</SPAN> maplexLabelPlacementProps<SPAN class="punctuation token">;</SPAN> newLabelClass<SPAN class="punctuation token">.</SPAN>StandardLabelPlacementProperties <SPAN class="operator token">=</SPAN> standardLabelPlacementProps<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Get the layer's label classes</SPAN> <SPAN class="keyword token">var</SPAN> lyrsLabelsClasses <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="comment token">//Add the new label class to the labels label class</SPAN> lyrsLabelsClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>newLabelClass<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> lyrDefn<SPAN class="punctuation token">.</SPAN>LabelClasses <SPAN class="operator token">=</SPAN> lyrsLabelsClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToArray</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Set the labelClasses back</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="comment token">//set the layer's definition;</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></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><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.