L.esri.Find

Extends L.esri.Task

L.esri.Find is an abstraction for the find API included in Map Services. It provides a chainable API for building request parameters and executing find tasks.

Constructor

ConstructorDescription
L.esri.find(<MapService>endpoint)L.esri.find(<Object>options)Accepts either an options object or an instance of MapService.

Options

OptionTypeDefaultDescription
urlString''URL of the ArcGIS service you would like to consume.
proxyStringfalseURL of an ArcGIS API for JavaScript proxy or ArcGIS Resource Proxy to use for proxying POST requests.
useCorsBooleantrueIf this service should use CORS when making GET requests.

Methods

MethodReturnsDescription
text(<String>text)thisText that is searched across the layers and fields the user specifies.
contains(<Boolean>contains)thisWhen true find task will search for a value that contains the text. When false it will do an exact match on the text string. Default is true.
fields(<Array>fields or <String>fields)thisAn array or comma-separated list of field names to search. If not specified, all fields are searched.
spatialReference(<Integer>sr)thisThe well known ID (ex. 4326) for the results.
layerDef(<Integer>id, <String>where)thisAdd a layer definition to the find task.
layers(<Array>layers or <String>layers)thisLayers to perform find task on. Accepts an array of layer IDs or comma-separated list.
returnGeometry(<Boolean>returnGeometry)thisReturn geometry with results. Default is true.
maxAllowableOffset(<Integer>maxAllowableOffset)thisSpecifies the maximum allowable offset to be used for generalizing geometries returned by the find task.
precision(<Integer>precision)thisSpecifies the number of decimal places in returned geometries.
returnZ(<Boolean>returnZ)thisInclude Z values in the results. Default value is true. This parameter only applies if returnGeometry=true.
returnM(<Boolean>returnM)thisIncludes M values if the features have them. Default value is false. This parameter only applies if returnGeometry=true.
dynamicLayers(<Object>dynamicLayers)thisProperty used for adding new layers or modifying the data source of existing ones in the current map service.
simplify(<Map>map, <Integer>factor)thisSimplify the geometries of the output features for the current map view. the factor parameter controls the amount of simplification between 0 (no simplification) and 1 (simplify to the most basic shape possible).
format(<Boolean>formatResponse)thisUse false to ensure that the server returns unformatted feature attributes.Only available for ArcGIS Server 10.5+.
token(<String>token)thisAdds a token to this request if the service requires authentication. Will be added automatically if used with a service.
run(<Function>callback, <Object>context)thisExectues the find request with the current parameters, features will be passed to callback as a GeoJSON FeatureCollection. Accepts an optional function context.

Example

Finding features
var find = L.esri.find('https://services.nationalmap.gov/arcgis/rest/services/govunits/MapServer');

find.layers('18').text('Colorado');

find.run(function (error, featureCollection, response) {
    if (error) {
    console.log(error);
    return;
    }
    console.log('GNIS Name: ' + featureCollection.features[0].properties.GNIS_NAME);
});
Finding features by specified search field name
var find = L.esri.find({
    url: 'https://services.nationalmap.gov/arcgis/rest/services/govunits/MapServer'
});

find.layers('13').text('198133').fields('GNIS_ID');

find.run(function (error, featureCollection, response) {
    if (error) {
    console.log(error);
    return;
    }
    console.log('Found ' + featureCollection.features.length + ' feature(s)');
    console.log('Found ' + featureCollection.features[0].properties.GNIS_NAME + ' in ' + featureCollection.features[0].properties.STATE_NAME);
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.