Query and search from onReceiveData with eSearch

760
8
Jump to solution
05-10-2019 05:06 AM
MartinOwens1
Occasional Contributor II

I'm attempting to automatically perform a query and search based on a string that is getting passed to the eSearch widget. Their is only 1 config search layer expression available to match the search data that is getting received. I'm receiving the data string fine, just need some help populating the dijit and running the query search. Any help would be great!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Sure in your onRecieveData function set 

this.openPopupAfterSearch = true;

And make this modification to the _drawResults function (add lines 73 - 79):

      _drawResults: function (layerIndex, results, currentLayer, closeOnComplete) {
        var layerConfig = this.config.layers[layerIndex];
        if (this.graphicsLayerBuffer instanceof FeatureLayer) {
          this._addOperationalLayer(this.graphicsLayerBuffer);
        }
        if (currentLayer instanceof FeatureLayer) {
          this._addOperationalLayer(currentLayer);
        }

        var type, centerpoint;
        for (var i = 0, len = this.currentFeatures.length; i < len; i++) {
          var feature = this.currentFeatures[i];
          var listItem = this.list.items[this._returnListIndexFromOID(feature.attributes[layerConfig.objectIdField])];
          if(feature.geometry){
            type = feature.geometry.type;
          }else{
            type = "table"
          }

          switch (type) {
          case "multipoint":
          case "point":
            centerpoint = feature.geometry;
            break;
          case "polyline":
            centerpoint = feature.geometry.getPoint(0, 0);
            break;
          case "extent":
          case "polygon":
            centerpoint = feature.geometry.getExtent().getCenter();
            break;
          default:
            break;
          }
          listItem.centerpoint = centerpoint;
          var lyrDisablePopupsAndTrue = (layerConfig.hasOwnProperty("disablePopups") && layerConfig.disablePopups)?true:false;
          if((!this.config.disablePopups && !lyrDisablePopupsAndTrue) && !currentLayer._hasInfoTemplate){
            feature.setInfoTemplate(this._configurePopupTemplate(listItem));
          }
          feature.setSymbol(listItem.sym);
          if (feature.geometry) {
            currentLayer.add(feature);
            listItem.graphic = feature;
          }
        }
        this.zoomAttempt = 0;
        if (layerConfig.shareResult && layerConfig.addToAttrib) {
          if(this.attWidget){
            this.attTableOpenedbySearch = !this.attWidget.showing;
            this.wManager.openWidget(this.attWidget);
            this.attWidget._openTable().then(lang.hitch(this, this._openResultInAttributeTable, currentLayer));
          }
          if (closeOnComplete) {
            setTimeout(lang.hitch(this, function () {
              this.pManager.closePanel(this.id + '_panel');
            }), 500);
          }
        } else {
          this._zoomAndClose(closeOnComplete);
        }

        if (this.mouseovergraphics) {
          on(currentLayer, 'mouse-over', lang.hitch(this, this.onMouseOverGraphic));
        }
        try{
          this.updateDataSourceData(layerIndex, {
            features: currentLayer.graphics
          });
        }catch(e){
          console.error(e);
        }
        this.currentLayerAdded = currentLayer;
        if(this.openPopupAfterSearch){
          setTimeout(lang.hitch(this, function () {
            var layerConfig = this.config.layers[this.currentLayerIndex];
            var oidField = layerConfig.objectIdField;
            this._searchResultListByOID(this.currentLayerAdded.graphics[0].attributes[oidField]);
          }), 500);
        }
      },

View solution in original post

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus

Martin,

   The best route is to call the _queryFromURL function from your onRecieveData function

0 Kudos
MartinOwens1
Occasional Contributor II

Thanks for the reply Robert. I've set the onReceive to call the _queryFromURL function and it's working to select the parcel by the passed attribute. The issue is, I was hoping it would send the web map pop up to your custom popup panel widget, but it's not. It's working correctly when I select by graphic just not when I pass it the query params. Is there something in the PopUp Panel js to display content if a feature is selected in the eSearch?  I wrote some things to the console to troubleshoot. In the eSearch _zoomAndClose function it displays the currentFeature (perfect) in the Popup panel widget under displayPopupContent function it doesn't see any content until I click to select a parcel.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

???. So when you use the eSearch it normally does not show the popup for the results until you click on one of the results in the results list. So am I understanding you to say you want the popup panel to display the result of your search automatically?

0 Kudos
MartinOwens1
Occasional Contributor II

Yeah would that be possible? Once the query is complete and the search result layer is created to display the popup in the popup panel.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sure in your onRecieveData function set 

this.openPopupAfterSearch = true;

And make this modification to the _drawResults function (add lines 73 - 79):

      _drawResults: function (layerIndex, results, currentLayer, closeOnComplete) {
        var layerConfig = this.config.layers[layerIndex];
        if (this.graphicsLayerBuffer instanceof FeatureLayer) {
          this._addOperationalLayer(this.graphicsLayerBuffer);
        }
        if (currentLayer instanceof FeatureLayer) {
          this._addOperationalLayer(currentLayer);
        }

        var type, centerpoint;
        for (var i = 0, len = this.currentFeatures.length; i < len; i++) {
          var feature = this.currentFeatures[i];
          var listItem = this.list.items[this._returnListIndexFromOID(feature.attributes[layerConfig.objectIdField])];
          if(feature.geometry){
            type = feature.geometry.type;
          }else{
            type = "table"
          }

          switch (type) {
          case "multipoint":
          case "point":
            centerpoint = feature.geometry;
            break;
          case "polyline":
            centerpoint = feature.geometry.getPoint(0, 0);
            break;
          case "extent":
          case "polygon":
            centerpoint = feature.geometry.getExtent().getCenter();
            break;
          default:
            break;
          }
          listItem.centerpoint = centerpoint;
          var lyrDisablePopupsAndTrue = (layerConfig.hasOwnProperty("disablePopups") && layerConfig.disablePopups)?true:false;
          if((!this.config.disablePopups && !lyrDisablePopupsAndTrue) && !currentLayer._hasInfoTemplate){
            feature.setInfoTemplate(this._configurePopupTemplate(listItem));
          }
          feature.setSymbol(listItem.sym);
          if (feature.geometry) {
            currentLayer.add(feature);
            listItem.graphic = feature;
          }
        }
        this.zoomAttempt = 0;
        if (layerConfig.shareResult && layerConfig.addToAttrib) {
          if(this.attWidget){
            this.attTableOpenedbySearch = !this.attWidget.showing;
            this.wManager.openWidget(this.attWidget);
            this.attWidget._openTable().then(lang.hitch(this, this._openResultInAttributeTable, currentLayer));
          }
          if (closeOnComplete) {
            setTimeout(lang.hitch(this, function () {
              this.pManager.closePanel(this.id + '_panel');
            }), 500);
          }
        } else {
          this._zoomAndClose(closeOnComplete);
        }

        if (this.mouseovergraphics) {
          on(currentLayer, 'mouse-over', lang.hitch(this, this.onMouseOverGraphic));
        }
        try{
          this.updateDataSourceData(layerIndex, {
            features: currentLayer.graphics
          });
        }catch(e){
          console.error(e);
        }
        this.currentLayerAdded = currentLayer;
        if(this.openPopupAfterSearch){
          setTimeout(lang.hitch(this, function () {
            var layerConfig = this.config.layers[this.currentLayerIndex];
            var oidField = layerConfig.objectIdField;
            this._searchResultListByOID(this.currentLayerAdded.graphics[0].attributes[oidField]);
          }), 500);
        }
      },
0 Kudos
MartinOwens1
Occasional Contributor II

That is passing the value but seems to inherit the eSearch popup fields and not the web map even though it's configured to use popup from web map. Side note the only reason i'm using the web map for the popup is because there are some custom arcade expressions I've created on the data.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Martin,

  So when you click on the results in the eSearch list does it show the desired popup?

0 Kudos
MartinOwens1
Occasional Contributor II

I figured out my issue i'm an idiot. The current web map layer with the popup was added to the map through https and the eSearch config layer I added to search was through http on accident. It couldn't see the layer in the map. Thanks Robert for all of your help! It's working great!

0 Kudos