Help and Suggestion

344
1
08-28-2019 07:23 AM
S_MMaruf
New Contributor II

Hello guys,

I am trying fetch sublayer from WmsLayer for visible and invisible those layers . but problem is when i am using  this code "this.layer.getSublayers().get(0).setVisible(this.visible);"  and run the code I am getting bound exception "Index 0 out of bounds for length 0". and i am debugging this code i get the value of sublayer list as Null. can anybody help how to i am able to get sublayer from Wmslayer? what is the wrong in my code?

0 Kudos
1 Reply
AlanLucas
Esri Contributor

Hi,

Try loading the WmsLayer before calling getSublayers(), for example:

WmsLayer wmsLayer = new WmsLayer(url, layerNames);
assertEquals(0, wmsLayer.getSublayers().size());
wmsLayer.loadAsync();

mWmsLayer.addDoneLoadingListener(() -> {
  if (wmsLayer.getLoadStatus() == LoadStatus.LOADED) {
    assertTrue(wmsLayer.getSublayers().size() > 0);

  }
});

0 Kudos