Selecting an object in SceneView

900
6
03-27-2019 10:08 AM
AlexanderKulikov
New Contributor II

Hi! How to select an object from a ready-made scene loaded from the portal,  as in this exampleArcGIS Runtime SDK for Android 100.4.1

0 Kudos
6 Replies
by Anonymous User
Not applicable

Hi Alexander,

Is there a particular way you're wanting to select an object that is different from how it's demonstrated in the sample? Is it by tapping on it or as a result of some other query?

https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/scene-layer-selection/

Cheers,

Trevor

0 Kudos
AlexanderKulikov
New Contributor II

Clicking on it! I don't know how to work with: ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(buildings); The example uses a single layer that is loaded by url. How to do the same but with loaded from the scene portal

0 Kudos
by Anonymous User
Not applicable

Hi Alexander,

You should be able to access any scene layers in your scene with a call .getOperationalLayers() and then getting one or more layers from the LayerList. So something like:

for (Layer layer : scene.getOperationalLayers()) {
  if (layer instanceof ArcGISSceneLayer) {
    // follow the above sample for implementing identify and select on the scene layer 
  }
}
0 Kudos
AlexanderKulikov
New Contributor II

I was able to choose only one layer, how to implement for multiple layers?

for (final Layer Layer: mSceneView.getScene().getOperationalLayers()) {
                            if (Layer instanceof ArcGISSceneLayer) {
                                sceneLayer = ((ArcGISSceneLayer) Layer);
                            }
                        }


mSceneView.setOnTouchListener(new DefaultSceneViewOnTouchListener(mSceneView) {

                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {

                        // clear any previous selection

                        sceneLayer.clearSelection();

                        android.graphics.Point screenPoint = new android.graphics.Point(Math.round(motionEvent.getX()),
                                Math.round(motionEvent.getY()));

                        // identify clicked feature
                        ListenableFuture<IdentifyLayerResult> identify = mSceneView
                                .identifyLayerAsync(sceneLayer, screenPoint, 10, false, 10);

                        identify.addDoneListener(() -> {
                            try {
                                // get the identified result and check that it is a feature
                                IdentifyLayerResult result = identify.get();
                                List<GeoElement> geoElements = result.getElements();
                                if (!geoElements.isEmpty()) {
                                    Log.d(TAG, "geoelement not empty");
                                    GeoElement geoElement = geoElements.get(0);
                                    if (geoElement instanceof Feature) {
                                        // select the feature

                                        sceneLayer.selectFeature((Feature) geoElement);
                                    }
                                }
                            } catch (InterruptedException | ExecutionException e) {
                                String error = "Error while identifying layer result: " + e.getMessage();
                                Log.e(TAG, error);
                                Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show();
                            }
                        });
                        return true;
                    }

                });
0 Kudos
by Anonymous User
Not applicable

Hi!

We've got a very similar method for handling that! identifyLayersAsync(...).

There's a sample of it being implemented here (on a MapView, but the syntax is identical for a SceneView--both inherit a GeoView which implements identify). https://github.com/Esri/arcgis-runtime-samples-android/blob/65533272642bd366e31af709c250063ded30219a...

You'll want to call getElements() on the identify result to get the geoelements you want to select

Kind regards,

Trevor

0 Kudos
AlexanderKulikov
New Contributor II

Hi!

It became even more unclear  How to call selectFeature?

0 Kudos