What code do I need to modify to have Web AppBuilder 2.0 app save state default to being on with no prompt in the lower right corner. I want it to automatically load the users extent and layers from their last session when the application is started.
Joel,
In the apps MapManager.js search for the _checkAppState function and make these changes (Lines 22 - 34):
_checkAppState: function() { //URL parameters that affect map extent var urlKeys = ['extent', 'center', 'marker', 'find', 'query', 'scale', 'level']; var useAppState = this.appConfig.keepAppState; if(useAppState) { array.forEach(urlKeys, function(k){ if(k in this.urlParams){ useAppState = false; } }, this); } if(useAppState){ this.appStateManager.getWabAppState().then(lang.hitch(this, function(stateData) { LayerInfos.getInstance(this.map, this.map.itemInfo) .then(lang.hitch(this, function(layerInfosObj) { this.layerInfosObj = layerInfosObj; if(stateData.extent || stateData.layers) { // var appStatePopup = new AppStatePopup({ // nls: { // title: this.nls.appState.title, // restoreMap: this.nls.appState.restoreMap // } // }); // appStatePopup.placeAt('main-page'); // on(appStatePopup, 'applyAppState', lang.hitch(this, function(){ // this._applyAppState(stateData, this.map); // })); // appStatePopup.startup(); // appStatePopup.show(); this._applyAppState(stateData, this.map); } })); })); } },
Still works in 2.10
Hi Robert, do you have an update for this in 2.8 /2.9? The same change doesn't seem to be working. Thanks!
Elwyn,
Sorry I do not.
Hi Robert,
thanks these changes in MapManager.js work on Windows, Mac and Android. But in Safari on Apple devices the app doesn't recover the app state. Do you have any suggestions on how to fix this?
Worked for me in 2.1
Don't forget to mark the reply that answered your question by clicking the Correct Answer link.
Thanks! Worked great. Exactly what I was looking for.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.