How can I get the currently selected features from Search Widget to a new widget?

3647
2
05-23-2015 07:03 PM
MikeWottrich
New Contributor II

Hello,

I want to use the features returned from a search in a new widget. How can my new widget access the currently selected features (FYI - features selected using the 'Enhanced Search' widget.

Any and all help would be appreciated.

thanks,

Mike

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Mike,

  If you choose "Add Result as Operational Layer" then you can use some code like this in your other widget:

        var slyr;
        array.some(this.map.graphicsLayerIds, lang.hitch(this, function (layerId) {
          var lyr = this.map.getLayer(layerId);
          if(lyr.name === "Search result: Parcels"){ /*change "Parcels to the name of your layer */
            slyr = lyr;
            return true;
          }
        }));
        if(slyr){
          array.map(slyr.graphics, lang.hitch(this, function(gra, index){
            //do something with the selected graphics
          }));
        }
MikeWottrich
New Contributor II

Thank you Robert.

This was very helpful. I will test this out later today.

Mike

0 Kudos