Receive data in the eSearch Results tab from the Search widget.

820
7
Jump to solution
03-28-2018 10:01 AM
MartinOwens1
Occasional Contributor II

I'm publishing data from the Search widget and was wondering if the eSearch can grab those results and populate the Results tab based on one of the config searches I have. I wouldn't need it to create another graphic in this case becasue the Search is already doing that.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Martin,

   What I do on my site is in the Search widget.js I publish the search widgets results like this:

      _onSelectResult: function(e) {
....
        // publish select result to other widgets
        this.publishData({
          'selectResult': e
        });

        //Dispatch event to have eSearch search for this geometry.
        this.publishData({
          'target': 'eSearch',
          'feature': result.feature
        });
      },

Then in the eSearch:

      onReceiveData: function(widgetName, WidgetId, data){
        if(data.message && data.message === "Deactivate_DrawTool"){
          this.drawBox.deactivate();
        }
        if(data && data.target && data.target === 'eSearch'){
          if(data.feature.geometry.type === "polygon"){
            this.search(data.feature.geometry.getCentroid(), 0);
          }else{
            this.search(data.feature.geometry, 0);
          }
        }
      },

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Emeritus

Martin,

   What I do on my site is in the Search widget.js I publish the search widgets results like this:

      _onSelectResult: function(e) {
....
        // publish select result to other widgets
        this.publishData({
          'selectResult': e
        });

        //Dispatch event to have eSearch search for this geometry.
        this.publishData({
          'target': 'eSearch',
          'feature': result.feature
        });
      },

Then in the eSearch:

      onReceiveData: function(widgetName, WidgetId, data){
        if(data.message && data.message === "Deactivate_DrawTool"){
          this.drawBox.deactivate();
        }
        if(data && data.target && data.target === 'eSearch'){
          if(data.feature.geometry.type === "polygon"){
            this.search(data.feature.geometry.getCentroid(), 0);
          }else{
            this.search(data.feature.geometry, 0);
          }
        }
      },
MartinOwens1
Occasional Contributor II

That worked perfect! Thank you!

0 Kudos
MartinOwens1
Occasional Contributor II

I have noticed an issue with the .getCentoid approach if the centoid falls outside of the polygon due to an irregular shape it return reults from the other shape. Is there a way to force it to always be inside the original polygon shape that is seached on?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Martin,

   That is going to be a bit more difficult.

      onReceiveData: function(widgetName, WidgetId, data){
        if(data.message && data.message === "Deactivate_DrawTool"){
          this.drawBox.deactivate();
        }
        if(data && data.target && data.target === 'eSearch'){
          if(data.feature.geometry.type === "polygon"){
            esriConfig.defaults.geometryService.labelPoints([data.feature.geometry], lang.hitch(this, function(labelPoint) {
              this.search(labelPoint, 0);
            });
          }else{
            this.search(data.feature.geometry, 0);
          }
        }
      },
0 Kudos
MartinOwens1
Occasional Contributor II

That seems like it's really close it zooms to the correct extent to select the polygon geometry but the results in the eSeach just say searching with the progress bar and receive this in the console:

TypeError: d.spatialReference is undefine.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

OK try:

      onReceiveData: function(widgetName, WidgetId, data){
        if(data.message && data.message === "Deactivate_DrawTool"){
          this.drawBox.deactivate();
        }
        if(data && data.target && data.target === 'eSearch'){
          if(data.feature.geometry.type === "polygon"){
            esriConfig.defaults.geometryService.labelPoints([data.feature.geometry], lang.hitch(this, function(labelPoint) {
              this.search(labelPoint[0], 0);
            }));
          }else{
            this.search(data.feature.geometry, 0);
          }
        }
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
MartinOwens1
Occasional Contributor II

Worked like a charm. Thanks Robert!

0 Kudos