import LayerSearchSource from "@arcgis/core/widgets/Search/LayerSearchSource.js";const LayerSearchSource = await $arcgis.import("@arcgis/core/widgets/Search/LayerSearchSource.js");- Inheritance:
- LayerSearchSource→
SearchSource→ Accessor
- 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
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 | ||
| | ||
| | ||
filter inherited | ||
getResults inherited | ||
getSuggestions inherited | ||
Layer | | |
maxResults inherited | ||
maxSuggestions inherited | ||
minSuggestCharacters inherited | ||
| | ||
| | ||
outFields inherited | ||
placeholder inherited | ||
popupEnabled inherited | ||
popupTemplate inherited | ||
prefix inherited | ||
resultGraphicEnabled inherited | ||
resultSymbol inherited | SymbolUnion | null | undefined | |
| | ||
| | ||
suffix inherited | ||
suggestionsEnabled inherited | ||
| | ||
uid readonly inherited | ||
withinViewEnabled inherited | ||
zoomScale inherited |
autoNavigate
Indicates whether to automatically navigate to the selected result once selected.
- Default value
- true
filter
- Type
- SearchFilter | null | undefined
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
- 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.
layer
- 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
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.
placeholder
Used as a hint for the source input text.
- Default value
- ""
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.
suffix
- Type
- string
Specify this to add a suffix to the user's input for the search value.
- Default value
- ""
suggestionsEnabled
Indicates whether to display suggestions as the user enters input text in the widget.
- Default value
- true
suggestionTemplate
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
- 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.
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.
Example
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 (): LayerSearchSource<Layer>
Creates a deep clone of this object.
- Returns
- LayerSearchSource
A clone of the new LayerSearchSource 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.