1

From ArcGIS Runtime Java API documentation, there is an identifyLayersAsync() method.

From documentation:

Asynchronously identifies the topmost visible geo-element in each identifiable layer attached to the map, near given screen point.

Is there a way to for ArcGIS Runtime to return a single geo-element belonging to any layer, such that it is the topmost element?

P.S. Also asked on Stackoverflow.

Edit

I'm still having this problem. To rephrase it, I need to find out the feature (that belongs to any layer within a list of layers) that the user has clicked on. The feature returned must be feature that the user thought he/she has clicked on (based on visual judgement).

Additionally, the method must work for both maps and scenes.

I'm going to offer bounty on both sites. At this point I'm quite sure that the API doesn't do this out-of-the-box, so I'm looking for work-around solutions.

Edit 2

It looks like my question stating about "topmost feature" has caused some confusion. The "topmost" condition is only true when it is a MapView (2D). What I really need is to identify the feature that the user is actually seeing on the MapView/SceneView when the user does the clicking.

Additionally, features at the bottom layer may have a very high "z" (height) value and may appear nearest to the camera viewport.

If you call identifyLayerAsync() for a single layer, the API would be able to figure out the feature that is nearest to the viewport. However, the API does not have any mean to do the same analysis taking in all features from all layers (or selected list of layers).

0

I haven't tested this where features within a particular layer overlap, but if it behaves as Esri advertises, then it should work in that case too.

private async Task<IdentifyLayerResult> GetTopMost(GeoView view, LayerCollection layers, System.Windows.Point pnt)
{
    int tolerance = 3; // pixels
    var results = await view.IdentifyLayersAsync(pnt, tolerance, false);
    IdentifyLayerResult topmost = null;
    int topIdx = -1;
    foreach (var result in results)
    {
        var layer = layers.FirstOrDefault(l => l.Name == result.LayerContent.Name);
        if (layer != null)
        {
            int idx = layers.IndexOf(layer);
            if (idx > topIdx)
            {
                topmost = result;
                topIdx = idx;
            }
        }
        else
            Debug.Print("no layer found named " + result.LayerContent.Name);
    }
    if (topmost != null)
    {
        Debug.Print("Top most: " + topmost.LayerContent.Name + " idx: " + topIdx
            + ", count: " + topmost.GeoElements.Count);

        var toplayer = layers[topIdx];
    }
    else
    {
        Debug.Print("no feature identified");
    }
    return topmost;
}

With a mapview ...

private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
    var topmost = await GetTopMost(MyMapView,MyMapView.Map.OperationalLayers, e.Position);
}

With a sceneview ...

private async void MySceneView_GeoViewDoubleTapped(object sender, GeoViewInputEventArgs e)
{
    var result = await GetTopMost(MySceneView, MySceneView.Scene.OperationalLayers, e.Position);
}
  • updated to work with either sceneview or mapview – Kirk Kuykendall Feb 21 at 23:12
  • I believe this would work for a mapview where layers that are at the top would generally appear to be nearest to the user. For a sceneview, features at the top layer doesn't always mean that it is nearer to the user's viewport. – Jai Feb 22 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.