Select to view content in your preferred language

District SearchWidget with Enterprise Locator two specific countries

379
5
Jump to solution
02-19-2026 02:09 AM
SebastianKrings
Frequent Contributor

Hi,

currently we are using the SearchWidget with defaultSources enabled.
In our EnterprisePortal we have our own LocatorService.

As far as I understood the portal one is taken over arcgis.com-WorldLocator by simply setting the portalUrl in JS:

esriConfig.portalUrl = ...

 

Now we would like to district the search results to specific countries (DE + DK in my case).
I am not getting it to work.

Best guess I found is the LocatorSource to set the CountryCode.
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSourc...
Unfortunately there is no sample.

I tried to place it into the sources-array which also countains our Layers to search in.
Additionally I disabled to use defaultSearchSource.

Here is my current code:

const sources = await this.getSearchSourcesAsync(handles);

const sourceDE = new LocatorSearchSource();
sourceDE.countryCode = 'DE';
sources.push(sourceDE);

const searchWidget = new Search({
	view: mapView,
	includeDefaultSources: false,
	locationEnabled: false,
	sources,
	container: this.elementRefSearch!.nativeElement
});

 

In the ExperienceBuilder its pretty easy to district on specific countries. It offers an option for that:

SebastianKrings_0-1771495147363.png

The LocatorSearchSource however only accepts a single country at once.


I hope there is an equivalent easy way to district the countries for the JS SearchWidget.

0 Kudos
1 Solution

Accepted Solutions
WesleyO
Esri Contributor

Hi @SebastianKrings ,

Using the countryCode property is the correct equivalent you are looking for. You should be able to add multiple countries by separating them by commas for your string input, similar to how you have done it in Experience Builder.

Here is an example: https://codepen.io/woriginales/pen/KwMOZPP

 

View solution in original post

0 Kudos
5 Replies
WesleyO
Esri Contributor

Hi @SebastianKrings ,

Using the countryCode property is the correct equivalent you are looking for. You should be able to add multiple countries by separating them by commas for your string input, similar to how you have done it in Experience Builder.

Here is an example: https://codepen.io/woriginales/pen/KwMOZPP

 

0 Kudos
SebastianKrings
Frequent Contributor

Hey thanks.

Is it somehow possible to omit url like using the default-sources where I do not need to put the geocode url?
I would prefer not to have const urls in my app.

Nevertheless, the documentation should be updated here as well.
For LocatorSearchSource for property countryCode it says:

Constricts search results to a specified country code. For example, US for United States or SE for Sweden.

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSourc...

0 Kudos
Noah-Sager
Esri Regular Contributor

Unfortunately, if you modify the sources, you'll need the geocoding url as well. I think some devs put constants in a separate file if that helps.

The doc for countryCode looks right to me. Both "US" and "SE" seem to work fine. Can you explain what you think should be updated?

0 Kudos
SebastianKrings
Frequent Contributor

The doc says no word about using multiple codes comma separated is a valid option.
For me it sounds that you just can enter exactly one code.
E.g.:
Instead of current:


Constricts search results to a specified country code. For example, US for United States or SE for Sweden.

It could be:

Constricts search results to one or more specified country codes. For example, US for United States or SE for Sweden or "'US', 'SE'" for both.

Noah-Sager
Esri Regular Contributor

Ah, that's a good call. Thanks for pointing that out @SebastianKrings, we'll improve the doc there.