Class: FeatureLayer

Description

Class added v2.0.
dojo.require("esri.layers.FeatureLayer");

The feature layer inherits from the graphics layer and can be used to display features from a single layer in either a Map Service or Feature Service. The layer can be either a (spatial) layer or (non-spatial) table. If the underlying layer (or table) is from a Feature Service, its features can be edited.

Samples

Search for samples that use this class.  

Class hierarchy

esri.layers.Layer
  |_ esri.layers.GraphicsLayer
        |_ esri.layers.FeatureLayer

Constructor

Constructor Description
esri.layers.FeatureLayer(url, options?) Creates a new instance of a feature layer object from the ArcGIS Server REST resource identified by the input URL. Once created you can optionally set a definition expression or time definition.
esri.layers.FeatureLayer(featureCollectionObject, options?)

Creates a new instance of a feature layer using a FeatureCollection object. The feature layer, when initialized with a feature collection object has the following behavior:

  • Edits are applied on the client not posted to the server.
  • The feature layer generates a unique object id for new features.
  • Does not support queries that need to be performed on the server, e.g. queries with a where clause.
  • The feature layer toJson method returns an object with the same properties as the feature collection. The returned object includes all the features that are in the layer when the method is called. This method can be used to access a serializable representation of the features that can be saved on the server.

Properties

Property Type Description
capabilities String Information about the capabilities enabled for this layer.
copyright String Copyright information for the layer.
defaultDefinitionExpression String Metadata describing the default definition expression for the layer as defined by the service.
description String The description of the layer as defined in the map service.
displayField String The name of the layer's primary display field. The value of this property matches the name of one of the fields of the layer.
fields Field[] The array of fields in the layer.
fullExtent Extent The full extent of the layer.
geometryType String Geometry type of the features in the layer. Can be one of the following: "esriGeometryPoint", "esriGeometryPolygon" or "esriGeometryPolyline".
globalIdField String The globalIdField for the layer.
graphics Graphic[] Array of features in the layer.
hasAttachments Boolean True if attachments are enabled on the feature layer.
htmlPopupType String The html popup type defined for the layer. View the constants table for a list of valid values.
layerId Number Unique ID of the layer that the FeatureLayer was contructed against.
maxScale Number Maximum visible scale for the layer. If the map is zoomed in beyond this scale, the layer will not be visible. A value of 0 means that the layer does not have a maxium scale.
minScale Number Minimum visible scale for the layer. If the map is zoomed out beyond this scale, the layer will not be visible. A value of 0 means that the layer does not have a minimum scale.
name String The name of the layer as defined in the map service.
objectIdField String The name of the field that contains the Object ID field for the layer.
relationships Object[] Each element in the array is an object that describes the layer's relationship with another layer or table.
renderer Renderer The renderer for the layer.
templates FeatureTemplate[] An array of feature templates defined in the Feature Service layer. Only applicable for ArcGIS Server Feature Service layers.
timeInfo TimeInfo Time information for the layer, such as start time field, end time field, track id field, layers time extent and the draw time interval. Only applicable if the layer is time aware.
type String Specifies the type of layer. Can be "Feature Layer" or "Table".
typeIdField String The field that represents the Type ID field. Only applicable for ArcGIS Server Feature Service layers.
types FeatureType[] An array of sub types defined in the Feature Service layer. Only applicable for ArcGIS Server Feature Service layers.
version Number The version of ArcGIS Server where the layer is published. Examples are 9.3, 9.3.1, 10, 10.01.

Constants

Constant Description
MODE_ONDEMAND

In on-demand mode, the feature layer retrieves features from the server when needed based on the requirements defined in the following properties:

  • Map properties such as the current spatial extent and time extent.
  • Layer properties such as time offset and definition expression.
MODE_SELECTION

In selection mode, features are retrieved from the server only when they are selected. Features are available on the client only while they are selected. To work with selected features:

  1. Call the selectFeatures method.
  2. Listen for the onSelectionComplete event.
  3. Once onSelectionComplete fires, retrieve the selected features using the getSelectedFeatures method.

When editing feature layers in selection mode, you will need to add the map service associated with the feature service to the map as a dynamic map service. After modifying features, listen for the onEditsComplete event and manually refresh the associated dynamic map service layer so the modified features are rendered. If you do not have the map service added as a dynamic map service then the changes will not be visible because once the edits are complete the feature is no longer selected.

MODE_SNAPSHOT In snapshot mode, the feature layer retrieves all the features from the associated layer resource and displays them as graphics on the client. Definition expressions and time definitions are honored. The features are retrieved once the feature layer is added to the map. After the onUpdateEnd event has fired, you can access the features using the graphics property of the layer or through selection and query operations.
POPUP_HTML_TEXT The popup displays content in HTML/TEXT
POPUP_NONE No popup type defined
POPUP_URL The popup displays the contents of a URL.
SELECTION_ADD Adds features to the current selection set
SELECTION_NEW Creates a new selection.
SELECTION_SUBTRACT Removes features from the current selection

Methods

Method Return Value Description
addAttachment(objectId, formNode, callback?, errback?) dojo.Deferred Add an attachment to the feature specified by the ObjectId.
applyEdits(adds?, updates?, deletes?, callback?, errback?) dojo.Deferred Apply edits to the feature layer. Only applicable for layers in a feature service.
clearSelection() FeatureLayer Clears the current selection.
deleteAttachments(objectId, attachmentIds, callback?, errback?) dojo.Deferred Delete one or more attachments for the feature specified by the input ObjectId.
getDefinitionExpression() String Returns the current definition expression.
getSelectedFeatures() Graphic[] Gets the currently selected features.
getSelectionSymbol() Symbol Gets the current selection symbol.
getTimeDefinition() TimeExtent Get the current time definition applied to the feature layer.
isEditable() Boolean Returns true if the FeatureLayer is editable.
queryAttachmentInfos(objectId, callback?, errback?) dojo.Deferred Query for information about attachments associated with the specified ObjectIds.
queryCount(query, callback?, errback?) dojo.Deferred Get a count of the number of features that satisfy the input query. Valid only for layers published using ArcGIS Server 10 SP1 or greater. Layers published with earlier versions of ArcGIS Server return an error to the error callback.
queryFeatures(query, callback?, errback?) dojo.Deferred Query features from the feature layer. Layer definition and time definition are honored. Whenever possible the feature layer will perform the query on the client.
queryIds(query, callback?, errback?) dojo.Deferred Query for ObjectIds. There is no limit on the number of ObjectIds that are returned from the server. Like queryFeatures this operation will perform queries on the client (browser) whenever possible.
queryRelatedFeatures(relQuery, callback?, errback?) dojo.Deferred Query features or records, from another layer or table, related to features in this layer.
refresh() none Refreshes the features in the feature layer. The feature layer requeries all the features in the service, except the selected features, and updates itself.
selectFeatures(query, selectionMethod?, callback?, errback?) dojo.Deferred Selects features from the FeatureLayer. Layer properties like layer definition and time definition are honored. The selection method defines how query results are passed to the selection. The feature layer will highlight the current selection if a selection symbol has been defined. Whenever possible, the feature layer will perform the query operation on the client (browser).
setDefinitionExpression() FeatureLayer Set's the definition expression for the FeatureLayer. Only the features that match the definition expression are displayed.
setOpacity(opacity) none Initial opacity or transparency of layer. Not supported in Internet Explorer.
setRenderer(renderer) none Set the renderer for the feature layer.
setSelectionSymbol(symbol) FeatureLayer Set's the selection symbol for the feature layer. If no symbol is specified, features are drawn using the layer's renderer.
setTimeDefinition(definition) FeatureLayer Set's the time definition for the feature layer.
setTimeOffset(offsetValue, offsetUnits) FeatureLayer Sets a time offset for the layer. Only applicable for time-aware layers.
toJson() Object Returns an easily serializable object representation of the layer.

Events

Event Description
onAddAttachmentComplete(result) Fires when addAttachments() is complete.
onBeforeApplyEdits(adds, updates, deletes) Fired before edits are applied to the feature layer.
onDblClick(event) Fires when a feature has been double clicked.
onDeleteAttachmentsComplete(results) Fires when deleteAttachments is complete.
onEditsComplete(addResults, updateResults, deleteResults) Fires after applyEdits() has been called.
onQueryAttachmentInfosComplete(attachmentInfos) Fires when queryAttachmentInfos() is complete.
onQueryCountComplete(count) Fires when the query for the count is complete. This event is only available for layers published using ArcGIS Server 10 SP1 or later.
onQueryFeaturesComplete(featureSet) Fires when queryFeatures() is complete.
onQueryIdsComplete(ids) Fires when queryIds() is complete.
onQueryRelatedFeaturesComplete(relatedFeatures) Fires when queryRelatedFeatures() is complete.
onSelectionClear() Fires after clearSelection has been called.
onSelectionComplete(features, selectionMethod) Fires when selectFeatures() has completed. OnSelectionComplete always fires unless there is an error returned by the server.
onUpdateEnd(error) Fired when the layer has finished updating its content. This event is always preceded by onUpdateStart
onUpdateStart() Fired when the layer begins to update its content. The following table describes when the event is fired in various modes.
Snapshot
  • When the layer is added to the map.
  • When layer properties such as definition expression, time definition or time offset are modified.
  • When the map's time extent changes.
  • When the layer is refreshed.
OnDemand
  • When the layer is added to the map.
  • When the map's spatial extent or time extent changes.
  • When layer properties such as definition expression or time offset are modified.
  • When the layer is refreshed.
Selection The event is not fired in selection mode.
Constructor Detail

esri.layers.FeatureLayer(url, options?)

Creates a new instance of a feature layer object from the ArcGIS Server REST resource identified by the input URL. Once created you can optionally set a definition expression or time definition.
Parameters:
<String> url Required URL to the ArcGIS Server REST resource that represents a feature service. An example is http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer/0. For more information on constructing a URL, see The Services Directory and the REST API.
<Object> options Optional Optional parameters. See options list.
Options:
<Boolean> displayOnPan When true, graphics are displayed during panning. When false, the graphics are turned off during pan movement. Setting to false may improve performance in Internet Explorer. The default is true.
<String> id Unique ID to assign to the layer. If not assigned, esri.Map creates a unique ID.
<InfoTemplate> infoTemplate The template that defines the content to display in the map info window when the user clicks on a feature. If not specified, the info window will not be displayed.
<Number> maxAllowableOffset The maximum allowable offset, only applicable for layers that are not editable.
<Number> mode

Specify the layers mode of operation. Each mode determines when and how many features are sent to the client. You can specify the following values:

  • esri.layers.FeatureLayer.MODE_SNAPSHOT
  • esri.layers.FeatureLayer.MODE_ONDEMAND
  • esri.layers.FeatureLayer.MODE_SELECTION

See the constants table for details on each mode.

<Number> opacity Initial opacity or transparency of layer. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency. The default value is 1.0. Not supported in Internet Explorer.
<String[]> outFields

A comma delimited list of field names to include in the FeatureLayer. If not specified, the feature layer will return the OBJECTID field and if applicable the start time field, end time field and type id field. You can specify ["*"] to fetch the values for all fields in the layer, this is useful when editing features.

<Number> tileHeight Specify the size of the virtual tiles, used in on-demand mode. The virtual tile scheme is used in on-demand mode to make effective use of browser caching. The default value is 512. This option is only valid in on-demand mode and must be a square. For example, specifying a value like 512x256 is not supported.
<Number> tileWidth Specify the size of the virtual tiles, used in on-demand mode. The virtual tile scheme is used in on-demand mode to make effective use of browser caching. The default value is 512. This option is only valid in on-demand mode and must be a square. For example, specifying a value like 512x256 is not supported.
  featureLayer = new esri.layers.FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1",{
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
    tileWidth:200,
    tileHeight:200
  });
<String> trackIdField The name of the trackIdField.
  featureLayer = new esri.layers.FeatureLayer(featureLayerURL, {
    mode: esri.layers.FeatureLayer.MODE_SELECTION,
    trackIdField: "Animal_1"
  });
<Boolean> visible Initial visibility of the layer. Default is true.
Code snippets:
var infoTemplate = new esri.InfoTemplate("${FIELD_NAME}", content);
featureLayer = new esri.layers.FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServer/0",{
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
    infoTemplate: infoTemplate,
    outFields: ["*"]
});

esri.layers.FeatureLayer(featureCollectionObject, options?)

Creates a new instance of a feature layer using a FeatureCollection object. The feature layer, when initialized with a feature collection object has the following behavior:

  • Edits are applied on the client not posted to the server.
  • The feature layer generates a unique object id for new features.
  • Does not support queries that need to be performed on the server, e.g. queries with a where clause.
  • The feature layer toJson method returns an object with the same properties as the feature collection. The returned object includes all the features that are in the layer when the method is called. This method can be used to access a serializable representation of the features that can be saved on the server.
Parameters:
<Object> featureCollectionObject Required

A feature collection is an object with the following properties:

<Object> layerDefinition The structure is the same as the information returned by REST for a layer in a feature or map service.
<Object> featureSet A collection of features.
<Object> options Optional Optional parameters. See options list.
Code snippets:
var featureCollection = {
  layerDefinition: layerDefinition,
  featureSet: null
};
featureLayer = new esri.layers.FeatureLayer(featureCollection, {
  mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
});
Properties Detail

<String> capabilities

Information about the capabilities enabled for this layer.

<String> copyright

Copyright information for the layer.

<String> defaultDefinitionExpression

Metadata describing the default definition expression for the layer as defined by the service. The default definition expression limits the features available for display and query. You cannot override this value but you define additional filters on the default expression using the setDefinitionExpression method. For example, if the default definition expression is set to display data where "STATE_NAME = 'California'" you could use setDefinitionExpression to only display a subset of the features in California e.g., "COUNTY='San Diego'".
See also:
setDefinitionExpression  

<String> description

The description of the layer as defined in the map service.

<String> displayField

The name of the layer's primary display field. The value of this property matches the name of one of the fields of the layer.

<Field[]> fields

The array of fields in the layer.

<Extent> fullExtent

The full extent of the layer.

<String> geometryType

Geometry type of the features in the layer. Can be one of the following: "esriGeometryPoint", "esriGeometryPolygon" or "esriGeometryPolyline".

<String> globalIdField

The globalIdField for the layer.

<Graphic[]> graphics

Array of features in the layer.

<Boolean> hasAttachments

True if attachments are enabled on the feature layer. Use the queryAttachmentInfos method to determine if the the feature has attachments. If the layer is editable (isEditable) and supports attachments the following operations can be performed.

  • Add attachments to features.
  • Delete existing attachments.
See also:
queryAttachmentInfos  

<String> htmlPopupType

The html popup type defined for the layer. View the constants table for a list of valid values.

<Number> layerId

Unique ID of the layer that the FeatureLayer was contructed against.

<Number> maxScale

Maximum visible scale for the layer. If the map is zoomed in beyond this scale, the layer will not be visible. A value of 0 means that the layer does not have a maxium scale.

<Number> minScale

Minimum visible scale for the layer. If the map is zoomed out beyond this scale, the layer will not be visible. A value of 0 means that the layer does not have a minimum scale.

<String> name

The name of the layer as defined in the map service.

<String> objectIdField

The name of the field that contains the Object ID field for the layer.

<Object[]> relationships

Each element in the array is an object that describes the layer's relationship with another layer or table. Use the queryRelatedFeatures method to retrieve features or records related to a feature in this layer. The object has the following properties:

<Number> id Unique ID for the relationship
<String> name Name of the relationship.
<Number> relatedTableId Unique ID of the related table or layer
Code snippets:
var relationships = wellFeatureLayer.relationships;
dojo.forEach(relationships,function(relationship){
  console.log("name: " + relationship.name);
  console.log("id: " + relationship.id);
  console.log("relationship id: "   + relationship.relatedTableId);
});

See also:
queryRelatedFeatures  

<Renderer> renderer

The renderer for the layer.

<FeatureTemplate[]> templates

An array of feature templates defined in the Feature Service layer. Only applicable for ArcGIS Server Feature Service layers.
Code snippets:
var templates = layer.templates;
dojo.forEach(templates,function(template){
   console.log(template.description);
   console.log(template.name);
});

<TimeInfo> timeInfo

Time information for the layer, such as start time field, end time field, track id field, layers time extent and the draw time interval. Only applicable if the layer is time aware.

<String> type

Specifies the type of layer. Can be "Feature Layer" or "Table".

<String> typeIdField

The field that represents the Type ID field. Only applicable for ArcGIS Server Feature Service layers.

<FeatureType[]> types

An array of sub types defined in the Feature Service layer. Only applicable for ArcGIS Server Feature Service layers.

<Number> version

The version of ArcGIS Server where the layer is published. Examples are 9.3, 9.3.1, 10, 10.01. (As of v2.1)
Methods Detail

addAttachment(objectId, formNode, callback?, errback?)

Add an attachment to the feature specified by the ObjectId. Only applicable if isEditable and hasAttachments are true.
Return value: dojo.Deferred
Input Parameters:
<Number> objectId Required The ObjectId of the feature to which the attachment is added.
<HTMLFormElement> formNode Required HTML form that contains a file upload field pointing to the file to be added as an attachment.
<Function> callback Optional The function to call when the method has completed. The arguments in the function are the same as the addAttachmentComplete event.
<Function> errback Optional An error object is returned if an error occurs during task execution.
See also:
onAddAttachmentComplete  

applyEdits(adds?, updates?, deletes?, callback?, errback?)

Apply edits to the feature layer. Only applicable for layers in a feature service.
Return value: dojo.Deferred
Input Parameters:
<Graphic[]> adds Optional Array of features to add to the layer in the feature service. New features are typically created using the Draw toolbar.
<Graphic[]> updates Optional

Array of features whose geometry and/or attributes have changed. Features must have a valid OBJECTID. The geometry of features is typically modified using the Edit toolbar. Attributes are modified using the Attribute Inspector.

<Graphic[]> deletes Optional Array of features to delete. Must have valid ObjectId
<Function> callback Optional This function will be called when the operation is complete. The arguments passed to this function are the same as the onEditsComplete event.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
 var targetGraphic = firePerimeterFL.getSelectedFeatures()[0].setGeometry(reshapedGeometry);
 firePerimeterFL.applyEdits(null, [targetGraphic], null);
 

See also:
onEditsComplete  

clearSelection()

Clears the current selection.
Return value: FeatureLayer
See also:
onSelectionClear  

deleteAttachments(objectId, attachmentIds, callback?, errback?)

Delete one or more attachments for the feature specified by the input ObjectId. Only applicable if isEditable and hasAttachments are true.
Return value: dojo.Deferred
Input Parameters:
<Number> objectId Required The ObjectId of the feature from which the attachment is removed.
<Number[]> attachmentIds Required The array of attachment ids to delete.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.

getDefinitionExpression()

Returns the current definition expression.
Return value: String

getSelectedFeatures()

Gets the currently selected features.
Return value: Graphic[]

getSelectionSymbol()

Gets the current selection symbol.
Return value: Symbol

getTimeDefinition()

Get the current time definition applied to the feature layer.
Return value: TimeExtent
Code snippets:
timeSlider.createTimeStopsByTimeInterval(featureLayer.getTimeDefinition(), 
  1, esri.layers.TimeInfo.UNIT_HOURS);

isEditable()

Returns true if the FeatureLayer is editable. If the layer is editable the following operations can be performed.

  • Add new features.
  • Modify the geometry and attributes of existing features.
  • Delete features.
Return value: Boolean

queryAttachmentInfos(objectId, callback?, errback?)

Query for information about attachments associated with the specified ObjectIds.
Return value: dojo.Deferred
Input Parameters:
<Number> objectId Required The ObjectId for the feature to query for attachment information.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.

queryCount(query, callback?, errback?)

Get a count of the number of features that satisfy the input query. Valid only for layers published using ArcGIS Server 10 SP1 or greater. Layers published with earlier versions of ArcGIS Server return an error to the error callback. (As of v2.1)
Return value: dojo.Deferred
Input Parameters:
<Query> query Required

The input query. The query object has the following restrictions to avoid conflicts between layer and map properties.

  • outFields specified by the query object are overriden by the outFields specified in the FeatureLayer constructor.
  • The returnGeometry value specified by the query object is ignored and true is used.
  • The outSpatialReference set by the query object is ignored and the map's spatial reference is used.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
var query = new esri.tasks.Query();
query.where = "POP90_SQMI < 100";
featureLayer.queryCount(query,function(count){
  console.log(count + " features satisfied the input query");
},function(error){
  console.log(error);
});      

queryFeatures(query, callback?, errback?)

Query features from the feature layer. Layer definition and time definition are honored. Whenever possible the feature layer will perform the query on the client.
Return value: dojo.Deferred
Input Parameters:
<Query> query Required

The input query. The query object has the following restrictions to avoid conflicts between layer and map properties.

  • outFields specified by the query object are overriden by the outFields specified in the FeatureLayer constructor.
  • The returnGeometry value specified by the query object is ignored and true is used.
  • The outSpatialReference set by the query object is ignored and the map's spatial reference is used.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
var query = new esri.tasks.Query();
query.objectIds = [features[0].attributes.OBJECTID];
query.outFields = [ "*" ];
// Query for the features with the given object ID
featureLayer.queryFeatures(query, function(featureSet) {
});

See also:
onQueryFeaturesComplete  

queryIds(query, callback?, errback?)

Query for ObjectIds. There is no limit on the number of ObjectIds that are returned from the server. Like queryFeatures this operation will perform queries on the client (browser) whenever possible.
Return value: dojo.Deferred
Input Parameters:
<Query> query Required

The input query. The query object has the following restrictions to avoid conflicts between layer and map properties.

  • outFields specified by the query object are overriden by the outFields specified in the FeatureLayer constructor.
  • The returnGeometry value specified by the query object is ignored and true is used.
  • The outSpatialReference set by the query object is ignored and the map's spatial reference is used.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
// create a query to fetch object IDs for all records
var query = new esri.tasks.Query();
query.where = "1=1";

featureLayer.queryIds(query, function(objectIds) {
  //do something with the objectIds here
});

See also:
onQueryIdsComplete  

queryRelatedFeatures(relQuery, callback?, errback?)

Query features or records, from another layer or table, related to features in this layer.
Return value: dojo.Deferred
Input Parameters:
<RelationshipQuery> relQuery Required The input query.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
var relatedQuery = new esri.tasks.RelationshipQuery();
relatedQuery.outFields = ["AGREE_WITH_INCIDENT"];
relatedQuery.relationshipId = 1;

//query for the features related to the "clicked" feature
dojo.connect(featureLayer, "onClick", function(evt) {
  graphicAttributes = evt.graphic.attributes;
  relatedQuery.objectIds = [graphicAttributes.OBJECTID];
  featureLayer.queryRelatedFeatures(relatedQuery,relatedRecords);
}

refresh()

Refreshes the features in the feature layer. The feature layer requeries all the features in the service, except the selected features, and updates itself.
Return value: none

selectFeatures(query, selectionMethod?, callback?, errback?)

Selects features from the FeatureLayer. Layer properties like layer definition and time definition are honored. The selection method defines how query results are passed to the selection. The feature layer will highlight the current selection if a selection symbol has been defined. Whenever possible, the feature layer will perform the query operation on the client (browser).
Return value: dojo.Deferred
Input Parameters:
<Query> query Required

The input query. The query object has the following restrictions to avoid conflicts between layer and map properties.

  • outFields specified by the query object are overriden by the outFields specified in the FeatureLayer constructor.
  • The returnGeometry value specified by the query object is ignored and true is used.
  • The outSpatialReference set by the query object is ignored and the map's spatial reference is used.
<Number> selectionMethod Optional The selection method defines how the restul of the selection is combined with the existing selection. See Constants table for valid values. The default option is to create a new selection.
<Function> callback Optional The function to call when the method has completed. The arguments in the function are the same as the onSelectionComplete event.
<Function> errback Optional An error object is returned if an error occurs.
Code snippets:
  var query = new esri.tasks.Query();
  query.geometry = feature.geometry;
  featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);

See also:
onSelectionComplete  

setDefinitionExpression()

Set's the definition expression for the FeatureLayer. Only the features that match the definition expression are displayed. A definition expression limits the features available for display and queries by applying constraints to the layer's attribute fields. Setting a definition expression is useful when the dataset is large and you don't want to bring everything to the client for analysis. This method is typically called before adding the layer to the map. If the method is called after the layer is added to the map the layer will refresh itself to reflect the new definition expression.

This definition expression is combined with the layer's default definition expression which results in a further restriction of the layer.

Return value: FeatureLayer
Code snippets:
  featureLayer.setDefinitionExpression("STATE_NAME = 'South Carolina'");

setOpacity(opacity)

Initial opacity or transparency of layer. Not supported in Internet Explorer.
Return value: none
Input Parameters:
<Number> opacity Required Value from 0 to 1, where 0 is 100% transparent and 1 has no transparency. The default value is 1.
Code snippets:
  featureLayer.setOpacity(.50);

setRenderer(renderer)

Set the renderer for the feature layer.
Return value: none
Input Parameters:
<Renderer> renderer Required The renderer to apply to the feature layer
Code snippets:
var symbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,0,0,0.5]));
var renderer = new esri.renderer.SimpleRenderer(symbol);
featureLayer.setRenderer(renderer);

setSelectionSymbol(symbol)

Set's the selection symbol for the feature layer. If no symbol is specified, features are drawn using the layer's renderer.
Return value: FeatureLayer
Input Parameters:
<Symbol> symbol Required Symol for the current selection. Make sure the symbol type is appropriate for the geometry type of the layer.
Code snippets:
var selectionSymbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,255,0,0.5]));
featureLayer.setSelectionSymbol(selectionSymbol);

setTimeDefinition(definition)

Set's the time definition for the feature layer. A time definition temporarily filters the features in the layer to match the specified time extent. Only applicable for time-aware layers. Only supported when the feature layer is in snapshot mode.

In addition to time definition, time-aware layers also support the time extent set on the map. Time-aware layers automatically update when the map's time extent is changed, similar to how layers react when the map's spatial reference is modified. If a layer's time defintion is set to display features between 1970 and 1975 and the map has a time extent set to 1972-1980, the effective time on the feature layer will be 1972-1975

Return value: FeatureLayer
Input Parameters:
<TimeExtent> definition Required The new time extent used to filter the layer.
Code snippets:
  var defn = new esri.TimeExtent();
  defn.startTime = new Date("November 30,2009 6:00:00")
  defn.endTime = new Date("November 30, 2009 8:00:00");
  featureLayer.setTimeDefinition(defn);

setTimeOffset(offsetValue, offsetUnits)

Time offset allows you to display the features at a different time so they can be overlayed on top of previous or future time periods. For example, to visualize the growth pattern of two wild fires that happened in two different years, one of the layers can be given an offset that will cause it to appear as if the fire started at the same time as the other fire. Note that the offset does not change the temporal component of the data itself and has no effect if the layer is not time aware.

Example: If a layer has data recorded for the year 1970, an offset value of 2 years would temporarily shift the data to 1972 (for display purposes only, query and selection are not affected by offset).

Return value: FeatureLayer
Input Parameters:
<Number> offsetValue Required The length of time to offset from "this" time. Specify a positive or negative whole number.
<String> offsetUnits Required Units in wich the offset is specified. See the TimeInfo constants for valid values.

toJson()

Returns an easily serializable object representation of the layer.Regardless of the layer's mode of operation, only features currently available on the client are included.

{
  layerDefinition: <Object>,
    featureSet: {
    features:<Object[]>
  }
}
Return value: Object

Events Detail

onAddAttachmentComplete(result)

Fires when addAttachments() is complete.
Arguments:
<FeatureEditResult> result The result of the addAttachment operation indicating if the attachment was sucessfully added.
See also:
addAttachment  

onBeforeApplyEdits(adds, updates, deletes)

Fired before edits are applied to the feature layer.
Arguments:
<Graphic[]> adds Array of features to add to the layer in the feature service.
<Graphic[]> updates Array of features whose geometry and/or attributes have changed.
<Graphic[]> deletes Array of features to delete.

onDblClick(event)

Fires when a feature has been double clicked.
Arguments:
<Object> event The returned object contains screenPoint, mapPoint, and graphic.
Code snippets:
dojo.connect(firePerimeterFL, "onDblClick", function(evt) {
  editToolbar.activate(esri.toolbars.Edit.EDIT_VERTICES , evt.graphic);
});

onDeleteAttachmentsComplete(results)

Fires when deleteAttachments is complete.
Arguments:
<FeatureEditResult[]> results The result objects, one for each attachment indicating if it was succesfully removed.
See also:
deleteAttachments  

onEditsComplete(addResults, updateResults, deleteResults)

Fires after applyEdits() has been called.
Arguments:
<FeatureEditResult[]> addResults An array of result objects, one for each feature, indicating if it was successfully added. If the feature was added the result object will contain the unique object ID assigned to the feature.
<FeatureEditResult[]> updateResults An array of result objects, one for each feature, indicating if it was successfully updated.
<FeatureEditResult[]> deleteResults An array of result objects, one for each feature, indicating if the it was successfully deleted.
See also:
applyEdits  

onQueryAttachmentInfosComplete(attachmentInfos)

Fires when queryAttachmentInfos() is complete.
Arguments:
<Object[]> attachmentInfos Information about the attachments associated with the feature. Each element in this array is an object with the following properties: objectId,url,id,name,contentType,size.
See also:
queryAttachmentInfos  

onQueryCountComplete(count)

Fires when the query for the count is complete. This event is only available for layers published using ArcGIS Server 10 SP1 or later. (As of v2.1)
Arguments:
<Number> count The number of features that satisfy the input query.
Code snippets:
dojo.connect(featureLayer,'onQueryCountComplete',function(count){
  console.log(count + " features satisfied the input query");
});

onQueryFeaturesComplete(featureSet)

Fires when queryFeatures() is complete.
Arguments:
<FeatureSet> featureSet The FeatureSet returned from the query.
See also:
queryFeatures  

onQueryIdsComplete(ids)

Fires when queryIds() is complete.
Arguments:
<Number[]> ids Array of ObjectIds returned from the query.
See also:
queryIds  

onQueryRelatedFeaturesComplete(relatedFeatures)

Fires when queryRelatedFeatures() is complete.
Arguments:
<Object> relatedFeatures An object that contains feature sets. Each feature set contains features, from the target layer/table, related to the source feature. In the example bleow 15 and 9 are the object IDs of the features in the source layer/table.
{
  "15": <FeatureSet1>,
  "9":  <FeatureSet2>
}
See also:
queryRelatedFeatures  

onSelectionClear()

Fires after clearSelection has been called.
See also:
clearSelection  

onSelectionComplete(features, selectionMethod)

Fires when selectFeatures() has completed. OnSelectionComplete always fires unless there is an error returned by the server.
Arguments:
<Graphic[]> features Features returned from the query.This does not equal the current selection, call getSelectedFeatures() to retrieve the current selection set.
<Number> selectionMethod Selection method used in the selectFeatures method.
See also:
selectFeatures  

onUpdateEnd(error)

Fired when the layer has finished updating its content. This event is always preceded by onUpdateStart
Arguments:
<Error> error Optional argument available when an error occurs during the update.

onUpdateStart()

Fired when the layer begins to update its content. The following table describes when the event is fired in various modes.
Snapshot
  • When the layer is added to the map.
  • When layer properties such as definition expression, time definition or time offset are modified.
  • When the map's time extent changes.
  • When the layer is refreshed.
OnDemand
  • When the layer is added to the map.
  • When the map's spatial extent or time extent changes.
  • When layer properties such as definition expression or time offset are modified.
  • When the layer is refreshed.
Selection The event is not fired in selection mode.