How to remove default symbol and default label from legend widget (WAB dev ed 2.7)

580
2
Jump to solution
02-07-2018 10:00 AM
by Anonymous User
Not applicable

I have a geoprocessing widget that consumes a geoprocessing service which has several feature class output parameters. One of the output feature classes is symbolized with unique values in the configuration of the geoprocessing widget.  The widget configuration does not have an option to remove the default symbol or default label so the Legend widget shows a symbol and label ("others") that I do not want since all my unique values are accounted for.

I'm sure there are multiple ways to remove this in code but I really just need a quick hack for this particular app and the code in \WebAppBuilderForArcGIS\server\apps\2\jimu.js\LayerInfos\LayerInfoForDefault.js looked promising but so far no luck with the changes I've tried there. Can someone point me towards the code where the default symbol and default label in the legend are generated?  I can essentially hide the symbol by making it tiny but can't get rid of the default label "others". I've looked at the code for both the geoprocessing and legend widgets and don't see an easy solution there.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Karin,

   I think your best bet is to do something like this in the Legend Widget.js.

    _getLayerInfosParam: function() {
      var layerInfosParam;

      /*
      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);
      }
      */

      layerInfosParam = legendUtils.getLayerInfosParam(this.config);
      arrayUtils.some(layerInfosParam, function(obj){
//replace the title with your layers title
        if(obj.title === 'Search Results: Crimes'){
          obj.layer.renderer.defaultSymbol = null;
          obj.layer.renderer.defaultLabel = '';
        }
        return false;
      });

      return layerInfosParam;
    },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Karin,

   I think your best bet is to do something like this in the Legend Widget.js.

    _getLayerInfosParam: function() {
      var layerInfosParam;

      /*
      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);
      }
      */

      layerInfosParam = legendUtils.getLayerInfosParam(this.config);
      arrayUtils.some(layerInfosParam, function(obj){
//replace the title with your layers title
        if(obj.title === 'Search Results: Crimes'){
          obj.layer.renderer.defaultSymbol = null;
          obj.layer.renderer.defaultLabel = '';
        }
        return false;
      });

      return layerInfosParam;
    },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
by Anonymous User
Not applicable

Robert,

Thanks so much!  Adding that code worked perfectly, the quick fix I was looking for.

0 Kudos