Search widget on existing map layers?

828
7
Jump to solution
05-04-2018 01:06 AM
Shane_
by
New Contributor II

Using v4.7 of the JavaScript API:

I add two feature layers to a map (sourced on .json data files). The layers show up fine, with the data expected, and selectable/deselectable using the LayersList widget.

When I try to setup the Search widget, both layers appear in the select dropdown list ok, but when I enter some text to search I don't get any hits and the auto-suggestions are also not appearing. I think that map.layers[0] and map.layers[1] are not referencing the actual layers (I also tried map.layers[8] and map.layers[9] - which don't exist - and got no errors).

When I look at the JavaScript console, and run a

console.log("Results of the search: ", event)

I see in Results / Source: featureLayer: undefined

but 

searchFields: ["name"] so (some of) the parameters sent below are getting through.

The fieldname to search in is "name". Any help to resolve this would be appreciated. Here's the code:

 

var searchSources =[
{ featureLayer: map.layers[0], searchFields: ["name"], displayField: "name", exactMatch: false, outFields: ["*"], name: "A search", placeholder: "A search", maxResults: 6, maxSuggestions: 6, suggestionsEnabled: true, minSuggestCharacters: 0 },
{ featureLayer: map.layers[1], searchFields: ["name"], displayField: "name", exactMatch: false, outFields: ["*"], name: "B search", placeholder: "B search", maxResults: 6, maxSuggestions: 6, suggestionsEnabled: true, minSuggestCharacters: 0 }];
var search = new Search({ map: map, allPlaceholder: "Search A and B", sources: searchSources });
view.ui.add(search, {position: "top-right", });

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

The search widgets suggest and query functionality depends on the layer coming from ArcGIS Server or AGOL, so that is the issue.

Suggestions require the FL to support paginiation which a FL from graphics does not.

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

S C,

  So when you say: 

I add two feature layers to a map (sourced on .json data files)

You mean they are not coming from AGOL or an ArcGIS Server? Are you meaning they com from an array of client side graphics?

0 Kudos
Shane_
by
New Contributor II

Yes, they're from array of client side graphics

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

The search widgets suggest and query functionality depends on the layer coming from ArcGIS Server or AGOL, so that is the issue.

Suggestions require the FL to support paginiation which a FL from graphics does not.

0 Kudos
Shane_
by
New Contributor II

Thanks. But leaving suggestions aside, could the query at least return results from an FL from graphics?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Not that I am aware of. The layer needs to be from ArcGIS Server or AGOL.

0 Kudos
Shane_
by
New Contributor II

Understood. Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos