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.
Solved! Go to Solution.
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); } })); })); } },
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); } })); })); } },
Thanks! Worked great. Exactly what I was looking for.
Joel,
Don't forget to mark the reply that answered your question by clicking the Correct Answer link.
Worked for me in 2.1
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?
Elwyn,
Sorry I do not.
Hi Robert, do you have an update for this in 2.8 /2.9? The same change doesn't seem to be working. Thanks!
Leo,
The code base for that function is unchanged in 2.8 and 2.9 so there is no reason it would not still work.
oops, forgot to add line 34, thanks again.