Refresh a single feature on FeatureLayer

335
2
Jump to solution
05-26-2023 05:14 AM
LucasBertoni
New Contributor II

On my app I have a MapView with a FeatureLayer, sometimes a feature is added to that FeatureLayer in the backend as part of a separate user flow and my javascript application receives its id.

The new feature is displayed after I call .refresh() on my FeatureLayer but that forces a full reload of the data which seems like a waste.

So my question is: provided I have an objectId of a feature that was added in the background, how can I make my FeatureLayer/MapView display it in the most optimal way?

When I add a feature using the applyEdits function from the FeatureLayer I notice that a more focused refresh is done (not as many calls as a refresh), so there seems to be a way and I can't find any documentation about it.

Thanks in advance.

1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

As you figured out already, the refresh does not support the workflow you are asking for. It is something we plan on supporting in the future. 

Is your app using MapView? Then as you suggested you can use applyEdits for more focused refreshes. Can you please see if the workaround works? If the layer emits an edit event with the updated, added, or removed features, that triggers the refresh of that feature. https://codepen.io/ycabon/pen/BaqENbb?editors=0010

 

View solution in original post

2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

As you figured out already, the refresh does not support the workflow you are asking for. It is something we plan on supporting in the future. 

Is your app using MapView? Then as you suggested you can use applyEdits for more focused refreshes. Can you please see if the workaround works? If the layer emits an edit event with the updated, added, or removed features, that triggers the refresh of that feature. https://codepen.io/ycabon/pen/BaqENbb?editors=0010

 

LucasBertoni
New Contributor II

Hi @UndralBatsukh thanks for your reply, the workaround worked perfectly, it causes the same effect as if I had used the clientside `applyEdits` function.

I had tried emitting that event before posting here, but my mistake was not adding all the empty arrays to the event object, as soon as I added them it started working as expected.

Thanks again.

0 Kudos