Hello,
I am using version 4.24.
I have a FeatureLayer and I'm providing Features to it on the client-side. I construct Graphics for the coordinates returned from my application API, and put them on a map. When I hit my API after the initial and successful operation, which instantiates the FeatureLayer and provides it it's initial source (the collection of features I have constructed on the client), I would like to update the coordinates of those features on the map whenever I request an update from my API.
My assumption was that I could use `featureLayer.applyEdits` and pass along the updated features, but nothing happens. The result of that operation states that X items were updated, but the map does up change (the features remain stationary). I have also tried to delete features using `featureLayer.applyEdits` with the `deletedFeatures`... but with the same result. The result states that X items were deleted... but they're still on the map.
Before I start removing everything to put it back at new coordinates, I thought I would check to see if there is something wrong with my approach. I would hate to be removing thousands of features and putting them back, just to update their coordinates, on a regular basis.
I was able to achieve this very easily using Leaflet and MapBox previously, so I'm sure I must be missing something here...
Thanks in advance for any assistance.
Solved! Go to Solution.
Here's an example showing how you can update feature geometries using applyEdits: https://codepen.io/annefitz/pen/jOzXQxv?editors=100
I am now able to remove Features using `applyEdits` and `deletedFeatures`, but I am still not able to update the coordinates of the Features.
The mistake I made was that I was specifying a custom attribute as the `objectId`, but it was a guid. No errors were reported and my Features were rendering successfully, but the custom attribute (in my case a guid) was not appropriate for `applyEdits`. By adding another attribute with a type of `oid`, I am now able to delete the features.
I'm starting to wonder if updates are limited to attributes and not the geometry of the Graphic...
I am now able to delete, and then add new Features to get what I want. I will look into the the updateFeatures again later on and update this thread for those who are interested.
Here's an example showing how you can update feature geometries using applyEdits: https://codepen.io/annefitz/pen/jOzXQxv?editors=100
Thanks @AnneFitz 🙂
It's good to know that this is possible. I think querying the features and then updating them as you have done here is better. I have been trying to do the update by creating a feature and setting the objectId and then providing the updated geometry. Something there has been off, as I experienced with the delete comment above.
Thanks again