Select to view content in your preferred language

Map Legend Selected Item Improvements

1455
5
04-11-2011 05:30 PM
JDog
by
Emerging Contributor
Is it possible to get a more robust mechanism to extract the currently selected item from the Legend control?  I've been fighting with the Tree class as well as the "LayerItemViewModel" or "LegendItemViewModel" to extract out which layer from the collection of layers loaded into the Map Viewer control is currently selected.  I would like to determine the Layer Type (Dynamic Layer, Feature Layer, etc.) as well as the Layer ID.  This would enable me to set the various other controls like Identify control, Editor control, etc. 

My biggest challenge is that I can't figure out a practical way to determine the "Parent Layer" of a Feature layer if that feature layer has styles assigned to it?  The LegendTree could potentially provide me a way to grab the Parent Layer ID using something like this "itm.LegendTree.LayerItems.Items(itm.LegendTree.LayerItemsMode)" but it's not an exposed item?

Any thoughts?
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
I would like to determine the Layer Type (Dynamic Layer, Feature Layer, etc.) as well as the Layer ID. This would enable me to set the various other controls like Identify control, Editor control, etc.


From any legend item, you can get the underlying layer with :   legendItem.Layer.
Then with this layer you can access any layer property  such as  the layerID, the layerType,.....


I can't figure out a practical way to determine the "Parent Layer" of a Feature layer if that feature layer has styles assigned to it?

Not sure what you mean by 'Parent Layer' and 'has styles', but perhaps usage of legendItem.Layer will fix this issue as well.
0 Kudos
JDog
by
Emerging Contributor
By Parent Layer, I mean a Feature Layer could have styles that get represented by child nodes in the treeview under a given Feature Layer.  The styles are selectable but return a different object type (can't recall if it returns LegendItem or LayerItem?).  I haven't been able to figure out how to get the Feature Layer details from these items?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
OK, I see the problem.

There is nothing exposed by the API that returns the parent item of a legend item.

You have to go through the legend tree with a program similar to that returning the selected item (or you can extend that program to return at the same time the selected item and the parent item).
0 Kudos
Reynaldde_Castro
Deactivated User
Is there a way to programmatically set the selected layer?  I want to check a particular checkbox depending on user selection.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Is there a way to programmatically set the selected layer?


If you are talking about selecting a layer in the legend control, you can do that by code by using the 'IsSelected' property of the LayerItemViewModel.
This sample : http://help.arcgis.com/en/webapi/sil...dWithTemplates demonstrates how to use the 'IsCollapsed' property but you can use the IsSelected property the same way (except than with the default template, the legend supports one selected item only).
0 Kudos