Select to view content in your preferred language

Filtering a webmap layer within a web appbuilder application on startup

6118
24
Jump to solution
05-24-2017 01:03 AM
SvivaManager
Frequent Contributor

Hello,

Is there any way for me to filter a layer on startup of an application?

My current solution was to publish the same layer twice in a web map service. One layer shows all records. The other one is filtered by date.

I want to have only one layer published and when the user starts the appilcation, filter it by date and let him do as he pleased.

Is there a way to configure a widget with a certain filter to kick-in on startup?

Regards,

Shay.

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Shay,

  OK after re-examining your requirement the best solution seems to be set your filter widget to open at start and then add lines 38-40 to your Filter Widgets postCreate function:

      postCreate: function(){
        this.inherited(arguments);
        this._store = {};
        this.layerInfosObj = LayerInfos.getInstanceSync();
        this.filterUtils = new FilterUtils();
        this.filterManager = FilterManager.getInstance();

        var filters = this.config.filters;
        array.forEach(filters, function(filterObj, idx) {
          var isAskForValue = this.filterUtils.isAskForValues(filterObj.filter);

          var parse = {
            icon: filterObj.icon ? jimuUtils.processUrlInWidgetConfig(filterObj.icon, this.folderUrl) :
              this.folderUrl + '/css/images/default_task_icon.png',
            index: idx,
            title: filterObj.name,
            toggleTip: this.nls.toggleTip,
            hasValue: isAskForValue ?
              (window.appInfo.isRunInMobile ? 'block !important' : '') : 'none',
            isAskForValue: isAskForValue,
            apply: lang.getObject('jimuNls.common.apply', false, window) || 'Apply'
          };

          if (!this._store[filterObj.layerId]) {
            this._store[filterObj.layerId] = {
              mapFilterControls: {}
              // filter_item_idx
            }; // filter_item_idx, mapFilterControls
          }

          var template = lang.replace(this._itemTemplate, parse, /\$\{([^\}]+)\}/ig);
          var node = html.toDom(template);
          html.place(node, this.filterList);
          this.own(
            query('.header', node)
            .on('click', lang.hitch(this, 'enableFilter', node, filterObj, parse))
          );
          if(filterObj.name === 'ParksFinder'){
            query('.header', node)[0].click();
          }

Where 'ParksFinder' is the name of your filter in the widget you want applied on startup.

View solution in original post

24 Replies
RobertScheitlin__GISP
MVP Emeritus

Shay,

   The simplest answer is to use the Filter widget and set the widget to open at startup.

0 Kudos
SvivaManager
Frequent Contributor

Hi Robert,

Thank you, but from what I know, when the widget starts with the application, it does not commit a filter on the layer, it just shows the widget screen.. 

Do you know on a way to choose a custom fiter to run when it opens up? (only on startup and not each time the user clicks the widget).

Shay.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ok, then you will want to filter your layer in you web map in AGOL then.

0 Kudos
SvivaManager
Frequent Contributor

But then it's permanent and the user cannot change it  also, there is no option to filter it with formulas like in arcmap to use the current date as a parameter.

Shay.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Shay,

  So what you are wanting is not available OTB then and would call for customization.

Here is a thread on this subject:https://community.esri.com/thread/181799-run-filter-in-background-executing-programmatically-an-expe... 

0 Kudos
SvivaManager
Frequent Contributor

Thank you Robert! It looks promising but the FilterManager does not have a method called applyWidgetFilter.. I tried it on the app's code in the jmu.js folder

Shay.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Shay,

   I am not sure which version of WAB you are using then as 2.4 FilterManager absolutely has a applyWidgetFilter method.

0 Kudos
SvivaManager
Frequent Contributor

Version 2.2. I'll try to upgrade and see if it changes anything.

0 Kudos
SvivaManager
Frequent Contributor

I am probably missing here something.. It doesn't work because once this command runs -

FilterManager.getInstance();

The result is undefined.. there is no instance.. I tried to define a filter for this layer in the filter widget + a filter in the webmap itself but the instance stays undefined.

Do you happen to know what exactly this code is trying to initialize?

Shay.

0 Kudos