Select to view content in your preferred language

query widget customization turn operational layers off when running a query

1386
2
Jump to solution
12-28-2017 04:02 PM
Anish_Adhikari
Frequent Contributor

I just configured the query widget for my application and it works well for the most part. However it would be great if when I run the query, my existing operational layers would automatically be disabled with query results layer as only visible layer.  Similarly I want the operational layer to be re-enabled when I click on remove the result link or close the widget. 

I tried looking into query widgets code but not sure where the click events are buried.

Has anyone got any ideas about this?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Anish,

   Here are the changes to the Query Widget.js (all additional code is added to the begging of each function indicated):

      postCreate:function(){
        this.mapObj = {
          layers: {}
        };
...

      onClose:function(){
        //Use this to restore the layers visiblity state
        var layerOptions = this.mapObj.layers;
        this.layerInfosObj.restoreState({
          layerOptions: layerOptions || null
        });
...

      //start to query
      _onBtnApplyClicked:function(currentAttrs){
        if (this.layerInfosObj && this.layerInfosObj.traversal) {
          this.layerInfosObj.traversal(lang.hitch(this, function(layerInfo) {
            this.mapObj.layers[layerInfo.id] = {
              visible: layerInfo.isVisible()
            };
        //Now turn then off
            if(layerInfo.isVisible()){
              layerInfo.setTopLayerVisible(false);
            }
          }));
        }
...

      removeSingleQueryResult: function(singleQueryResult){
        //Use this to restore the layers visiblity state
        var layerOptions = this.mapObj.layers;
        this.layerInfosObj.restoreState({
          layerOptions: layerOptions || null
        });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
...

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Anish,

   Here are the changes to the Query Widget.js (all additional code is added to the begging of each function indicated):

      postCreate:function(){
        this.mapObj = {
          layers: {}
        };
...

      onClose:function(){
        //Use this to restore the layers visiblity state
        var layerOptions = this.mapObj.layers;
        this.layerInfosObj.restoreState({
          layerOptions: layerOptions || null
        });
...

      //start to query
      _onBtnApplyClicked:function(currentAttrs){
        if (this.layerInfosObj && this.layerInfosObj.traversal) {
          this.layerInfosObj.traversal(lang.hitch(this, function(layerInfo) {
            this.mapObj.layers[layerInfo.id] = {
              visible: layerInfo.isVisible()
            };
        //Now turn then off
            if(layerInfo.isVisible()){
              layerInfo.setTopLayerVisible(false);
            }
          }));
        }
...

      removeSingleQueryResult: function(singleQueryResult){
        //Use this to restore the layers visiblity state
        var layerOptions = this.mapObj.layers;
        this.layerInfosObj.restoreState({
          layerOptions: layerOptions || null
        });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
...
Anish_Adhikari
Frequent Contributor

Thanks Robert. I really appreciate it. 

0 Kudos