L.esri.Tasks.Find
L.esri.Tasks.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
Constructor |
Description |
L.esri.Tasks.find(<MapService> endpoint )
L.esri.Tasks.find(<Object> options )
|
Accepts either an options object or an instance of MapService. |
Options
Option |
Type |
Default |
Description |
url |
String |
'' |
URL of the ArcGIS service you would like to consume. |
proxy |
String |
false |
URL of an ArcGIS API for JavaScript proxy or ArcGIS Resource Proxy to use for proxying POST requests. |
useCors |
Boolean |
true |
If this service should use CORS when making GET requests. |
Methods
Method |
Returns |
Description |
text(<String> text ) |
this |
Text that is searched across the layers and fields the user specifies. |
contains(<Boolean> contains ) |
this |
When true find task will search for a value that contains the searchText . When false it will do an exact match on the searchText string. Default is true . |
fields(<Array> fields or <String> fields ) |
this |
An array or comma-separated list of field names to search. If not specified, all fields are searched. |
spatialReference(<Integer> sr ) |
this |
The well known ID (ex. 4326) for the results. |
layerDef(<Integer> id , <String> where ) |
this |
Add a layer definition to the find task. |
layers(<Array> layers or <String> layers ) |
this |
Layers to perform find task on. Accepts an array of layer IDs or comma-separated list. |
returnGeometry(<Boolean> returnGeometry ) |
this |
Return geometry with results. Default is true . |
maxAllowableOffset(<Integer> maxAllowableOffset ) |
this |
Specifies the maximum allowable offset to be used for generalizing geometries returned by the find task. |
precision(<Integer> precision ) |
this |
Specifies the number of decimal places in returned geometries. |
returnZ(<Boolean> returnZ ) |
this |
Include Z values in the results. Default value is true . This parameter only applies if returnGeometry=true . |
returnM(<Boolean> returnM ) |
this |
Includes M values if the features have them. Default value is false . This parameter only applies if returnGeometry=true . |
dynamicLayers(<Object> dynamicLayers ) |
this |
Property used for adding new layers or modifying the data source of existing ones in the current map service. |
simplify(<Map> map , <Integer> factor ) |
this |
Simplify 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). |
token(<String> token ) |
this |
Adds a token to this request if the service requires authentication. Will be added automatically if used with a service. |
run(<Function> callback , <Object> context ) |
this |
Exectues 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.Tasks.find('http://services.nationalmap.gov/arcgis/rest/services/govunits/MapServer');
find.layers('18')
.text('Colorado');
find.run(function(error, featureCollection, response){
console.log('GNIS Name: ' + featureCollection.features[0].properties.GNIS_NAME);
});
Finding features by specified search field name
var find = L.esri.Tasks.find({
url: 'http://services.nationalmap.gov/arcgis/rest/services/govunits/MapServer'
});
find.layers('13')
.text('198133')
.fields('GNIS_ID');
find.run(function(error, featureCollection, response){
console.log('Found ' + featureCollection.features.length + ' feature(s)');
console.log('Found ' + featureCollection.features[0].properties.GNIS_NAME + ' in ' + featureCollection.features[0].properties.STATE_NAME);
});
Edit this page on GitHub