AnsweredAssumed Answered

Calling map.allLayers removes all layers.

Question asked by tristan.sebens on Oct 5, 2017
Latest reply on Oct 28, 2017 by tristan.sebens

I've run into an interesting quirk in my code and I'm trying to track down the source of it. In my application I have about 40 layers, any combination of which can be displayed at one time as 3d polylines. What I want to do is implement a legend widget by adding all of the layers to a group layer, and then using that group layer as the basis for my legend widget.

 

Here's my function to accomplish that:

 

function createLegend() {
   var legend = new Legend({
      view: view,
      layerInfos: [{
      layer: new GroupLayer({
         layers: map.allLayers;
       }),
       title: "Layer Legend"
    }]
});

// Add widget to the bottom left corner of the view
view.ui.add(legend, "bottom-left");
}

The interesting thing is this: as soon as I call map.allLayers, all of the layers disappear from the map. I have a layer list in the app, and it goes from full to empty instantaneously once the call is made. I even set a time delay on the function call: all of the layers remain in the map until map.allLayers gets called.

 

I put in a console.log( map ) statement before and after map.allLayers gets called, and sure enough the layers are there before the call, and gone after.

 

I'm wondering if anyone else has faced this kind of thing, and what I might do about it.

Outcomes