Select to view content in your preferred language

Can I query a feature before its permanently deleted by the editor?

154
1
Jump to solution
a month ago
JMMFIRE
New Contributor II

I'm experimenting with designing a method by which I can undo/redo feature adds, updates, and deletes in conjunction with the Editor widget. I currently have event listeners for these on my layers that would take advantage this functionality. The methodology I'm using would require me to obtain the feature and include that, along with some other data, in an array that stores the actions that have been completed. 

The problem I'm facing is that I have no way to query a feature before it has been deleted. If I were to query a feature in the `if (featureLayerEditsEvent.deletedFeatures[0]?.objectId)` block (like I do below) the query will return empty since the feature has already been deleted by the time the query is executed. 

I was wondering if there may be an event I can listen to that occurs before the delete is confirmed?

Here's how I currently have my layer edits listener set up for reference: 

    this.groupLayer.on('edits', async (featureLayerEditsEvent: __esri.FeatureLayerEditsEvent) => {
      console.log('featureLayerEditsEvent', featureLayerEditsEvent);

      if (featureLayerEditsEvent.addedFeatures[0]?.objectId) {

        const getEdittingGraphicQueryParams = {
          where: `objectId = ${featureLayerEditsEvent.addedFeatures[0].objectId}`,
          outFields: ['*'],
        };

        const innerFeatureSet: FeatureSetTyped<GroupItemData> = await this.groupLayer.queryFeatures(getEdittingGraphicQueryParams);

        pushCompletedAction(new DiagramAction('add', innerFeatureSet.features[0], this.groupLayer));

        this.createGroupedGraphic(featureLayerEditsEvent.addedFeatures[0].objectId, this.groupLayer)
          .then(() => {
            this.editor.cancelWorkflow()
              .then(() => {
                mapView.ui.remove(this.editor);
              })
              .catch((error: unknown) => {
                console.error('Error starting update workflow:', error);
              });
          })
          .catch((error: unknown) => {
            console.error('Error creating grouped graphic:', error);
          });

      } else if (featureLayerEditsEvent.updatedFeatures[0]?.objectId) {
        const getEdittingGraphicQueryParams = {
          where: `objectId = ${featureLayerEditsEvent.updatedFeatures[0].objectId}`,
          outFields: ['*'],
        };

        const innerFeatureSet: FeatureSetTyped<GroupItemData> = await this.groupLayer.queryFeatures(getEdittingGraphicQueryParams);

        // Pushing the completed action has to be handled differently for an edit. 
        // on edits is fired twice when moving a graphic: once when moving and then again when submitted.
        action = new DiagramAction('edit', innerFeatureSet.features[0], this.groupLayer);

      } else if (featureLayerEditsEvent.deletedFeatures[0]?.objectId) {
        const getEdittingGraphicQueryParams = {
          where: `objectId = ${featureLayerEditsEvent.deletedFeatures[0].objectId}`,
          outFields: ['*'],
        };

        const innerFeatureSet: FeatureSetTyped<GroupItemData> = await this.groupLayer.queryFeatures(getEdittingGraphicQueryParams);

        pushCompletedAction(new DiagramAction('delete', innerFeatureSet[0], this.groupLayer));

        featureLayerEditsEvent.deletedFeatures.forEach(() => {

          if (this.selectedGraphics.length > 0) {
            this.selectedGraphics.forEach((selectedGraphic) => {
              this.removeGroupedGraphic(selectedGraphic);
            });
          } else {
            this.removeGroupedGraphic(editingGraphic);
          }
        });
        doneEditing();

        this.editor.cancelWorkflow()

          .catch((error: unknown) => {
            console.warn('Error canceling workflow:', error);
          });
      }
    });



0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

This thread shows how to get a reference to features after the user has confirmed to delete them, but prior to them actually being deleted.

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

This thread shows how to get a reference to features after the user has confirmed to delete them, but prior to them actually being deleted.