I fixed this. Here is the code for who wants do the same.
mapView.setOnSingleTapListener(new OnSingleTapListener() {
@Override
public void onSingleTap(float v, float v1) {
Point point = mapView.toMapPoint(v, v1);
new AsyncTaskDetalhePontoNoMapa(getURLTipoMapa(), point, mapView, arcGISDynamicMapServiceLayer.getSpatialReference(), isOutorga(), ActivityMapa.this).execute();
}
});
Finally, my asynctask:
import android.os.AsyncTask;
import com.esri.android.map.MapView;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.FeatureSet;
import com.esri.core.map.Graphic;
import com.esri.core.tasks.ags.query.Query;
import com.esri.core.tasks.ags.query.QueryTask;
import org.codehaus.jackson.map.ObjectMapper;
import app.i3systems.bramar.ffdc.interfaces.Listable;
import app.i3systems.bramar.ffdc.interfaces.PontoClicavel;
import app.i3systems.bramar.ffdc.model.Outorga;
import app.i3systems.bramar.ffdc.model.Poco;
import app.i3systems.bramar.ffdc.utils.Utils;
import app.i3systems.bramar.ffdc.utils.UtilsSharedPreferences;
/**
* Created by pedrofsn on 07-07-17.
*/
public class AsyncTaskDetalhePontoNoMapa extends AsyncTask<Point, Void, String> {
private Point clickPoint;
private double resolution;
private String url;
private SpatialReference spatialReference;
private boolean isOutorga;
private PontoClicavel callback;
public AsyncTaskDetalhePontoNoMapa(String url, Point clickPoint, MapView mapView, SpatialReference spatialReference, boolean isOutorga, PontoClicavel callback) {
this.url = url;
this.callback = callback;
this.isOutorga = isOutorga;
this.clickPoint = clickPoint;
this.spatialReference = spatialReference;
this.resolution = mapView.getResolution();
}
@Override
protected String doInBackground(Point... params) {
double tolerance = 100;
double resolutionWithTolerance = tolerance * resolution;
Envelope envelope = new Envelope(clickPoint, resolutionWithTolerance, resolutionWithTolerance);
try {
UserCredentials userCredentials = new UserCredentials();
userCredentials.setUserAccount(UtilsSharedPreferences.getLogin(), UtilsSharedPreferences.getSenha());
QueryTask queryTask = new QueryTask(url + "/0", userCredentials);
Query query = new Query();
query.setInSpatialReference(spatialReference);
query.setOutSpatialReference(spatialReference);
query.setGeometry(envelope);
query.setMaxFeatures(30);
query.setOutFields(new String[]{"*"});
FeatureSet featureSet = queryTask.execute(query);
Graphic[] resultGraphic = featureSet.getGraphics();
if (!Utils.isNullOrEmpty(resultGraphic) && resultGraphic.length > 0) {
ObjectMapper mapper = new ObjectMapper();
Listable listable = mapper.convertValue(resultGraphic[0].getAttributes(), isOutorga ? Outorga.class : Poco.class);
return listable.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
Utils.log("Coordenadas : " + clickPoint.getX() + ", " + clickPoint.getY());
return null;
}
@Override
protected void onPostExecute(String string) {
super.onPostExecute(string);
callback.onDetalhesObtidosDoPontoNoMapa(clickPoint, string);
}
}