Select to view content in your preferred language

Getting attribute information for deletedFeature

220
4
Jump to solution
08-06-2024 03:44 AM
Aeseir
by
Frequent Contributor

We have a feature layer that is created client side e.g.

const featureLayer = new FeatureLayer({
      title: "Test",
      geometryType: "polygon",
      objectIdField: "ObjectID",
      fields: [
        {
          name: "ObjectID",
          alias: "ObjectID",
          type: "oid"
        },
        {
          name: "id",
          alias: "id",
          type: "guid"
        },
        {
          name: "type",
          alias: "Type",
          type: "string"
        },
        {
          name: "identifiedMarkerID",
          alias: "identifiedMarkerID",
          type: "string"
        },
        {
          name: "recordedDate",
          alias: "recordedDate",
          type: "date"
        }
      ],
      source: [],
      spatialReference: view.spatialReference
    });

 

we then listen to the featurelayer event "edits" and key changes get pushed to server.

problem is that deletedFeatures doesn't show attributes of the said deleted feature, only objectId and globalId, there is no way to access attributes to get the identifiedMarkerID.

we need to be able to record that a feature with identifiedMarkerID that was deleted so if we get audited, we can see that feature was removed and when.

we use the editor widget to handle all the client side feature addition/modification/removal.

Any advice on how to do this.

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

There doesn't seem to be a "natural" way to do this since by the time "edits" has been fired, the feature has been deleted, with no way to get its info from the layer anymore.  The widget otherwise provides nothing like a "before-edits" event, which would be helpful in this regard.  I see a couple options here though.

First, you could put logic between the "edits" event and your changes getting pushed to the server.  In this intermediate step, you could get the feature's data from the server before sending the information to the server about the feature being deleted.  This kind of workflow would require an extra server request being added to your overall workflow, and so would be somewhat inefficient, since you'd be sending a network request to get information that existed on your client less than a second ago.

The other option is to add a hack that gets you a reference to the feature before it gets deleted.  The best way appears to be by overriding the deleteFeatureFromWorkflow method of the Editor widget, because this method gets called immediately after the final "Delete" button on the widget is clicked, but before the delete operation actually takes place.  Therefore, this would be the ideal place to examine the attributes of any features being deleted:

var editor = new Editor({view:view});

var deleteFeatureFromWorkflow = editor.deleteFeatureFromWorkflow;

editor.deleteFeatureFromWorkflow = function() {
	//This is the array of graphics being deleted
	var graphics = editor.activeWorkflow.data.candidates;

	graphics.forEach(function(graphic) {
		//Do something with the graphic reference here
		console.log("identifiedMarkerID: " + graphic.attributes.identifiedMarkerID;
	});

	return deleteFeatureFromWorkflow.apply(this, arguments);
};

 

View solution in original post

4 Replies
JoelBennett
MVP Regular Contributor

There doesn't seem to be a "natural" way to do this since by the time "edits" has been fired, the feature has been deleted, with no way to get its info from the layer anymore.  The widget otherwise provides nothing like a "before-edits" event, which would be helpful in this regard.  I see a couple options here though.

First, you could put logic between the "edits" event and your changes getting pushed to the server.  In this intermediate step, you could get the feature's data from the server before sending the information to the server about the feature being deleted.  This kind of workflow would require an extra server request being added to your overall workflow, and so would be somewhat inefficient, since you'd be sending a network request to get information that existed on your client less than a second ago.

The other option is to add a hack that gets you a reference to the feature before it gets deleted.  The best way appears to be by overriding the deleteFeatureFromWorkflow method of the Editor widget, because this method gets called immediately after the final "Delete" button on the widget is clicked, but before the delete operation actually takes place.  Therefore, this would be the ideal place to examine the attributes of any features being deleted:

var editor = new Editor({view:view});

var deleteFeatureFromWorkflow = editor.deleteFeatureFromWorkflow;

editor.deleteFeatureFromWorkflow = function() {
	//This is the array of graphics being deleted
	var graphics = editor.activeWorkflow.data.candidates;

	graphics.forEach(function(graphic) {
		//Do something with the graphic reference here
		console.log("identifiedMarkerID: " + graphic.attributes.identifiedMarkerID;
	});

	return deleteFeatureFromWorkflow.apply(this, arguments);
};

 

Aeseir
by
Frequent Contributor

I like it, i hacked a different approach but yours essentially creates a lifecycle hook.

0 Kudos
JoelBennett
MVP Regular Contributor

Nice, good to hear you got it working.  The description of the arguments object here is definitely better than what I would come up with.  By calling apply with the arguments object, it ensures the function being called is executed with the same arguments (if any) that were passed to the current function.

Aeseir
by
Frequent Contributor

Yep sorry i removed my query about arguments, brain wasn't fully operating when I finally got it to work.

0 Kudos