Any ideas how to limit the number of features a user can create using the Editor widget?

742
1
10-11-2019 02:11 PM
JackHardwick
New Contributor II

I'm building what basically amounts to a GeoForm where users will be prompted to create a polygon and a point feature for their survey response. I am using the Editor Widget to do this and I'm beginning to understand the different workflow sections that are initiated at each point of the create and update workflows. For this survey, we'd like users to only submit one type of each feature geometry. My attempt can be described as follows:

Use the whenLayerView() method on the point and polygon layers. If the layer loads successfully, with each mouse click check the amount of records, if the amount of records is equal to 1, turn off the adding capability for that layer. 

I can tell this isn't a great way of doing what I want as it doesn't update the layerInfos quickly enough by the time the workflow repeats back to stage 1 after the initial feature addition. I suppose that when the user clicks the "add" button of the editor that the current creationInfo isn't being refreshed for the editorViewModel? Usually once the workflow has been changed back and forth from create to update, I can see the new layerInfos updating and removing my creation abilities for that layer. This provides far too much wiggle room however and simply won't do. 

Is there a simple way to catch when a feature is being updated, prevent more inputs until the feature has updated, then refresh the editor to display the new creation abilities?

Any advice for how I should proceed or a better way to approach this problem? Thanks!

0 Kudos
1 Reply
JackHardwick
New Contributor II

I'm recognizing some shortcomings in my understanding of Javascript. I figured out a less than elegant way of doing what I wanted. On mouse clicks in the document, check the number of features in my point or polygon layers. If the result of this query is equal to 1, remove the editor widget, change the setting, and re-add it. This wasn't bringing the user back to the initial workflow start, so I have it reset the active workflow as well. This isn't a perfect fix as the user can still initially see the polygon/point template appear back at step 1 of the workflow, but if they click on it, it resets the workflow completely and removes the option without letting them proceed further. Any advice for a better way to do this is still welcome! 

0 Kudos