Feature Services are the primary way of accessing vector features from Esri services, and are very deep in terms of functionality. Below are some examples of accessing information about a feature service (metadata), and querying for actual features.
// make a request to a feature service
client.featureservice({
url: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3'
}, function ( err, result ) {
if (err) {
console.error("ERROR: " + err);
} else {
console.log("Got the FeatureService Metadata: ", result );
}
});
Alternatively we can decompose the service url into params to provide more flexibility:
// Our feature service endpoint is:
// http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3?f=json
// Decompose the endpoint into a series of parameters
var params = {
catalog: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services',
service: 'Census',
type: 'MapServer',
layer: 3
};
// make request to the service
client.featureservice( params , function (err, result) {
if (err) {
console.error("ERROR: " + err);
} else {
console.log("Got the FeatureService Metadata: ", result );
}
});
Method | Arguments | Description |
---|---|---|
query(<query options>, <callback>) |
options |
Executes a query to filter using either SQL, a spatial clause or both simultaneously. Returns an array of matching features. |
count(<query options>, <callback>) |
options |
Accepts the same argument, but this method returns only the count of features satisfying the filter. |
ids(<query options>, <callback>) |
options |
Accepts the same argument. This method returns an array of IDs corresponding to features that satisfy the filter. |
queryRelatedRecords(<query options>, <callback>) |
options |
Allows for querying related tables. The only required query parameter is relationshipId . |
We can form spatial/sql queries for features very flexibly. If we don't send any params we are simply accepting the defaults provided by the service itself.
Here we request the default feature service query for data
var fs = client.featureservice( params , function(err, data){
fs.query({f: 'json'}, function( err, result ){
if (err) {
console.error("ERROR: " + err);
} else {
console.log("Features: ", result );
}
});
});
Feature Services are very deep and powerful. We can pass any supported parameter via a params hash:
var query_params = {
f: 'json',
returnGeometry: true,
where: '1=1',
outSR: '4326'
};
var fs = client.featureservice( params , function(err, data){
fs.query( query_params, function( err, result ){
if (err) {
console.error("ERROR: " + err);
} else {
console.log("Features: ", result );
}
});
fs.count( query_params, function( err, result ){
if (err) {
console.error("ERROR: " + err);
} else {
console.log(result); // { count: 666 }
}
});
});
We can also request features from a related layer. At the very least, the relationshipId parameter must be specified.
var query_params = {
relationshipId: 0
};
var fs = client.featureservice( params , function(err, data){
fs.queryRelatedRecords( query_params, function( err, result ){
if (err) {
console.error("ERROR: " + err);
} else {
console.log("Features: ", result );
}
});
});
Method | Arguments | Description |
---|---|---|
add(addParams, <callback>) |
options |
Expects a JSON object with a features property composed of an array of individual features. |
update([features], <callback>) |
options |
Expects a JSON object with a features property composed of an array of individual features. |
remove([ids], <callback>) |
options |
Expects a JSON object with an objectIds property composed of an array of individual ids. |
edit(<query options>, <callback>) |
options |
Allows for passing adds , updates and deletes simultaneously. |
You can find examples of these methods in action in our test suite and more information about the associated RESTful operations below.