Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample shows how to create a FeatureLayer from client-side graphics. The graphics are created from a shapefile that you can upload into the application. After the graphics are created, they are added to a FeatureLayer.

To run the sample, download the shapefile using the Expand widget in the top right, then add the zipped file.

Note that this sample demonstrates creating a FeatureLayer with client-side graphics, using the shapefile as an example format.

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

  1. The array of graphics must be set on the source property. All graphics must have the same geometry type.
  2. The geometryType of the layer is inferred from the graphics provided in the source and therefore doesn't have to be explicitly set by the developer.
  3. The spatialReference of the features is inferred by the geometries provided in the source and therefore doesn't have to be explicitly set by the developer.
  4. An array of field objects providing the schema (name, alias, and type) of each attribute field must be provided by the developer.
  5. The objectID field must be specified.
var layer = new FeatureLayer({
  source: graphics, // autocast from an array of esri/Graphic
  objectIdField: "FID",
  popupTemplate: pTemplate,
});

map.add(layer);

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
Loading...