Force LayerList widget to refresh

1642
5
Jump to solution
05-09-2019 03:54 AM
sitsit
by
New Contributor III

Hi,

I am trying to modify the Save Session widget to save changes made by the user in the order of the layers, but I am stuck.

I succeeded in reorder the layers in the map, but the LayerList still shows the previous order.

Is there a simple way to force the LayerList to refresh?

I tried to add and then remove a dummy layer, with the following results:

- if the LayerList is not loaded when I load the session, everything works fine

- if the LayerList is already loaded when I load the session, the LayerList does not refresh

To add and remove the layer I simply used addLayer and removeLayer:

var dumLayer = new ArcGISDynamicMapServiceLayer(layer.url);
this.map.addLayer(dumLayer);
this.map.removeLayer(dumLayer);

Did I forget something? I also noticed that if I comment the removeLayer line, the LayerList does not refresh.

I also tried to destroy and recreeate the layer, but I don't undesrstand how to use the WidgetManager createWidget method.

Thanks in advance,

Marco

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Marco,

  Sure get a reference to the LayerList widget and call its _refresh method.

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Marco,

  Sure get a reference to the LayerList widget and call its _refresh method.

sitsit
by
New Contributor III

Hi Robert,

thanks for the help, I didn't know that I could directly call the refresh function.

I noticed that I still have to add and remove the dummy layer for the refresh to take effect, but it's not a big deal.

Thanks again,

Marco

0 Kudos
imritanshu
New Contributor III

How to refresh layerlist in 4.x?

0 Kudos
imritanshu
New Contributor III

for someone who is looking for a solution in 4.x can use below function to recompile layerlist

this.layerListWidget.viewModel._recompileList();
LeonDavis
New Contributor II

Hi imritanshu

Thanks for this, Would you mind sharing how to implement this as a reset button within the layerlist if you have this worked out?

Thanks for the help with this it's really appreciated.

Leon

0 Kudos