Hi! How to select an object from a ready-made scene loaded from the portal, as in this example ! ArcGIS Runtime SDK for Android 100.4.1
I was able to choose only one layer, how to implement for multiple layers?
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">final</SPAN> Layer Layer<SPAN class="operator token">:</SPAN> mSceneView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getScene</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getOperationalLayers</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>Layer <SPAN class="keyword token">instanceof</SPAN> <SPAN class="token class-name">ArcGISSceneLayer</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> sceneLayer <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>ArcGISSceneLayer<SPAN class="punctuation token">)</SPAN> Layer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> mSceneView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setOnTouchListener</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DefaultSceneViewOnTouchListener</SPAN><SPAN class="punctuation token">(</SPAN>mSceneView<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> @Override <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">boolean</SPAN> <SPAN class="token function">onSingleTapConfirmed</SPAN><SPAN class="punctuation token">(</SPAN>MotionEvent motionEvent<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// clear any previous selection</SPAN> sceneLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">clearSelection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> android<SPAN class="punctuation token">.</SPAN>graphics<SPAN class="punctuation token">.</SPAN>Point screenPoint <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">android<SPAN class="punctuation token">.</SPAN>graphics<SPAN class="punctuation token">.</SPAN>Point</SPAN><SPAN class="punctuation token">(</SPAN>Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">round</SPAN><SPAN class="punctuation token">(</SPAN>motionEvent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getX</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">round</SPAN><SPAN class="punctuation token">(</SPAN>motionEvent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getY</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// identify clicked feature</SPAN> ListenableFuture<SPAN class="operator token"><</SPAN>IdentifyLayerResult<SPAN class="operator token">></SPAN> identify <SPAN class="operator token">=</SPAN> mSceneView <SPAN class="punctuation token">.</SPAN><SPAN class="token function">identifyLayerAsync</SPAN><SPAN class="punctuation token">(</SPAN>sceneLayer<SPAN class="punctuation token">,</SPAN> screenPoint<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> identify<SPAN class="punctuation token">.</SPAN><SPAN class="token function">addDoneListener</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// get the identified result and check that it is a feature</SPAN> IdentifyLayerResult result <SPAN class="operator token">=</SPAN> identify<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> List<SPAN class="operator token"><</SPAN>GeoElement<SPAN class="operator token">></SPAN> geoElements <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getElements</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>geoElements<SPAN class="punctuation token">.</SPAN><SPAN class="token function">isEmpty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Log<SPAN class="punctuation token">.</SPAN><SPAN class="token function">d</SPAN><SPAN class="punctuation token">(</SPAN>TAG<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"geoelement not empty"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> GeoElement geoElement <SPAN class="operator token">=</SPAN> geoElements<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>geoElement <SPAN class="keyword token">instanceof</SPAN> <SPAN class="token class-name">Feature</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// select the feature</SPAN> sceneLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">selectFeature</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>Feature<SPAN class="punctuation token">)</SPAN> geoElement<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">InterruptedException</SPAN> <SPAN class="operator token">|</SPAN> ExecutionException e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> String error <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Error while identifying layer result: "</SPAN> <SPAN class="operator token">+</SPAN> e<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getMessage</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> Log<SPAN class="punctuation token">.</SPAN><SPAN class="token function">e</SPAN><SPAN class="punctuation token">(</SPAN>TAG<SPAN class="punctuation token">,</SPAN> error<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> Toast<SPAN class="punctuation token">.</SPAN><SPAN class="token function">makeText</SPAN><SPAN class="punctuation token">(</SPAN>MainActivity<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">,</SPAN> error<SPAN class="punctuation token">,</SPAN> Toast<SPAN class="punctuation token">.</SPAN>LENGTH_LONG<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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 } }
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
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
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.