AnsweredAssumed Answered

How to click in point of map and show attributes (like sample)?

Question asked by pedrokra on Jul 3, 2017
Latest reply on Jul 10, 2017 by pedrokra

I tried a query and on web-query for tests purpose and it's working, like: http://is.bramar.net/arcgis/rest/services/SocioEconomics/OutrogasAESA_FS/FeatureServer/0/query?where=1+%3D+1&objectIds=&… 

 

In android it is not working.

 

My code:

[...]

compile 'com.esri.arcgis.android:arcgis-android:10.2.9'
[...]

featureLayer = new ArcGISFeatureLayer(

"http://is.bramar.net/arcgis/rest/services/SocioEconomics/OutrogasAESA_FS/FeatureServer"

, MODE.ONDEMAND);
[...]

and

mapView.setOnSingleTapListener(new OnSingleTapListener() {

    public void onSingleTap(float x, float y) {

        Geometry geom = (GeometryEngine.buffer(pointClicked, mapView.getSpatialReference(), 100, null));

        // build a query to select the clicked feature
        Query query = new Query();
        query.setOutFields(new String[]{"*"});
        query.setSpatialRelationship(SpatialRelationship.ENVELOPE_INTERSECTS);
        query.setGeometry(geom);
        query.setInSpatialReference(mapView.getSpatialReference());

        featureLayer.selectFeatures(query, ArcGISFeatureLayer.SELECTION_METHOD.NEW, new CallbackListener<FeatureSet>() {

            // handle any errors
            public void onError(Throwable e) {
                Log.d(TAG, "Select Features Error" + e.getLocalizedMessage());
            }

            public void onCallback(FeatureSet queryResults) {

                int size = 0;

                if (!Utils.isNullOrEmpty(queryResults.getGraphics())) {
                    size = queryResults.getGraphics().length;
                }

                Utils.log("Size: " + size);

                if (size > 0) {

                    Log.d(TAG, "Feature found id=" + queryResults.getGraphics()[0].getAttributeValue(featureLayer.getObjectIdField()));

                    // set new data and notify adapter that data has changed
                    listAdapter.setFeatureSet(queryResults);
                    listAdapter.notifyDataSetChanged();

                    // This callback is not run in the main UI thread. All GUI
                    // related events must run in the UI thread,
                    // therefore use the Activity.runOnUiThread() method. See
                    // http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)
                    // for more information.
                    AttributeEditorActivity.this.runOnUiThread(new Runnable() {

                        public void run() {

                            // show the editor dialog.
                            showDialog(ATTRIBUTE_EDITOR_DIALOG_ID);

                        }
                    });
                }
            }
        });
    }
});

Outcomes