Edit Geometry of a Feature in Feature Layer without Editor Widget

1735
4
Jump to solution
04-02-2019 10:01 AM
NaveedAhmed2
New Contributor III

Is this possible with JS API 4.x to edit geometry of a feature in a Feature Layer without using Editor Widget. Something like we are doing in 3.x in the sample below

https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=ed_feature_creation

I am asking this question because SketchViewModel and Sketch widgets work with GraphicsLayer. I will appreciate the proposed solution. 

Thanks

0 Kudos
1 Solution

Accepted Solutions
NaveedAhmed2
New Contributor III

Hi Noah,

Thank you for your reply. I was looking for to update features geometry instead of just updating the attributes without using Editor widget of 4.x API. Since in 3.x we were using Draw widget to update the geometry of a feature from Feature Layer and then we were saving these changes through applyEdits() as shown in the sample.

The sample you are referring to only shows how we can just update the attributes of a feature through applyEdits(). I read the documentation of the 4.11 version of JSAPI and found that SketchViewModel works only for a GraphicsLayer and we cannot use it directly to modify the geometry of a feature in Feature Layer. So I modify the code that creates a temporary graphic in a Graphics Layer based on the feature that is desired to be moved (update its geometry) so that users can update the geometry of that graphics by selecting it. I am using applyEdits() to update that graphic back in the original feature layer. 

Codepen for the code can be referred at https://codepen.io/naveeed/pen/XQXdEe

I believe this sample can be extended to polyline and polygon features as well.

I think this solves my problem.

View solution in original post

0 Kudos
4 Replies
Noah-Sager
Esri Regular Contributor

Hi Naveed, do you mean something like using the applyEdits() method of the FeatureLayer? If so, we have a sample for that from our 4.10 release:

https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/index.html

NaveedAhmed2
New Contributor III

Hi Noah,

Thank you for your reply. I was looking for to update features geometry instead of just updating the attributes without using Editor widget of 4.x API. Since in 3.x we were using Draw widget to update the geometry of a feature from Feature Layer and then we were saving these changes through applyEdits() as shown in the sample.

The sample you are referring to only shows how we can just update the attributes of a feature through applyEdits(). I read the documentation of the 4.11 version of JSAPI and found that SketchViewModel works only for a GraphicsLayer and we cannot use it directly to modify the geometry of a feature in Feature Layer. So I modify the code that creates a temporary graphic in a Graphics Layer based on the feature that is desired to be moved (update its geometry) so that users can update the geometry of that graphics by selecting it. I am using applyEdits() to update that graphic back in the original feature layer. 

Codepen for the code can be referred at https://codepen.io/naveeed/pen/XQXdEe

I believe this sample can be extended to polyline and polygon features as well.

I think this solves my problem.

0 Kudos
MohamadMousheimish1
New Contributor II

Hi Naveed,

I'm intending to do what you was looking for (Updating the geometry (Shape) of a specific feature) and not only the attribute.

I've opened the link provided in your reply, I couldn't update any shape, I was only able to move point from a specific point to another.

Any suggestions please?

Regards.

0 Kudos
NaveedAhmed2
New Contributor III

Hi Mohamad,

Sorry about the late response. I did not get a chance for a while to use this account.

Do you mean that you are not able to access the codepen page below, although it is still working for me even I open it in the incognito window of my browser? You can also try it in other browsers, pc or incognito mode.

https://codepen.io/naveeed/pen/XQXdEe 

Let me know if you still have this problem.

Thanks,

Naveed

0 Kudos