Reset Layer List

1847
4
02-21-2017 02:41 AM
PieterjanWintjes
New Contributor III

Hi,

I am looking for a possibility to reset the layer list to its original settings after switching on and off several individual layers.

Can this beadded to, either the ESRI widget Layer List or the (Communtiy) enhanced Layer List.

Thanks,

Pieterjan Wintjes

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Pieterjan,

   You can use the WAB app state manager to accomplish this:

'jimu/LayerInfos/LayerInfos',
'jimu/AppStateManager'
...
LayerInfos,
AppStateManager
...
//Save the apps state before you changes the layers
this.appStateManager = AppStateManager.getInstance(null);
this.appStateManager.saveWabAppState(this.map, this.layerInfosObj);

//restore apps state
this.appStateManager.getWabAppState().then(lang.hitch(this, function(stateData) {
  var layerOptions = stateData.layers;
  this.layerInfosObj.restoreState({
    layerOptions: layerOptions || null
  });
}));

The main issue with this is it will save the map extent as well as the layer visibility.

PieterjanWintjes
New Contributor III

Hi Robert,

Thank you for your response, I think I did not make myself clear in my question.

If I restart my application you and click on the black window in the lower right corner of my screen I go back to my latest location including the layer settings.

What my customers are actually asking for, is having a possibility to go to the latest location, but with the default settings of the TOC, or maybe better, add an option to the top right button in the layer widget, which will reset the layers to its default settings.

Pieterjan

Van: Robert Scheitlin, GISP

Verzonden: dinsdag 21 februari 2017 15:20

Aan: Wintjes, Pieterjan <pieterjan.wintjes@brabantwater.nl>

Onderwerp: Re: - Re: Reset Layer List

GeoNet <https://community.esri.com/?et=watches.email.thread>

Re: Reset Layer List

reply from Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.thread> in ArcGIS API for JavaScript - View the full discussion<https://community.esri.com/message/667949-re-reset-layer-list?commentID=667949&et=watches.email.thread#comment-667949>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Pieterjan,

   Actually I did understand your question and suggested something that is the closest to what you are asking for. So happy coding.

0 Kudos
PieterjanWintjes
New Contributor III

Hi Robert,

Glad you understood the idea, but my knowledge of ‘happy coding’ is not that big. I added the code as far as I could, but I don’t know where to place this part:

//Save the apps state before you changes the layers

this.appStateManager = AppStateManager.getInstance(null);

this.appStateManager.saveWabAppState(this.map, this.layerInfosObj);

//restore apps state

this.appStateManager.getWabAppState().then(lang.hitch(this, function(stateData) {

var layerOptions = stateData.layers;

this.layerInfosObj.restoreState({

layerOptions: layerOptions || null

});

}));

Can you give me a hint where this code needs to be added.

Thanks,

Pieterjan

Van: Robert Scheitlin, GISP

Verzonden: woensdag 22 februari 2017 15:10

Aan: Wintjes, Pieterjan <pieterjan.wintjes@brabantwater.nl>

Onderwerp: Re: - Re: Reset Layer List

GeoNet <https://community.esri.com/?et=watches.email.thread>

Re: Reset Layer List

reply from Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.thread> in ArcGIS API for JavaScript - View the full discussion<https://community.esri.com/message/668292-re-reset-layer-list?commentID=668292&et=watches.email.thread#comment-668292>

0 Kudos