AnsweredAssumed Answered

Convert Queried Feature to ArcGIS Feature - ArcGIS Android SDK

Question asked by on Feb 8, 2019
Latest reply on Feb 11, 2019 by

Hello Everyone,

Given below are my scenario

Query the service Url with object id then if it contains any attachment then display it and facilitate the user to add attachments.

I have referred the samples and found the Edit attachment. But in that it has been done through ListenableFuture<IdentifyLayerResult>. But instead I want to do it with ListenableFuture<FeatureQueryResult>

Everything fine till the query and getting result. After getting result and iterating through next. I am getting result as feature and could not find any method to convert  from to Please suggest me on this.

Given below Code Snap

private void
    mServiceFeatureTable = new ServiceFeatureTable(getString(R.string.sample_service_url));
    // create the feature layer using the service feature table
    mFeatureLayer = new FeatureLayer(mServiceFeatureTable);
    // clear any previous selection
    mSelectedArcGISFeature = null;
    final QueryParameters query = new QueryParameters();
    final String searchString ="objectid=77";

    //make search case insensitive
    final ListenableFuture<FeatureQueryResult> future = mServiceFeatureTable.queryFeaturesAsync(query, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

    // add done loading listener to fire when the selection returns
    future.addDoneListener(new Runnable() {
        public void run() {
            try {
                // call get on the future to get the result
                FeatureQueryResult result = future.get();

                // check there are some results
                if (result.iterator().hasNext()) {

                    // get the extend of the first feature in the result to zoom to

                    Feature feature = result.iterator().next();
                    Envelope envelope = feature.getGeometry().getExtent();
                    mMapView.setViewpointGeometryAsync(envelope, 10);
                       //Select the feature
             //*** GOT STUCKUP HERE * mselectedArcGISFeature is ArcGISFeature ---- How to Convert Feature to ArcGISFeature

                    mAttributeID = mSelectedArcGISFeature.getAttributes().get("objectid").toString();
                    // get the number of attachments
                    final ListenableFuture<List<Attachment>> attachmentResults = mSelectedArcGISFeature.fetchAttachmentsAsync();
                    attachmentResults.addDoneListener(new Runnable() {
                        public void run() {
                            try {
                                attachments = attachmentResults.get();
                                Log.d("number of attachments :", attachments.size() + "");
                                // show callout with the value for the attribute "typdamage" of the selected feature
                                mSelectedArcGISFeatureAttributeValue = (String) mSelectedArcGISFeature.getAttributes().get("typdamage");
                                if (progressDialog.isShowing()) {
                                showCallout(mSelectedArcGISFeatureAttributeValue, attachments.size(),mapPoint);
                                Toast.makeText(MainActivity.this, getApplication().getString(R.string.info_button_message), Toast.LENGTH_SHORT).show();
                            } catch (Exception e) {
                                Log.e(TAG, e.getMessage());

                } else {
                    Toast.makeText(MainActivity.this, "No states found with name: " + searchString, Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                Toast.makeText(MainActivity.this, "Feature search failed for: " + searchString + ". Error=" + e.getMessage(),
                        "Feature search failed for: " + searchString + ". Error=" + e.getMessage());