Select to view content in your preferred language

How can we change draw type of Editor Widget in JS API 4.x using Editor's ViewModel::SketchViewModel?

219
5
08-22-2024 08:21 AM
Vara_PrasadM_S
Frequent Contributor

Hi All,

Our requirement is to provide additional Draw Tools like - Circle, Rectangle, Ellipse etc, when a template is selected in Editor Widget (JS API 4.X). I tried to use Editor's viewModel (of type, EditorViewModel) property of Editor Widget and from that, use sketchViewModel property (of type, SketchViewModel) and call its "cancel" function (to cancel selected polygon tool - which is default) and call "create" function by passing the desired tool name as parameter (such as "circle").

Still, no change in the flow and same Polygon tool is continued to be active and could not draw any other shape. 

I could not understand where Im going wrong. I did not find much help/documentation on how to use the view models of Editor and its SketchViewModel. I also tried setting new instance of SketchViewModel, still no use.

Any help would be highly appreciated. 

Thanks in advance!

With Regards,

Vara Prasad

0 Kudos
5 Replies
AndreV
by
Regular Contributor

Hi Vara,

have you tried this property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Editor.html#supportingWid...

we used successfully to set defaultUpdateOptions and defaultCreateOptions, maybe this could help you too.

Andre

gdi-hohenlohekreis.de
0 Kudos
Vara_PrasadM_S
Frequent Contributor

Hi @AndreV , Thank you for your response. I have gone through 'defaultUpdateOptions' and 'defaultCreateOptions'. I did not find any option to set the draw type as Circle or Ellipse. 

0 Kudos
calin_gi
Occasional Contributor

Hi @Vara_PrasadM_S . I have the same issue. I didn't find a solution (yet), but as a workaround I listen to the sketch-create event on the Editor widget. Here I will draw an additional graphic as circle in the graphicslayer on state = active and on state=complete I change out the polygon geometry for a circle. I do this when the user has drawn three vertices. You can just use the first point as center point and the length of the first segment as radius, alternatively you can find the center point and radius by a formula of a circle going through the three vertices. When the user draws more vertices I go back to standard functionality. This way, at least a circle can be drawn, but as an added bonus a polygon as well.

Vara_PrasadM_S
Frequent Contributor

Hi @calin_gi, Thank you so much for the work around. I implemented it. However, I had to follow another approach for single graphic while creating a new feature. So, I had created a custom widget, where I used the FeaturesTemplate widget and on select event, gave option to select tool from Sketch Widget, and then upon creating the graphic, pushed the feature to DB through applyEdits call.

Thank you!

 

-Vara Prasad

0 Kudos
calin_gi
Occasional Contributor

Hi @Vara_PrasadM_S . Can you share your code for the custom widget? Is it a lot of effort?

0 Kudos