I'm working on an AppStudio app that works offline. The app's webmap is created from an MMPK and contains a point layer that the user can interact with.
Here's what I want to do:
I want to click on the map (outside the layer and its features) and find the geographically nearest point feature in the layer to the point that I clicked.
This seems like a pretty reasonable thing to want to do, but the GeometryEngine doesn't perform well in this scenario due to the large number of point features in this layer. Here's what I've tried or thought about trying, but doesn't work.
1.
- Create a buffer polygon for a fixed distance around the point that I click.
- Find all features in the feature layer that intersects with buffer polygon.
- Find distances between original point and each of the intersected features.
- Sort these distances to find the feature that is closest to the point that I clicked on.
This doesn't work because my feature layer has 120,000 point features. If I iterate through each of them to check if they intersect with my buffer polygon, it can take a LONG time.
2. I've thought about using ClosestFacilityTask, but this requires an online connection. So not an option for me.
Ideally, I guess I would've liked a Runtime method I can call where I input in these parameters: 1) original point's geometry and 2) feature layer. This would return a single feature that is closest to my point. But this is not a Runtime feature AFAIK.
Does anyone else have any ideas on how to proceed here? Any help appreciated.