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(urlOrOptions: string | FindOptions | Service)
find(urlOrOptions: string | FindOptions) // convenience factory

Options​

OptionTypeDefaultDescription
urlstringRequired. MapServer URL
layersnumber | number[] | string'all'Layers to search
searchTextstring''Text to search for
searchFieldsstring | string[]Fields to search in (all fields when omitted)
containsbooleantrueUse substring matching
returnGeometrybooleantrueInclude feature geometry
layerDefsstringLayer definition expressions, e.g. "0:POP > 100000"
srstring | numberSpatial reference for results
maxAllowableOffsetnumberGeometry simplification
geometryPrecisionnumberDecimal places for geometry
dynamicLayersArray<object>Search a dynamic layer definition instead of published layers
returnZ / returnMbooleanInclude Z / M values in returned geometry
gdbVersionstringGeodatabase version to search
tokenstringAuthentication token
apiKeystringArcGIS Location Platform API key
authenticationIAuthenticationManager | stringArcGIS REST JS auth manager (guide)

Chainable Methods​

MethodParameterDescription
.text(searchText)stringSet the text to search for
.fields(fields)string | string[]Fields to search in
.layers(layers)number | number[] | stringLayers to search
.contains(useSubstring)booleanSubstring matching (true) or exact match (false)
.returnGeometry(include)booleanInclude feature geometry in results
.layerDefs(layerId, where)number | string, stringAdd a WHERE clause for one layer (call repeatedly to add more)
.spatialReference(sr)string | numberSet output spatial reference WKID (alias: .sr())
.maxAllowableOffset(offset)numberGeneralize the returned geometry
.precision(places)numberDecimal places for returned geometry
.dynamicLayers(layers)object[]Search a dynamic layer definition
.returnZ(include) / .returnM(include)booleanInclude Z / M values
.gdbVersion(version)stringSearch a specific geodatabase version
.token(authToken)stringSet authentication token

Execution Method​

.run() → Promise<GeoJSON.FeatureCollection>​

Execute the find operation and return matching features as GeoJSON. Each feature's properties carry the ArcGIS attributes plus layerId, layerName, foundFieldName and value; Esri point, polyline and polygon geometries are converted, and any other geometry type comes back as null.

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();