add a button click event in _showResult()

2020
4
Jump to solution
05-23-2016 10:50 AM
Alexwang
Occasional Contributor II

HI, very confused about this dojo API and widget stuff. I want to add a button click event in the QueryTask _showResults() function so zooming to a feature is triggered ONLY when a button gets clicked. The following codes automatically trigger the button click event after the query finishes which is not what i want. Please help!

_query: function(){

   var query = new Query();

   query.where = "1=1";

  query.outFields = ["ID", "Name"];

   query.returnGeometry = true;

   var queryTask = new QueryTask("http://......");

   queryTask.execute(query, lang.hitch(this, this._showResults));

},

_showResults: function(featureSet){

        this.own(on(this.btnZoomTo, "click", lang.hitch(this, this.map.centerAndZoom(featureSet.features[0].geometry, 10))));

},

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

  The issue is that you are not assigning a function to the click, you were just assigning code:

_showResults: function(featureSet){
    this.own(on(this.btnZoomTo, "click", lang.hitch(this, function{
        this.map.centerAndZoom(featureSet.features[0].geometry, 10)
    })));
},

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

  The issue is that you are not assigning a function to the click, you were just assigning code:

_showResults: function(featureSet){
    this.own(on(this.btnZoomTo, "click", lang.hitch(this, function{
        this.map.centerAndZoom(featureSet.features[0].geometry, 10)
    })));
},
Alexwang
Occasional Contributor II

Thanks Robert. so if understood it correctly, my way will fire this.map.centerAndZoom() automatically without clicking while your version assigns a function to the click event and fire only when user clicks the button, correct? Thanks so much for your help!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

That is correct.

0 Kudos
Alexwang
Occasional Contributor II

this is my first WAB and widget project. lots of stuff to learn. thanks so much for your help. you made my life easier! t

0 Kudos