Hello,
In ArcGIS Pro, there is an option in the legendElement from layout to display only legend items when at least one feature is displayed on the map extent (Only show features visible in the map extent).
Is there such an option in the SDK or should I loop through the MapFrame's layer, make a check and then remove the element from the legend.
Thanks.
Solved! Go to Solution.
I am assuming u are referring to this setting....
which I am not personally familiar with but...if that _is_ the property u are interested in, with a bit of trial and error, it turns out it is this guy here: CIMLegendItem.AutoVisibility
This snippet toggles that AutoVisibility for all legend items. I noticed that the legend item property UI did not automatically refresh to reflect the "toggled" value but that is a bug (and I will relay that to the layout team). To update the UI I had to click on the legend and then back on the legend item.
internal class ToggleAutoVisibility : Button
{
protected override void OnClick()
{
var lyt = LayoutView.Active?.Layout;
if (lyt == null)
return;
QueuedTask.Run(() =>
{
var def = lyt.GetDefinition();
var legend = def.Elements.OfType<CIMLegend>().FirstOrDefault();
if (legend != null)
{
//toggle auto visibility of all the legend items
foreach(var leg_item in legend.Items)
{
leg_item.AutoVisibility = !leg_item.AutoVisibility;
}
//commit the change
lyt.SetDefinition(def);
}
});
}
}
I am assuming u are referring to this setting....
which I am not personally familiar with but...if that _is_ the property u are interested in, with a bit of trial and error, it turns out it is this guy here: CIMLegendItem.AutoVisibility
This snippet toggles that AutoVisibility for all legend items. I noticed that the legend item property UI did not automatically refresh to reflect the "toggled" value but that is a bug (and I will relay that to the layout team). To update the UI I had to click on the legend and then back on the legend item.
internal class ToggleAutoVisibility : Button
{
protected override void OnClick()
{
var lyt = LayoutView.Active?.Layout;
if (lyt == null)
return;
QueuedTask.Run(() =>
{
var def = lyt.GetDefinition();
var legend = def.Elements.OfType<CIMLegend>().FirstOrDefault();
if (legend != null)
{
//toggle auto visibility of all the legend items
foreach(var leg_item in legend.Items)
{
leg_item.AutoVisibility = !leg_item.AutoVisibility;
}
//commit the change
lyt.SetDefinition(def);
}
});
}
}
That was it. Thanks !