Hello, is it possible to search from all of the MapImageLayer sublayers?
Should I use a collection of LayerSearchSource to iterate through all of the sublayers and then add the collection to Search widget's 'sources' property.
const sources = new Collection<LayerSearchSource>();
//Loop through MapImageLayer and add to sources??
const search = new Search({
view: view,
sources: sources,
});
Hi @KristianTuusjärvi, yes, you can use a Sublayer just like a FeatureLayer as a LayerSearchSource.
I would recommend pulling out all the sublayers first, then add them as a LayerSearchSource individually so you can configure the settings like in this sample:
https://developers.arcgis.com/javascript/latest/sample-code/widgets-search-multiplesource/
That sample is unreachable, but are there any updates to the existing sample?
Thanks @KenBuja. I updated the link. No updates to report.
Hi @Noah-Sager
I'm not sure if the sample code has been modified, but there is no sample of a sublayer of a MapImageLayer in above sample code. I'm wondering how do you "pull out all the sublayers first"? Thank you for your answer.
@KristianTuusjärvi Have you managed to include the entire MapImageLayer as a source to Search?
Best,
Nadja
Correct @nadja, the sample I linked to shows how to set-up individual feature layers for use with the LayerSearchSource, like for example the searchFields and the outFields. It wouldn't work with just adding all Sublayers from a MapImageLayer without knowing more about the Sublayers. Does that make sense? So I don't think a programmatic approach would simplify things. I would just add the the Sublayers as individual LayerSearchSources.
Yes, thanks @Noah-Sager, this makes sense. However, I wonder how I would add the Sublayers as individual LayerSearchSource? Let's take the first Sublayer as an example. I tried several approaches to access the first Sublayer:
Yeah, unfortunately you can't load a Sublayer directly, it needs to be a FeatureLayer or one of the other approved layer types in the doc: https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#sources
What you can do is flatten the collection of Sublayers in the MapServer, then create FeatureLayers (and get the relevant LayerSearchSource attributes) out of each Sublayer.
You should be able to also use the Sublayer.createFeatureLayer() method, but I had trouble with the synchronicity of the requests.
After creating the FeatureLayer and the LayerSearchSource attributes, add them to an object, and then add that object to the Search widget sources Collection.
Here is a proof-of-concept app that should help clarify a potential workflow:
https://codepen.io/noash/pen/VwxgQzv?editors=1000
Try searching for a simple word here, like "new" or "yo".
I wonder if I can just add the whole MapImageLayer as a source to Search? It seems to be possible, but I don't understand how to choose the fields when there is multiple sublayers on MapImageLayer.
Here it is mentioned that MapImageLayer can be used. Any ideas?
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LayerSearchSource....
Sorry @KristianTuusjärvi, I just noticed this question. Unfortunately, MapImageLayer is not listed there. Perhaps we could improve the wording to make this more clear. What it means is that a FeatureLayer from a MapServer or a FeatureServer is usable. So if you had a MapServer like this:
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer
You could also just use each Sublayer URL (effectively consuming it as a FeatureLayer) as a source for the Search widget:
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/0
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3