Skip to main content

Find

Perform text-based searches across multiple fields and layers in an ArcGIS MapServer.

Interactive Demo

Search for text across multiple fields in the USA MapService. Try searching for state abbreviations like "CA", "TX", or "NY". Results are highlighted in green on the map.

Quick Start

import { Find } from 'esri-gl';

const findTask = new Find({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer',
});

const results = await findTask
.text('California')
.fields(['state_name', 'state_abbr'])
.layers([0, 1, 2])
.run();

Constructor

new Find(options: FindOptions)

Options

OptionTypeDefaultDescription
urlstringRequired. MapServer URL
layersArray<number>Layers to search
searchTextstringText to search for
searchFieldsstring[]Fields to search in
containsbooleantrueUse substring matching
returnGeometrybooleanfalseInclude feature geometry
layerDefsobjectLayer definition expressions
srnumberSpatial reference for results
tokenstringAuthentication token

Chainable Methods

MethodParameterDescription
.text(searchText)stringSet the text to search for
.fields(fieldArray)string[]Fields to search in
.layers(layerIds)number[]Layers to search
.contains(useSubstring)booleanSubstring matching (true) or exact match (false)
.returnGeometry(include)booleanInclude feature geometry in results
.layerDefinitions(defs)objectApply layer-specific WHERE clauses
.spatialReference(sr)numberSet output spatial reference WKID

Execution Method

.run()Promise<FindResponse>

Execute the find operation and return matching features.

Examples

const results = await new Find({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer',
})
.text('Texas')
.fields(['state_name', 'state_abbr'])
.layers([2])
.run();
const results = await new Find({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer',
})
.text('Los Angeles')
.fields(['city_name', 'areaname', 'name'])
.layers([0, 1])
.contains(true)
.returnGeometry(true)
.run();

Exact Match

const results = await new Find({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer',
})
.text('CA')
.fields(['state_abbr'])
.layers([2])
.contains(false)
.run();