AnsweredAssumed Answered

LayerInfos events

Question asked by Alfonso_CLUS on Jan 17, 2018
Latest reply on Jan 18, 2018 by Alfonso_CLUS

Hello,

I'm trying to update the layers available for a custom widget. The layers needed are those in the layerList checked and I would like to update the information every  time the user check or uncheck a layer. I tried to use the LayerInfosObject and catch the layerInfosIsVisibleChanged or the layerInfosIsShowInMapChanged events, however I've observed a very weir behavior.

 

I have to types of layers, those are in the webmap and those uploaded with the Add Data widget. For the layers included in the webmap it's fine, when I check or uncheck the layer an event is trigger.  The problem raise with the other layers where the number of events depends on the order when the layer was uploaded.

 

For example, the Webmap has two layers (A and B) and I added an three extra layers (C, D and E, in that order). When I update the visibility in the LayerList for the layer A or B, I can observe only one event. The same occurs with the layer C which was the first loaded. For the layer D, two events are triggered and three for the layer E.

 

Here is the code I use to test the event:

 

    startup: function() {
      this.inherited(arguments);
      console.log('Demo::startup');

      this.counter = 0;
      LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function(layerInfosObject){
        this.layerInfosObject = layerInfosObject;
        layerInfosObject.getLayerInfoArray().forEach(function(layerInfo) {
            console.log(layerInfo.title, layerInfo.id);
        });
        this.own(on(this.layerInfosObject, 'layerInfosIsVisibleChanged',
          lang.hitch(this, function(){
              this.counter += 1;
              console.log(this.counter);
          })));
      }));
    },

 

Is that normal?

 

Thank you,

Alfonso

Outcomes