I am using JavaScript 4.11 and I am trying to get the Feature Widget to access the popupTemplate for each layer that is under the same portalItem ID. So far the widget can only access one of the layers. Is there a way to write the code to have the widget access all of the items? I have the code below.
Solved! Go to Solution.
Here's one approach you could use: JS Bin - Collaborative JavaScript Debugging
Hi Marques,
You could use the layerId property to access other layers with in the portal item or service. Here is an example:
// loads the third layer in the given Portal Item
const layer = new FeatureLayer( {
portalItem: {
id: "8d26f04f31f642b6828b7023b84c2188"
},
layerId: 2
});
Hi David,
Thank you for your reply! I have tried that and it only accesses one layer at a time. I would like it so that each layer is showing in the Layer list and the widget works with each layer as I turn them on/off respectively. Apologies if I did not explain that in the initial post.
Marques,
In that case a work around I can think of is to make a GroupLayer with the individual layerId-layers/portal-items and add that GroupLayer to the map instead of the indivdual portal items. This method will also allow you to have more customization control when making certain layers visible or not and if you want to add actions to the LayerList such as decreasing opacity of a layer or GroupLayer.
Here's one approach you could use: JS Bin - Collaborative JavaScript Debugging
Yes!!! thank you so much!!!
would I use the visibilityMode to manage only having one layer visibile at a time?
Hi Marques,
If you set the visibilityMode of the GroupLayer to "independent" then it will treat child layers independently and allow you to click on and off on the child layers. Also if you declare each layer as a separate layer you can set their visibility as false or true if you want to initially show specific layers on startup.
Here is documentation on GroupLayer and its properties: GroupLayer | ArcGIS API for JavaScript 4.11
So would it be something like the following....(apologies I am learning JS as I go along)
Hi Marques,
I have redone the code for you here: JS Bin - Collaborative JavaScript Debugging
You can further edit the GroupLayer and the individual layers as you want from here. You can also create actions for the LayerList, like decreasing opacity if you so wish.