How to sketch on a feature layer using the sketch widget

1906
3
Jump to solution
08-02-2021 07:00 AM
Elijah-web
New Contributor

I have a feature layer hosted on a ArcGIS Online in my developer dashboard. I have seen that I can provide users with the ability to sketch on the map. My first issue is that when I on the map, when I release the cursor, whatever I have sketched just disappears. The second thing I want to know is how can I enable  a user to sketch on a feature layer. Also how can I save the sketches that the user has performed on the feature layer 

0 Kudos
1 Solution

Accepted Solutions
JoseBanuelos
Esri Contributor

Hello @Elijah-web ,

With the Sketch widget, the graphics you draw will exist on a GraphicsLayer. If you are having issues seeing the graphics you draw, it is most likely a spatial reference difference between the graphicsLayer and the view's spatial reference.

You can of course implement your own code to call FeatureLayer.applyEdits() and pass in the graphics you sketch with the Sketch widget to add the graphics to the FeatureLayer (keeping in mind that the graphics drawn and FeatureLayer must have the same spatialReference). However, it will be easier if you just utilize the Editor widget in your app. The Editor widget uses the same SketchViewModel that the Sketch widget uses. This means users of your application will be able to draw features and save them to the FeatureLayer. You don't have to add any additional code to save the changes to the layer, since the widget takes care of it.

Here are some helpful links to get you started with the Editor widget:

1. Api-reference documentation

2. Tutorial

3. 2D Editor Sample

4. 3D Editor Sample

View solution in original post

3 Replies
JoseBanuelos
Esri Contributor

Hello @Elijah-web ,

With the Sketch widget, the graphics you draw will exist on a GraphicsLayer. If you are having issues seeing the graphics you draw, it is most likely a spatial reference difference between the graphicsLayer and the view's spatial reference.

You can of course implement your own code to call FeatureLayer.applyEdits() and pass in the graphics you sketch with the Sketch widget to add the graphics to the FeatureLayer (keeping in mind that the graphics drawn and FeatureLayer must have the same spatialReference). However, it will be easier if you just utilize the Editor widget in your app. The Editor widget uses the same SketchViewModel that the Sketch widget uses. This means users of your application will be able to draw features and save them to the FeatureLayer. You don't have to add any additional code to save the changes to the layer, since the widget takes care of it.

Here are some helpful links to get you started with the Editor widget:

1. Api-reference documentation

2. Tutorial

3. 2D Editor Sample

4. 3D Editor Sample

Elijah-web
New Contributor

What is difference between using the MapView class to create a map object and using the Map class for creating the map object. Are there any differences??

0 Kudos
JoseBanuelos
Esri Contributor

Hi @Elijah-web ,

A simple way to look at this is the Map class represents the actual data (basemap + layers). The MapView is a view that allows the user to interact with the data. 

For example, you can set an extent, zoom level or scale, and a center point for your application. A user will be able to see the data at the extent you choose. They can then zoom or pan around the map to view and interact with the rest of the data. The View does not change the data, it just allows users to interact with it.

Hope this helps,

Jose

0 Kudos