Select to view content in your preferred language

Can you remove a search source from a web map that has search enabled?

99
2
Jump to solution
Tuesday
MBocek
by
Occasional Contributor

If a web map has search enabled in the application settings, is it possible to remove those sources in the map component? 

I would like the search source to only be a default one created from AGOL world geocoding. I figured out how to add the AGOL LocatorSearchSource to the search component, and I can make it the first option with the active-source-index property. However, the other options from the web map remain. This is an issue as one of the locators will prompt public users for credentials if selected.

I feel like I'm missing something simple that would allow for only the default source to be used for searching.

Search | ArcGIS Maps SDK for JavaScript

 

0 Kudos
1 Solution

Accepted Solutions
VenkataKondepati
Regular Contributor

Yes — you can. In the Search map component, the web map’s configured search sources are used unless you override them.

To force only the World Geocoder (and prevent the web map sources from showing up), do two things:

Disable default/webmap sources in the UI
Use include-default-sources-disabled="true" (this stops defaultSources from being included).
Esri Developer

Explicitly set sources to only your locator
Once sources is set, the component won’t fall back to allSources from the web map.
Esri Developer

Example:

<arcgis-search
  include-default-sources-disabled="true"
  active-source-index="0">
</arcgis-search>

 

import LocatorSearchSource from "@arcgis/core/widgets/Search/LocatorSearchSource.js";

const search = document.querySelector("arcgis-search");

search.sources = [
  new LocatorSearchSource({
    url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
    name: "World Geocoder"
  })
];

 

If you still see the secured locator after this, it usually means sources wasn’t actually being set (or it’s being appended elsewhere). But the supported approach is: disable default sources + set sources explicitly.

View solution in original post

2 Replies
VenkataKondepati
Regular Contributor

Yes — you can. In the Search map component, the web map’s configured search sources are used unless you override them.

To force only the World Geocoder (and prevent the web map sources from showing up), do two things:

Disable default/webmap sources in the UI
Use include-default-sources-disabled="true" (this stops defaultSources from being included).
Esri Developer

Explicitly set sources to only your locator
Once sources is set, the component won’t fall back to allSources from the web map.
Esri Developer

Example:

<arcgis-search
  include-default-sources-disabled="true"
  active-source-index="0">
</arcgis-search>

 

import LocatorSearchSource from "@arcgis/core/widgets/Search/LocatorSearchSource.js";

const search = document.querySelector("arcgis-search");

search.sources = [
  new LocatorSearchSource({
    url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
    name: "World Geocoder"
  })
];

 

If you still see the secured locator after this, it usually means sources wasn’t actually being set (or it’s being appended elsewhere). But the supported approach is: disable default sources + set sources explicitly.

MBocek
by
Occasional Contributor

Just adding the include-default-sources-disabled="true" seemed to do the trick. I got confused on the definition of default sources. Thanks!