How to remove a layer from the Legend widget in Developer Addition Web App Builder? We are programmatically adding a Grid layer to the map using JavaScript API, not the Web Map, and would like to hide the layer from the Legend Widget when we add this lay

902
6
Jump to solution
10-25-2017 10:37 AM
Highlighted
New Contributor III

How to remove a layer from the Legend widget in Developer Addition Web App Builder? We are programmatically adding a Grid layer to the map using JavaScript API, not the Web Map, and would like to hide the layer from the Legend Widget when we add this layer to the map.

This is how we add the layer to the map in the application:

var grid = new ArcGISDynamicMapServiceLayer("<mapserver>", {
          "opacity" : 1.0,
          "imageParameters" : imageParameters
        });
        
        this.map.addLayer(grid);
        grid.setVisibility(false);

Upon clicking a checkbox, the layer is set to visible = true.  We would like for this layer not to be added to the Legend widget as it is a simple 1 x 1 grid of the globe. 

Thank you for your time.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor

In the Legend Widget.js make these changes (lines 23 - 32, of corse changing Highway - ABIMS Bridges to your layers name as it appears in the legend):

    _getLayerInfosParam: function() {
      var layerInfosParam;
      /*
      this.config.legend.layerInfos = [{
        id: "NapervilleShelters_8858",
        hideLayers: []
      }, {
        id: "Wildfire_6998",
        hideLayers: []
      }, {
        id: "911CallsHotspot_3066",
        hideLayers: [0, 1]
      }];
      */


      if(this.config.legend.layerInfos === undefined) {
        // widget has not been configed.
        layerInfosParam = legendUtils.getLayerInfosParam();
      } else {
        // widget has been configed, respect config.
        layerInfosParam = legendUtils.getLayerInfosParamByConfig(this.config.legend);
      }
      filteredLayerInfosParam = layerInfosParam.filter(function(layerInfoParam) {
        if(layerInfoParam.title !== "Highway - ABIMS Bridges"){
          return layerInfoParam;
        }
      });
      return filteredLayerInfosParam;

      // filter layerInfosParam
      //return this._filterLayerInfsParam(layerInfosParam);
      //return layerInfosParam;
    },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

6 Replies
Highlighted
MVP Esteemed Contributor

In the Legend Widget.js make these changes (lines 23 - 32, of corse changing Highway - ABIMS Bridges to your layers name as it appears in the legend):

    _getLayerInfosParam: function() {
      var layerInfosParam;
      /*
      this.config.legend.layerInfos = [{
        id: "NapervilleShelters_8858",
        hideLayers: []
      }, {
        id: "Wildfire_6998",
        hideLayers: []
      }, {
        id: "911CallsHotspot_3066",
        hideLayers: [0, 1]
      }];
      */


      if(this.config.legend.layerInfos === undefined) {
        // widget has not been configed.
        layerInfosParam = legendUtils.getLayerInfosParam();
      } else {
        // widget has been configed, respect config.
        layerInfosParam = legendUtils.getLayerInfosParamByConfig(this.config.legend);
      }
      filteredLayerInfosParam = layerInfosParam.filter(function(layerInfoParam) {
        if(layerInfoParam.title !== "Highway - ABIMS Bridges"){
          return layerInfoParam;
        }
      });
      return filteredLayerInfosParam;

      // filter layerInfosParam
      //return this._filterLayerInfsParam(layerInfosParam);
      //return layerInfosParam;
    },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

Highlighted
New Contributor III

Thanks Robert that worked like a charm.  You are the man.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Great,  Don't forget to mark this question as answered then.

Highlighted
New Contributor III

Done

Reply
0 Kudos
Highlighted
Occasional Contributor

hi Robert is it also possible to hide only a sub-layers in a ArcGISDynaicMapserviceLayer ? It seems the layerInfoParam object returns,

{hideLayers: Array[0], layer: Object {...}, title: "Bird_Area"}

but the script to hide the sublayers seems not to work.

layerInfoParam.hideLayers[0];

thanks,

Reply
0 Kudos
Highlighted
Occasional Contributor

Got it working for the sub layers. here is the working code for anybody looking to hide a specific layer in a dynamic services

if(layerInfoParam.title === "Drinking_Water"){           
//WORNG WAY TO ACCESS THE LAYRS THIS WAS MY MISTAKE          
//layerInfoParam.hideLayers[1];           
//THE RIGHT WAY TO ACCESS THE SUBLAYERS IN DynamicMapService          
layerInfoParam.hideLayers=[0,1];                     
// return layerInfoParam.layer.layerInfos[0];       
return layerInfoParam;                   
}‍‍‍‍‍‍‍‍‍‍‍

Thanks again Robert for all the hard work.