Using the core Search widget I can use a function with searchViewModel.includeDefaultSources to replace just the default ArcGIS World Geocoding Service with another geocoding instance or remove this geocoder from the Search widgets sources.
E.g.
search.viewModel.includeDefaultSources = function(sourcesResponse) {
searchSources = sourcesResponse.defaultSources;
searchSources.pop();
searchSources.push({
name: "Place or Location",
placeholder: "Place or Location",
apiKey: apiKey,
singleLineFieldName: "SingleLine",
url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer",
categories: ["Populated Place", "Education", "Land Features", "Parks and Outdoors", "Water Features"],
countryCode: "NZL",
filter: searchExtent,
localSearchDisabled: true,
zoomScale: 4513.988705
});
return sourcesResponse.defaultSources;
};
This has been super useful in my map applications that use webmaps with configured search layers as it means I don't have to set the search sources in the application.
Now using the arcgis-search component I've not been able to reliably do the same thing. I've had some success with modifying a copy of the defaultSources and using this to set the sources. But it's a little hit and miss, sometimes it works on initial load other times it doesn't, perhaps because of timing.
E.g.
search.componentOnReady().then(() => {
reactiveUtils.when(
() => search.defaultSources.length > 1,
() => {
const searchSources = search.defaultSources.toArray();
searchSources.pop();
searchSources.push(locatorSearch);
search.includeDefaultSourcesDisabled = true;
search.sources = searchSources;
}
);
});
Or
reactiveUtils.whenOnce(() => search.defaultSources.length > 1).then(() => {
const searchSources = search.defaultSources.toArray();
searchSources.pop();
if (
webmap.applicationProperties.viewing.search.enabled === true &&
webmap.applicationProperties.viewing.search.addressSearchEnabled === true
) {
searchSources.push(locatorSearch);
search.sources = searchSources;
}
else if (
webmap.applicationProperties.viewing.search.enabled === true &&
webmap.applicationProperties.viewing.search.addressSearchEnabled === false
) {
search.sources = searchSources;
}
});
reactiveUtils.whenOnce(() => search.sources.length >= 1).then(() => {
search.includeDefaultSourcesDisabled = true;
console.log(search.sources);
});
So how can I reliably do this using the arcgis-search component?