Select to view content in your preferred language

Feature layer reference nested in web map group

369
1
09-22-2024 05:44 AM
wadsonmakari
Occasional Contributor

Hello all

Is there a way to get a reference to a feature layer within nested groups. I have built an experience and I am developing a custom widget that needs to select from one of the feature layers e.g Feature layer 1(see structure of the web map below),present the selected records on the widget so the user can use some of the selected records to drive further analysis

Group1

-Sub Group1

   -Feature layer 1

  -Feature layer 2

-Sub group 2

  -Feature layer 3

 -Feature layer 4

Group 2

-Sub group 2

 - Feature layer 5

 - Feature layer 6

I have followed this example here https://github.com/EsriDevEvents/arcgis-experience-builder-customizing-and-extending-2022/blob/main/...

I can't figure out a way of getting a reference to any of the feature layers nested in groups in my Map widget

Essentially I need a reference the Feature layer in way that is similar to this

const layer = this.state.jimuMapView.view.map.layers.getItemAt(0) // as FeatureLayer

It looks like this.state.jimuMapView.view.map.layers can only access the top level groups. In my example above that will be Group 1 and Group 2.

Is there a way of getting a reference to feature layers nested in groups? Is there an alternative way to achieve this that does not necessarily follow this workflow?

0 Kudos
1 Reply
TimWestern
MVP

I have done some debugging and I think I recall seeing that the layers look like data sources under a group or subgroup, so in theory it could be discoverable.  The problem is, the ids they get seem to be auto-generated.  The best fix I've seen for this is setup a settings file for your widget such that the order you assign the widgets goes to a particular index in the UseDataSources element.   If you do that, then you can set up an easy enumeration with a more readable name you can use to in theory look them up by index using the enumeration that matches the name.    I'm not sure there's an easier way to discover these on their own, especially when you may add a Map, and then have all these groups of groups of layers in side of it.  I've found making specific setup data sources for each later seems to be the approach that works, for now. 

0 Kudos