How to add Feature Layer created programtically using feature Layer Defination to Search widget in WAB

837
5
03-20-2017 12:46 AM
KumarHarish
New Contributor III

I have created a feature layer given on https://developers.arcgis.com/javascript/3/jssamples/fl_featureCollection.html in custom widget.  I tried to bind the programmatically created Feature layer with ESRI search widget. Here is my code

UpdateSearch:function(){
    var widgets = this.appConfig.getConfigElementsByName('Search');
    
   var searchWidget =this.widgetManager.getWidgetById(widgets[0].id);
   var src =
                           [
                             {
                               featureLayer: featureLayer,
                               name:"myLayer",
                               searchFields: ["ObjectId"],
                               displayField: "Name",
                               exactMatch: false,
                               outFields: ["*"],                               
                               suggestionsEnabled: true,
                               
                           }/*,
                           {
                               locator: new Locator("//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"),
                               singleLineFieldName: "SingleLine",
                               outFields: ["Addr_type"],
                               name: "Adress"
                           }*/
                           ];  //new source
                    searchWidget.sources = src;   
                    searchWidget.addLayersFromMap=true;                    
                    console.log(searchWidget.sources);
                   

   }

The layer doesn't appear in search widget.

Thanks in advance.

Kumar

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Kumar,

   A FeatureLayer coming from a FeatureCollection has this limitation:

  • Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.

So you can not use it with the Search widget.

KumarHarish
New Contributor III

Thanks Robert. 

Any other suggestion to search the feature in  FeatureLayer coming from a FeatureCollection?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kumar,

   I don't know of any way other than to loop through the graphics and check for that attribute value. If the FeatureCollection is coming from a map service initially then you can run the query on map service and get the ObjectID of the result you want and then loop through the FeatureCollection to get that OID.

KumarHarish
New Contributor III

Roberts Thanks.

What I am basically doing is getting data from web service and than creating a feature layer using feature layer definition followed by populated that data as features. This is working fine.

Now I like to add that feature layer in search widget.  I understand from your previous reply that it cannot be queried against the feature collection due to it limitation. 

If I understood correctly, manually created feature layer cannot be added to search widget. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kumar,

   That is correct based on my knowledge.

0 Kudos