Customize Add Data to only add to a designated Layer List

1132
5
Jump to solution
10-26-2018 10:52 AM
ScottMaginity1
New Contributor II

I am working on an app that has multiple layer lists. I need to configure the Add Data widget to only add the added layers to a specific layer list instead of all of them. I've tried variations on Hide a layer in the layer list and https://community.esri.com/thread/126201?commentID=472049#comment-472049 as work arounds. I think part of the problem is that they aren't in the Layer List to begin with and everything I have tried didn't seem to apply to new layers. Any help would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Scott,

  I finally made some time to look into this. The solution is quite simple if this workflow works for you.

You define what LayerList widget you do not want ANY add dataLayer to be added to in the code.

In the LayerList Widget LayerListView.js drawListNode function add these lines (lines 6-8):

    drawListNode: function(layerInfo, level, toTableNode, position) {
      var nodeAndSubNode, showLegendDiv;
      if(this.isLayerHiddenInWidget(layerInfo)) {
        return;
      }
      if(layerInfo.layerObject._wabProperties.excludeLyrList === this.layerListWidget.id){
        return;
      }
...

In the AddData widgets search/LayerLoader.js _addLayer function (add line 24):

      _addLayer: function(layer) {
        //console.warn("_addLayer",layer);
        //console.warn("map",this.map);
        var item = this.item;
        if (layer) {
          layer.xtnItemId = item.id;
          layer.xtnAddData = true;
          if (!layer.arcgisProps && item) {
            layer.arcgisProps = {
              title: item.title
            };
            layer._titleForLegend = item.title;
          }
          if (!esriLang.isDefined(layer.title)) {
            layer.title = item.title;
          }

          layer._wabProperties =  {
            itemLayerInfo: {
              itemId: item.id,
              itemUrl: this.itemUrl,
              portalUrl: item.portalUrl
            },
            excludeLyrList: "widgets_LayerList_Widget_20"
          };

          this.map.addLayer(layer);
        }
      },

You can get the layerlist id from the main config.json for your app.

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Scott,

  That is a difficult task. As you know the addData widget adds the layer to the map and the LayerList widget just listens for map layer changes based on the LayerInfos classes. So so would to get a reference to the layerlist you wanted to remove the layer from and using the second link you posted above add the layers id to the widgets config.hide array.

0 Kudos
ScottMaginity1
New Contributor II

Hi Robert,

I tried following the steps in the second thread I posted above just to see if I could exclude layers that way in the layer list but it didn't work. I am using WAB 2.9 and that thread is for 2.5 so I believe there must have been changes since then to the layerlist. I know that excluding layers from the layerlist is a built in functionality now for layers that are initially in the map but I need to be able to hide layers that are coming from the add data widget. I know the specific layers that will be available in the add data widget if that helps. I just need a way to limit where they show up once they are added to the map.

I should also note that I am very much a novice when it comes to altering widgets etc so I really appreciate the guidance.

0 Kudos
by Anonymous User
Not applicable

that would be nice for us as well.

For my emergency operations viewer I have 12 layer lists, one for each ESF.  They all have different layers. I hide all layers for each, so that each one has ONLY the layers that they need to see (i.e. Planning, Logistics, Fire, each have their own sets of layers, with some overlapping).   If they use Add Data, it adds to all of them.  So, this would be nice.

RobertScheitlin__GISP
MVP Emeritus

Scott,

  I finally made some time to look into this. The solution is quite simple if this workflow works for you.

You define what LayerList widget you do not want ANY add dataLayer to be added to in the code.

In the LayerList Widget LayerListView.js drawListNode function add these lines (lines 6-8):

    drawListNode: function(layerInfo, level, toTableNode, position) {
      var nodeAndSubNode, showLegendDiv;
      if(this.isLayerHiddenInWidget(layerInfo)) {
        return;
      }
      if(layerInfo.layerObject._wabProperties.excludeLyrList === this.layerListWidget.id){
        return;
      }
...

In the AddData widgets search/LayerLoader.js _addLayer function (add line 24):

      _addLayer: function(layer) {
        //console.warn("_addLayer",layer);
        //console.warn("map",this.map);
        var item = this.item;
        if (layer) {
          layer.xtnItemId = item.id;
          layer.xtnAddData = true;
          if (!layer.arcgisProps && item) {
            layer.arcgisProps = {
              title: item.title
            };
            layer._titleForLegend = item.title;
          }
          if (!esriLang.isDefined(layer.title)) {
            layer.title = item.title;
          }

          layer._wabProperties =  {
            itemLayerInfo: {
              itemId: item.id,
              itemUrl: this.itemUrl,
              portalUrl: item.portalUrl
            },
            excludeLyrList: "widgets_LayerList_Widget_20"
          };

          this.map.addLayer(layer);
        }
      },

You can get the layerlist id from the main config.json for your app.

0 Kudos
ScottMaginity1
New Contributor II

Thanks Robert! Your solution worked exactly as I needed it to.

0 Kudos