Create a FeatureLayer with client side graphics

This device does not support 3D.

View the system requirements for more information.

This sample shows how to create a Feature Layer from client side graphics. The graphics are created from GeoJSON earthquake data requested from the USGS. After the graphics are created, they are added to a FeatureLayer.

Creating a FeatureLayer with client-side graphics requires four properties be set on the layer.

  1. The array of graphics must be set on the source property.
  2. The geometryType of the features must be specified (all features must have the same geometry type).
  3. The spatialReference of the features must be specified.
  4. An array of fields objects providing the schema (name, alias, and type) of each attribute field must be provided.
  5. And the objectID field must be specified.
lyr = new FeatureLayer({
  source: graphics,  // autocast from an array of esri/Graphic
  // create an instance of esri/layers/support/Field for each field object
  fields: fields,
  objectIdField: "ObjectID",
  geometryType: "point",
  spatialReference: { wkid: 4326 },

  popupTemplate: pTemplate,
  renderer: quakesRenderer  // set the visualization on the layer
});

map.add(lyr);

Once the graphics are set on the layer, other layer properties, such as renderer and popupTemplate may be set, allowing you to leverage the benefits of a FeatureLayer for client-side graphics. Unlike FeatureLayer, the GraphicsLayer does not support renderer and popupTemplate properties.

Sample search results

TitleSample

There were no match results from your search criteria.