在我的项目中,我使用了MapView
ArcGIS Runtime for Android 中的一个。我对多边形内具有特定属性值的要素执行查询。搜索完成后,我想清除地图上所有现有的图形。我试过map.removeAll()
了,但它清除了我所有的图层!如何清除所有图形而不是删除所有图层?
这是我的代码:
private class AsyncQueryTask extends AsyncTask<String, Void, FeatureResult> {
@Override
protected void onPreExecute() {
progress = new ProgressDialog(Naghshe.this);
progress = ProgressDialog.show(Naghshe.this, "",
"Please wait....query task is executing");
}
@Override
protected FeatureResult doInBackground(String... queryArray) {
if (queryArray == null || queryArray.length <= 1)
return null;
String url = queryArray[0];
QueryParameters qParameters = new QueryParameters();
String whereClause = queryArray[1];
// SpatialReference sr = SpatialReference.create(102100);
qParameters.setGeometry(map.getExtent());
// qParameters.setOutSpatialReference(sr);
qParameters.setReturnGeometry(true);
qParameters.setWhere(whereClause);
QueryTask qTask = new QueryTask(url);
try {
FeatureResult results = qTask.execute(qParameters);
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(FeatureResult results) {
if (results != null) {
int size = (int) results.featureCount();
for (Object element : results) {
progress.incrementProgressBy(size / 100);
if (element instanceof Feature) {
Feature feature = (Feature) element;
Graphic graphic = new Graphic(feature.getGeometry(),
feature.getSymbol(), feature.getAttributes());
_graphicsLayer = new GraphicsLayer();
_graphicsLayer.addGraphic(graphic);
SimpleRenderer sr = new SimpleRenderer(new SimpleFillSymbol(Color.RED));
_graphicsLayer.setRenderer(sr);
boolean m =false;
if(!m)
{
map.addLayer(_graphicsLayer);
m=true;
}else {
map.removeLayer(_graphicsLayer);
map.addLayer(_graphicsLayer);
}
map.zoomin();
k++;
}
}
}
progress.dismiss();
boolQuery = false;
}