AnsweredAssumed Answered

Legend doesn't update or refresh on new query

Question asked by franklin.alexander on Jun 14, 2017

I have an app that pulls data from a server whenever queried, and based on the query parameters renders the proper symbology on the map layer. For the initial query, the legend updates just fine, however, on subsequent queries the legend does not automatically update. You have to toggle the layer off, then on again to get the Legend widget to update, as well as the legends in the Layer List widget. Has anyone else ran into this, and is there a way to force the legend to refresh every time there is a new query? In the widget.js file, there is a '_bindEvent' function that appears to do this, and I assume that 'refreshLegend' implies redrawing the legend symbols to reflect the new data rendered in the map layer. I still have a lot to learn with javascript, however, and my understanding isn't that good yet.

  

_bindEvent: function() {
   if(this.config.legend.autoUpdate) {
      this.own(on(this._jimuLayerInfos,
            'layerInfosIsShowInMapChanged',
            lang.hitch(this, 'refreshLegend')));

      this.own(on(this._jimuLayerInfos,
            'layerInfosChanged',
            lang.hitch(this, 'refreshLegend')));

      this.own(on(this._jimuLayerInfos,
            'layerInfosRendererChanged',
            lang.hitch(this, 'refreshLegend')));
   }
}

 

IF anyone is interested, I got this sorted out by setting the Query widget to clear the preceding query before running a new query. For some reason, the Legend event handlers only see the info changes when the map is clear and is blind to them whenever the layer info changes from an existing query to a new query.

Outcomes