LayerList Widget : Programatically filter layers?

1389
5
Jump to solution
01-31-2019 11:21 PM
PrashantKirpan
Occasional Contributor

Hi All,

I wanted to filter layers programatically in layer list widget. I developed a custom widget which allows to set layer visibility based on predefined criteria. I am able to manage that using below class.

LayerStructure.getInstance();

..layerNode.Hide()\Show()

After that,I am trying to remove invisible layers from layer-list widget but not sure what is the best way to handle this.

Is it possible to fire filter method programatically(same filter functionality) from other widget ? or remove layer from map?

Any help would be appreciated.

Regards,

Prashant 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Prashant,

  OK, here is what I have tested to work.

      _onBtnTestClicked: function(){
        //this is the critial missing piece
        this.layerFilter.isValid = true;

        //for your first method
        //loop though all the operational layers as set to true
        this.operLayerInfos.traversalAll(lang.hitch(this, function(layerInfo) {
          this.layerFilter.layerInfoIsValidStatus[layerInfo.id] = true;
        }));
        //now exclude the layer(s) you wish to hide
        this.layerFilter.layerInfoIsValidStatus["LOJIC_PublicSafety_Louisville_2161"] = false;
        //Or your second method
        // this.layerFilter._onFilter("Fire");
        //as long as you have line 2 the filter will work
        this.layerListView.refresh();
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Prashant,

   You would need get a reference to the LayerListWidget and then something like:

LayerListWidget.layerListView.layerFilter.layerInfoIsValidStatus[yourLayerInfo.id] = false;‍‍

This is basically what the LayerList widgets filter does, except it does the opposite and sets the value to true for the layers whose title matches whats typed in the filter box.

Oh of course you need to call refresh on the widget.

LayerListWidget._refresh();
0 Kudos
PrashantKirpan
Occasional Contributor

Hi Robert,

Thanks for reply,as you suggested I have tried to filter layers but doesn't update list,

1) To verify, i have added one button on layerlist view widget and execute below code on click event but UI is not updating.No error in code execution. 

_onBtnTestClicked: function () {

this.layerListView.layerFilter.layerInfoIsValidStatus["LayerId"] = true/false;
this._refresh();
},

2) Additionally,i called existing filter method on button click event but still no changes on UI. Code executed successfully.  

_onBtnTestClicked: function () {

this.layerFilter._onFilter("Filter criteria");
},

Do i need to call any function/event explicitly to update ui?

Any help would be appreciated.

Regards,

Prashant

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Prashant,

  OK, here is what I have tested to work.

      _onBtnTestClicked: function(){
        //this is the critial missing piece
        this.layerFilter.isValid = true;

        //for your first method
        //loop though all the operational layers as set to true
        this.operLayerInfos.traversalAll(lang.hitch(this, function(layerInfo) {
          this.layerFilter.layerInfoIsValidStatus[layerInfo.id] = true;
        }));
        //now exclude the layer(s) you wish to hide
        this.layerFilter.layerInfoIsValidStatus["LOJIC_PublicSafety_Louisville_2161"] = false;
        //Or your second method
        // this.layerFilter._onFilter("Fire");
        //as long as you have line 2 the filter will work
        this.layerListView.refresh();
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
PrashantKirpan
Occasional Contributor

Thank you so much Robert for your help. It's working fine. I am using widget communication to publish corresponding filter data. Receiving it in layer list widget and applying above code to filter and update UI.

Thanks again  

Cheers Prashant.

0 Kudos
keerthiappasani
New Contributor

Hi All,

I am creating custom widget for layerlist. In that widget created layers by using layerlist function. at the bottom of the widget i want to filter layers by using a textbox. 

Any help would be appreciated.

Thanks,

keerthi.

0 Kudos