Caught in an Async issue

195
2
Jump to solution
08-23-2019 03:46 PM
SteveCole
Frequent Contributor

I've been trying for 2 days to figure this out and I just can't. I believe that I'm experiencing an issue with inputs are available when needed because they're generated async and they're not ready when they're called upon.

My app asks the user to specify a local folder location (using the HTML 5 File functionality) and then it reads in the files of the specified folder to filter out the image files. Using the list of image files, I want it to then map the photo locations by creating a Feature Layer using a feature collection. This is accomplished by using an EXIF reading JS library to extract out the lat/long of any geotagged photos while looping through the list of image files. Well, that's the theory.

In practice, the array generated of my feature collection is never populated when the code needs it during the featureLayer creation. I think the process of looping through the files is still happening and so the feature collection isn't populated. I've tried to implement promises,thens,  & async/await and I have repeatedly failed.

Here is the link to my Fiddle.

In order to "run" the app, you just need a local folder with at least one geotagged photo in it. Run the app, click the Browse button to select the folder and that's it.

Steve

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

I have not run the your test app but have looked through the code quickly. When you are adding, removing or updating graphics in FeatureCollection you need to FeatureLayer.applyEdits method. 

I have created a simple test app to show the workflow to add client side graphics to a featurecollection at runtime. To use the app, click the button right under the zoom in/out buttons. 

Some useful links:

See Add an array of client-side features section under creating a featurelayer section.

Hope this helps,

-Undral

View solution in original post

2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

I have not run the your test app but have looked through the code quickly. When you are adding, removing or updating graphics in FeatureCollection you need to FeatureLayer.applyEdits method. 

I have created a simple test app to show the workflow to add client side graphics to a featurecollection at runtime. To use the app, click the button right under the zoom in/out buttons. 

Some useful links:

See Add an array of client-side features section under creating a featurelayer section.

Hope this helps,

-Undral

SteveCole
Frequent Contributor

Thanks for your help. It has taken a few days of digesting & tinkering but I feel I'm now back on track. I was already doing some of what you had suggested in your response but tweaking my app to more closely follow your sample was the right call. Honestly, I'm still having the async issue even with your code as a roadmap but, prior to me seeing your post, I added a setTimeout() block in my code and that was enough to prevent the operation from overrunning itself.

I should also note that your response in this thread about an applyEdits issue was also helpful. Thanks again!

Steve

0 Kudos