Make layer visible after LayerList widget has opened

8077
10
Jump to solution
07-09-2015 02:52 PM
RyanStrain
New Contributor III

I have a subLayer, "Parcels_9562_6",  within a group layer that I need to programmatically make visible, after the LayerList has already opened.  Another widget communicates with the LayerList widget during user interaction. I've had no success while fiddling around with the LayerList widget's, Widget.js and LayerListView.js files. Does someone know how this can be accomplished? Thanks.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Well this took some work to figure out. Keep the onRecieveData function in the widget.js and here is what it will look like:

//RJS Add
      onReceiveData: function (name, widgetId, data, historyData) {
        //this makes sure that it is your event that you are reacting to and not another
        if(name === 'eSearch' && data.hasOwnProperty('message')){
          //my layer is called Parcel Data so Parcel Data_0 is the first layer or group
          //these next lines cause the map to set that layer as not visible
          this.operLayerInfos.getLayerInfoById('Parcel Data_0').setTopLayerVisible(false);
          this.operLayerInfos.getLayerInfoById('Parcel Data_83').setTopLayerVisible(false);
          //this causes the layer list widget to redraw and show that the layers are turned off
          this._clearLayers();
          this.showLayers();
        }
      },
//RJS End Add

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   So are you saying that you have already figured out the part of how to make the sublayer visible in the map and that the LayerList widget is just not updating?

0 Kudos
RyanStrain
New Contributor III

No I haven't figured out how to make the sublayer visible in the map yet. It should be easy right?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   So what do you have so far?

Another widget communicates with the LayerList widget during user interaction

You can control sub layer visibility using the ImageParameters class in the JS API:

ImageParameters | API Reference | ArcGIS API for JavaScript

0 Kudos
RyanStrain
New Contributor III

Sorry I just realized it's your widget, the eSearch widget, that I'm communicating to the LayerList widget with. In your code ---

            var myObject = this.getUrlParams();

            if (myObject.esearch) {

                this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum);

                this.publishData({

                    message: myObject.slayer

                });

---communicates to the LayerList.js ---

          onReceiveData: function (name, widgetId, data, historyData) {

               dijit.byId("jimu_dijit_CheckBox_7").setValue(true);

          }

I check a Subdivisions layer checkbox. And also need to make the Subdivisions layer visible, since it is not visible by default.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   Do you mean the LayerListView.js is where you have your onReceiveData function?

0 Kudos
RyanStrain
New Contributor III

I currently have it in LayerList's Widget.js. If it needs to be in the LayerListView.js. I think I could place it there. I'm just struggling to figure out how to make it work.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Well this took some work to figure out. Keep the onRecieveData function in the widget.js and here is what it will look like:

//RJS Add
      onReceiveData: function (name, widgetId, data, historyData) {
        //this makes sure that it is your event that you are reacting to and not another
        if(name === 'eSearch' && data.hasOwnProperty('message')){
          //my layer is called Parcel Data so Parcel Data_0 is the first layer or group
          //these next lines cause the map to set that layer as not visible
          this.operLayerInfos.getLayerInfoById('Parcel Data_0').setTopLayerVisible(false);
          this.operLayerInfos.getLayerInfoById('Parcel Data_83').setTopLayerVisible(false);
          //this causes the layer list widget to redraw and show that the layers are turned off
          this._clearLayers();
          this.showLayers();
        }
      },
//RJS End Add
RyanStrain
New Contributor III

Beauty! Thanks for your work. I owe you a beer next time you're in Boise.

0 Kudos
AlistairFox
Occasional Contributor

Robert,

This is exactly what I need, now just to get it to work. I need to fire this off from when the Edit widget launches. What do I need to add in the Widget.js of the edit widget to get it to work.

0 Kudos