import LocatorSearchSource from "@arcgis/core/widgets/Search/LocatorSearchSource.js";const LocatorSearchSource = await $arcgis.import("@arcgis/core/widgets/Search/LocatorSearchSource.js");- Inheritance:
- LocatorSearchSource→
SearchSource→ Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.0
The following properties define a source pointing to a url that represents a locator service, which may be used to geocode locations with a Search widget or Search component.
- See also
Search widget - Deprecated since 4.33. Use the Search component instead.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
autoNavigate inherited | ||
| | ||
| | ||
declaredClass readonly inherited | ||
| | ||
| | ||
getResults inherited | ||
getSuggestions inherited | ||
| | ||
| | ||
| | ||
maxResults inherited | ||
maxSuggestions inherited | ||
minSuggestCharacters inherited | ||
| | ||
outFields inherited | ||
| | ||
popupEnabled inherited | ||
popupTemplate inherited | ||
prefix inherited | ||
resultGraphicEnabled inherited | ||
resultSymbol inherited | SymbolUnion | null | undefined | |
| | ||
| | ||
suffix inherited | ||
| | ||
uid readonly inherited | ||
| | ||
withinViewEnabled inherited | ||
| |
apiKey
- Since
- ArcGIS Maps SDK for JavaScript 4.19
An authorization string used to access a resource or service. API keys are generated and managed in the portal. An API key is tied explicitly to an ArcGIS account; it is also used to monitor service usage. Setting a fine-grained API key on a specific class overrides the global API key.
Example
const searchElem = document.querySelector("arcgis-search");await searchElem.componentOnReady();searchElem.sources = [{ name: "apiKey locator", placeholder: "APIs are Key", apiKey: "YOUR_API_KEY", url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"}]; autoNavigate
Indicates whether to automatically navigate to the selected result once selected.
- Default value
- true
defaultZoomScale
- Since
- ArcGIS Maps SDK for JavaScript 4.13
Sets the scale of the MapView.scale or SceneView.scale
for the resulting search result, if the locator service doesn't return an extent with a scale. An example of this is using
the Use current location option in the Search bar.
If you want to override the scale returned by the locator service, use zoomScale instead.
Example
// wait for Search to be ready to set the defaultZoomScalereactiveUtils.when( () => search.state === "ready", () => { let firstSource = search.allSources.at(0); if (firstSource) { firstSource.defaultZoomScale = 100000; } }); filter
- Type
- SearchFilter | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.4
This property replaces the now deprecated searchQueryParams, suggestQueryParams, and searchExtent
properties. Setting a value here takes precedence over withinViewEnabled.
Please see the object specification table below for details.
- See also
Examples
const theExtent = new Extent({ xmin: 11376463, ymin: -5163501, xmax: 18890529, ymax: -662888, spatialReference: { wkid: 3857 }});
const searchElem = document.querySelector("arcgis-search");await searchElem.componentOnReady();searchElem.sources = [{ url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", placeholder: "Carmen Sandiego", maxResults: 3, filter: searchExtent}];const theExtent = new Extent({ xmin: 11376463, ymin: -5163501, xmax: 18890529, ymax: -662888, spatialReference: { wkid: 3857 }});
const searchExtent = { geometry: theExtent, where: "TERRITORY = 'Northern Territory'"};
const sources = [{ layer: featureLayerTourism, placeholder: "Darwin", maxResults: 5, searchFields: ["POI"], displayField: "POI", name: "In a Sunburned Country", filter: searchExtent}];
const searchWidget = new Search({ view: view, sources: sources}); getResults
- Type
- GetResultsCallback | null | undefined
Function used to get search results. See GetResultsCallback for the function definition. When resolved, returns an object containing an array of search results.
getSuggestions
- Type
- GetSuggestionsCallback | null | undefined
Function used to get search suggestions. See GetSuggestionsCallback for the function definition. When resolved, returns an object containing an array of suggest results.
language
- Since
- ArcGIS Maps SDK for JavaScript 4.34
This property defines the preferred language for reverse geocoded results (if supported by the locator service at the geolocated location).
If null, the default language of the geocoded country will be used.
Similarly, the default language will be used if the parsed language is not supported in that geocoded country.
Example
// Return addresses in Spanish (if supported at the geolocated location)const search = new Search({ view, includeDefaultSources: false, sources: [ { apiKey: "YOUR_API_KEY", language: "es", // Spanish name: "ArcGIS World Geocoding Service", placeholder: "Find address or place", singleLineFieldName: "SingleLine", url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", } ]}); localSearchDisabled
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.22
This property controls prioritization of Search result candidates depending on the view scale.
When this property is false (the default value), the location parameter is included in
the request when the scale of the MapView.scale
or SceneView.scale is less than or equal to 300,000.
This prioritizes result candidates based on their distance from a specified point (the
center of the view).
When this property is true, the location parameter is never included in the request,
no matter the scale of the MapView.scale or
SceneView.scale.
- Default value
- false
Example
const searchElem = document.querySelector("arcgis-search");await searchElem.componentOnReady();searchElem.sources = [{ name: "ArcGIS World Geocoding Service", placeholder: "example: Campton, NH", apiKey: "YOUR_API_KEY", singleLineFieldName: "SingleLine", url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", localSearchDisabled: true}]; locationType
- Type
- LocationType | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.12
Defines the type of location, either street or rooftop, of the point returned from the
World Geocoding Service.
Example
// wait for Search to be ready to set the locationTypereactiveUtils.when( () => search.state === "ready", () => { let firstSource = search.allSources.at(0); if (firstSource) { firstSource.locationType = "rooftop"; } }); maxResults
Indicates the maximum number of search results to return.
- Default value
- 6
maxSuggestions
Indicates the maximum number of suggestions to return for the widget's input.
- Default value
- 6
minSuggestCharacters
Indicates the minimum number of characters required before querying for a suggestion.
outFields
Specifies the fields returned with the search results.
popupEnabled
Indicates whether to display a Popup when a selected result is clicked.
popupTemplate
- Type
- PopupTemplate | null | undefined
The popup template used to display search results.
If no popup is needed, set the source's popupTemplate to null.
This property should be set in instances where there is no existing PopupTemplate configured. For example, feature sources will default to any existing FeatureLayer.popupTemplate configured on the layer.
prefix
- Type
- string
Specify this to prefix the user's input of the search text.
- Default value
- ""
resultGraphicEnabled
Indicates whether to show a graphic on the
map for the selected source using the resultSymbol.
If using a LayerSearchSource, then this property only applies when the LayerSearchSource is not part of the map.
resultSymbol
- Type
- SymbolUnion | null | undefined
The symbol used to display the result.
Known Limitations
This property only applies when the layer/locator/source is not part of the map.
searchTemplate
- Type
- string
A template string used to display multiple fields in a defined order when results are displayed.
- Default value
- ""
Example
locatorLayerSource.searchTemplate = "{County}, {State}"; suffix
- Type
- string
Specify this to add a suffix to the user's input for the search value.
- Default value
- ""
uid
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 4.33
An automatically generated unique identifier assigned to the instance. The unique id is generated each time the application is loaded.
url
- Since
- ArcGIS Maps SDK for JavaScript 4.22
URL to the ArcGIS Server REST resource that represents a locator service. This is required.
Example
const searchElem = document.querySelector("arcgis-search");await searchElem.componentOnReady();searchElem.sources = [{ url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"}]; withinViewEnabled
- Type
- boolean
Indicates whether to constrain the search results to the view's extent.
- Default value
- false
zoomScale
The set zoom scale for the resulting search result. This scale is automatically honored.
Examples
const searchElem = document.querySelector("arcgis-search");await searchElem.componentOnReady();searchElem.sources = [{ url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", name: "LocatorSearchSource", zoomScale: 500000}];let searchWidget = new Search({ view: view, sources: [ { layer: featureLayer, searchFields: ["Name", "Team"], name: "LayerSearchSource", zoomScale: 500000 } ]});Methods
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): LocatorSearchSource
Creates a deep clone of this object.
- Returns
- LocatorSearchSource
A clone of the new LocatorSearchSource instance.
toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.