I am trying to iterate layers and change visibility of fields in feature layers. I tryed to get "CIMFieldDescription" but it returns null when layer has default field descriptions.
Am I going in wrong way?
Hi
The best way to change the visibility of a field to use the IDisplayTable.
This code will set all the fields in a layer to be visible:
<SPAN class="keyword token">var</SPAN> table <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><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> IDisplayTable<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="keyword token">var</SPAN> fieldDescriptions <SPAN class="operator token">=</SPAN> table<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetFieldDescriptions</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> field <SPAN class="keyword token">in</SPAN> fieldDescriptions<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> field<SPAN class="punctuation token">.</SPAN>IsVisible <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> table<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetFieldDescriptions</SPAN><SPAN class="punctuation token">(</SPAN>fieldDescriptions<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>
Thanks
Uma
Thank you for your help.
Your code help me to find out my mistake. My code worked by adding code "fl.SetFieldDescriptions(fieldDesc);"
Map pmap = await FindOpenExistingMapAsync(tb_Map.Text); List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList(); foreach (BasicFeatureLayer fl in featureLayerList) { await QueuedTask.Run(() => { var fieldDesc = fl.GetFieldDescriptions(); foreach (var fd in fieldDesc) { fd.IsVisible = myconfig.Visible; fd.Alias = myconfig.Alias; } fl.SetFieldDescriptions(fieldDesc); }); }
I used following code to change visibility but nothing changed on layers.
Map pmap = await FindOpenExistingMapAsync(tb_Map.Text);
List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList(); listView1.ItemsSource = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();
foreach (BasicFeatureLayer fl in featureLayerList) { await QueuedTask.Run(() => { foreach (FieldDescription fd in fl.GetFieldDescriptions()) { fd.IsVisible = true; fd.Alias = myconfig.Alias; }
});
}
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.