Skip to content
import LayerSearchSource from "@arcgis/core/widgets/Search/LayerSearchSource.js";
Inheritance:
LayerSearchSourceSearchSourceAccessor
Since
ArcGIS Maps SDK for JavaScript 4.11

The following properties define a Layer-based source whose features may be searched by a Search widget or Search component.

For string field searches, there is no leading wildcard. This effectively makes exactMatch true, which will remove unnecessary search results and suggestions.

Layers created from client-side graphics are not supported.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
PropertyTypeClass
autoNavigate
inherited
declaredClass
readonly inherited
filter
inherited
getResults
inherited
getSuggestions
inherited
Layer
maxResults
inherited
maxSuggestions
inherited
outFields
inherited
placeholder
inherited
popupEnabled
inherited
popupTemplate
inherited
prefix
inherited
resultSymbol
inherited
suffix
inherited
suggestionsEnabled
inherited
uid
readonly inherited
withinViewEnabled
inherited
zoomScale
inherited

autoNavigate

inherited Property
Type
boolean | null | undefined
Inherited from: SearchSource

Indicates whether to automatically navigate to the selected result once selected.

Default value
true

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

displayField

Property
Type
string | null | undefined

The results are displayed using this field. Defaults to the layer's displayField or the first string field.

exactMatch

Property
Type
boolean | null | undefined

Indicates to only return results that match the search value exactly. This property only applies to string field searches. exactMatch is always true when searching fields of type number.

Default value
false

filter

inherited Property
Type
SearchFilter | null | undefined
Inherited from: SearchSource

For filtering suggests or search results. Setting a value here takes precedence over withinViewEnabled. Please see the object specification table below for details.

Example
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

inherited Property
Type
GetResultsCallback | null | undefined
Inherited from: SearchSource

Function used to get search results. See GetResultsCallback for the function definition. When resolved, returns an object containing an array of search results.

See also

getSuggestions

inherited Property
Type
GetSuggestionsCallback | null | undefined
Inherited from: SearchSource

Function used to get search suggestions. See GetSuggestionsCallback for the function definition. When resolved, returns an object containing an array of suggest results.

See also

layer

Property
Type
Layer

The layer queried in the search. This is required. The layer can be a map/feature service feature layer(s), SceneLayers with an associated feature layer, BuildingComponentSublayer with an associated feature layer, GeoJSONLayer, CSVLayer or OGCFeatureLayer. See the SceneLayer Guide page on how to publish SceneLayers with associated feature layers.

The geometry type of the layer affects the behavior when a result is found. If the layer type is Point, the view will pan, but not zoom, to the result. If the layer type is Polygon or Polyline, the view will pan and zoom to the result.

Feature layers created from client-side graphics are not supported.

maxResults

inherited Property
Type
number | null | undefined
Inherited from: SearchSource

Indicates the maximum number of search results to return.

Default value
6

maxSuggestions

inherited Property
Type
number | null | undefined
Inherited from: SearchSource

Indicates the maximum number of suggestions to return for the widget's input.

Default value
6

minSuggestCharacters

inherited Property
Type
number | null | undefined
Inherited from: SearchSource

Indicates the minimum number of characters required before querying for a suggestion.

name

autocast Property
Type
string

The name of the source for display.

orderByFields

Property
Type
string[] | null | undefined

One or more field names used to order the query results. Specify ASC (ascending) or DESC (descending) after the field name to control the order. The default order is ASC.

outFields

inherited Property
Type
string[] | null | undefined
Inherited from: SearchSource

Specifies the fields returned with the search results.

placeholder

inherited Property
Type
string | null | undefined
Inherited from: SearchSource

Used as a hint for the source input text.

Default value
""

popupEnabled

inherited Property
Type
boolean | null | undefined
Inherited from: SearchSource

Indicates whether to display a Popup when a selected result is clicked.

popupTemplate

autocast inherited Property
Type
PopupTemplate | null | undefined
Inherited from: SearchSource

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

inherited Property
Type
string
Inherited from: SearchSource

Specify this to prefix the user's input of the search text.

Default value
""

resultGraphicEnabled

inherited Property
Type
boolean | null | undefined
Inherited from: SearchSource

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

inherited Property
Type
SymbolUnion | null | undefined
Inherited from: SearchSource

The symbol used to display the result.

Known Limitations

This property only applies when the layer/locator/source is not part of the map.

searchFields

Property
Type
string[] | null | undefined

An array of string values representing the names of fields in the feature layer to search.

searchTemplate

Property
Type
string | null | undefined

A template string used to display multiple fields in a defined order when results are displayed.

Example
LayerSearchSource.searchTemplate = "{County}, {State}";

suffix

inherited Property
Type
string
Inherited from: SearchSource

Specify this to add a suffix to the user's input for the search value.

Default value
""

suggestionsEnabled

inherited Property
Type
boolean | null | undefined
Inherited from: SearchSource

Indicates whether to display suggestions as the user enters input text in the widget.

Default value
true

suggestionTemplate

Property
Type
string | null | undefined

A template string used to display multiple fields in a defined order when suggestions are displayed. This takes precedence over displayField. Field names in the template must have the following format: {FieldName}. An example suggestionTemplate could look something like: Name: {OWNER}, Parcel: {PARCEL_ID}.

Example
LayerSearchSource.suggestionTemplate = "Name: {OWNER}, Parcel: {PARCEL_ID}";

uid

readonlyinherited Property
Type
string
Inherited from: IdentifiableMixin
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.

withinViewEnabled

inherited Property
Type
boolean
Inherited from: SearchSource

Indicates whether to constrain the search results to the view's extent.

Default value
false

zoomScale

inherited Property
Type
number | null | undefined
Inherited from: SearchSource

The set zoom scale for the resulting search result. This scale is automatically honored.

Example
let searchWidget = new Search({
view: view,
sources: [
{
layer: featureLayer,
searchFields: ["Name", "Team"],
name: "LayerSearchSource",
zoomScale: 500000
}
]
});

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
clone(): LayerSearchSource<Layer>
toJSON
inherited
toJSON(): any

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

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
ParameterTypeDescriptionRequired
json
any

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

Method
Signature
clone (): LayerSearchSource<Layer>

Creates a deep clone of this object.

Returns
LayerSearchSource

A clone of the new LayerSearchSource instance.

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

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.