In the 4.x API there is no mention of a way to get a list of all widgets that have been added to the mapView via mapView.ui.add(); MapView only provides the notion of 'default' widgets via the ui.components property. Not sure why there is a distinction between default widgets and ones custom added, but there is, and it feels strange they are treated differently.
I need to implement responsive widgets and need a way to derive the active widgets list at any given time. I'm using a combination of default widgets and custom widgets. It appears I need to manage this list manually outside of the mapView instance?
Solved! Go to Solution.
Yang,
You can get the widget type by using declaredClass:
setTimeout(function(){
view.ui._components.forEach(function(comp){
console.info(comp.widget.declaredClass)
});
}, 200);
Yang,
I am not sure why they do not give custom widget either but you can get all the UI widget components (the actual components not the string name) using the view.ui._components.
Thanks Robert, console logged the _component property and yes I do see an array with length that matches the number of widgets I've added. However given it's not part of the official API and I assume their style intended for this to be a private member, I'm hesitant to rely on it for my logic. Looks like I'll just manage the widgets state outside of the arcGIS instance
Yang,
I use private stuff all the time in my code I just have to test each new release of the API that it still exists and works as it did previously.
The other issue is, none of the _component properties contain a string value that differentiate the custom widgets. The top level id property is only populated for the 'default' widgets zoom and attribution. The 'custom' widgets from arcgis' out of box library do not have the id property populated. I've looked through the nested props too. None of them seem to hold the identifier for the widget... Very strange of how the default and custom widgets are differentiated.
Yang,
You can get the widget type by using declaredClass:
setTimeout(function(){
view.ui._components.forEach(function(comp){
console.info(comp.widget.declaredClass)
});
}, 200);
Judging by ArcGIS' sample codes, it appears the pattern for toggling widgets is simply add / remove them. As such, I'm going to need to manage the widgets list anyway outside of the view instance, so I'll just take this approach instead of relying on the private prop. But good tip the decalredClass method! I missed that in the API doc.