Update FeatureLayer using applyEdits()

Loading...

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

This sample demonstrates how to use FeatureLayer.applyEdits() to create new features, update attributes of existing features or delete existing features. This sample uses the FeatureForm widget to update attributes of existing features.

In this sample, the applyEdits function is called when a user either:

  • Clicks to create a new feature.
  • Selects a feature on the view and updates its attributes.
  • Selects a feature on the view and deletes it.
// Call FeatureLayer.applyEdits() with specified params.
function applyEdits(params) {
  unselectFeature();
  featureLayer.applyEdits(params).then(function(editsResult) {
    // Get the objectId of the newly added feature.
    // Call selectFeature function to highlight the new feature.
    if (editsResult.addFeatureResults.length > 0) {
      const objectId = editsResult.addFeatureResults[0].objectId;
      selectFeature(objectId);
    }
  })
  .catch(function(error) {
    console.log("===============================================");
    console.error("[ applyEdits ] FAILURE: ", error.code, error.name,
      error.message);
    console.log("error = ", error);
  });
}

FeatureLayer.applyEdits() resolves to an object containing edit results. If the edit failed, the edit result includes an error.

Sample search results

TitleSample
Loading...