Select to view content in your preferred language

Web AppBuilder 2.0 app state default on

4626
10
Jump to solution
04-08-2016 03:10 PM
JoelEdgar
Occasional Contributor

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.

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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);
              }
            }));
          }));
        }
      },

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

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);
              }
            }));
          }));
        }
      },
JoelEdgar
Occasional Contributor

Thanks! Worked great. Exactly what I was looking for.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Joel,


  Don't forget to mark the reply that answered your question by clicking the Correct Answer link.

SowjanyaSunkara3
Deactivated User

Worked for me in 2.1

deleted-user-byYNSf-f9ge6
Deactivated User

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?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Elwyn,

  Sorry I do not.

0 Kudos
LeoLadefian5
Frequent Contributor

Hi Robert, do you have an update for this in 2.8 /2.9?  The same change doesn't seem to be working.  Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

LeoLadefian5
Frequent Contributor

oops, forgot to add line 34, thanks again.

0 Kudos