mapView.identifyLayer outside of touch event?

916
2
Jump to solution
10-03-2019 10:00 AM
TravisYordi
New Contributor II

I have a custom view that sits on top of the map that has a list of misc images (a toolbar of sorts). Each image has the ability to be dragged across the screen and then wherever they drop the image, I would like to be able to perform the mapView.identifyLayer method to identify/read layer data from the screen point where the drop occurred.  When this method is called outside of a touch event, it goes into the function, but it never returns with a completion.  It hangs forever.  The same code works fine when called inside the geoView 'didTapAtScreenPoint' event.

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

I assume you are calling self.mapView.identifyLayer() from the main thread, and so I'm pretty sure that what's happening is that you're blocking the main thread with your group.wait() call and then the mapView is blocked when it tries to call back into your completion closure.  You can learn more about Runtime and threading here: https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-ios/blo... 

Rather than forcing a synchronous pattern into your function, you should define getFeatureDataAtLocation() with a callback method too. See my answer to a not entirely unrelated question from yesterday.

Perhaps one day Swift will finally adopt async  but until then you should use this pattern.

View solution in original post

2 Replies
Nicholas-Furness
Esri Regular Contributor

I assume you are calling self.mapView.identifyLayer() from the main thread, and so I'm pretty sure that what's happening is that you're blocking the main thread with your group.wait() call and then the mapView is blocked when it tries to call back into your completion closure.  You can learn more about Runtime and threading here: https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-ios/blo... 

Rather than forcing a synchronous pattern into your function, you should define getFeatureDataAtLocation() with a callback method too. See my answer to a not entirely unrelated question from yesterday.

Perhaps one day Swift will finally adopt async  but until then you should use this pattern.

TravisYordi
New Contributor II

You're absolutely right... I'm a bonehead : )  I do get results when I add a callback/completion to getFeatureDataAtLocation().

Thank you for the help!