Hello, I have a need to show or hide our widgets based on logged users. I found Robert's post here - https://community.esri.com/thread/174605#comment-598708 . Since we use Launchpad theme, so i simply change "HeaderController" to "AnchorBarController" in the codes, but the Legend Icon didn't appear on the Anchor Bar and didn't open either. Does anybody make the codes work for Lauchpad theme?
Solved! Go to Solution.
Alex.
The Launchpad theme is pretty different.
var widgetCfg = this._getWidgetConfig('Draw');
widgetCfg.visible = true;
var anchorCfg = this._getWidgetConfig('AnchorBarController');
var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);
//This actually open the widget
anchorWidget._createItem(widgetCfg, anchorWidget.iconList.length + 1);
anchorWidget.setOpenedIds([widgetCfg.id]);
//This is need to show the widgets icon in the header
anchorWidget.resize();
anchorWidget._makeIconVisible(anchorWidget.iconList.length);
Alex.
The Launchpad theme is pretty different.
var widgetCfg = this._getWidgetConfig('Draw');
widgetCfg.visible = true;
var anchorCfg = this._getWidgetConfig('AnchorBarController');
var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);
//This actually open the widget
anchorWidget._createItem(widgetCfg, anchorWidget.iconList.length + 1);
anchorWidget.setOpenedIds([widgetCfg.id]);
//This is need to show the widgets icon in the header
anchorWidget.resize();
anchorWidget._makeIconVisible(anchorWidget.iconList.length);
Appreciate it, Robert. Your codes worked. The only thing was that the widget was added at the end of the Anchor bar. I tried to set the index to its original index (widgetCfg.index = 2; ), but it was still added at the end. is there a way to add it as the first one instead of the last one?
Alex,
No not that I am aware of as the anchor bar controller creates all visible widgets at startup and invisible ones are ignored.
OK, thanks Roberts. Can you do it in an opposite way - to set the Draw widget visible at startup, then hide it later?
Alex,
This will keep the widget index correct:
var widgetCfg = this._getWidgetConfig('Draw');
widgetCfg.visible = true;
var anchorCfg = this._getWidgetConfig('AnchorBarController');
var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);
//Save the ids of any opened widgets
var oids = anchorWidget.getOpenedIds();
oids.push(widgetCfg.id);
//This removes all the existing icons
anchorWidget.clearIconGroupNode();
//This will recreate all the icons now that one of more visible property has changed
anchorWidget.postCreate();
anchorWidget.setOpenedIds(oids);
//This is need to show the widgets icon in the header
anchorWidget.resize();
WOW!!! worked perfectly. Thank you so much for your help! I'll never be able to figure it out by myself.
Thanks again Robert. I tested that the codes didn't work for on-screen widgets such as Attribute Table Widget. Can you please shed some light one more time?
Alex,
Sorry, I don't have any insight on off panel widgets like the AT widget.
no problem. Thanks again Robert.