Java ARCGIS android无法从querytask结果中获取扩展
我在使用ArcGIS android运行时API开发android应用程序方面有新的经验 我正在尝试缩放到一个延伸和延伸的远光灯。但对我来说,它不起作用 要素图层urlishttps://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyGisFileTest/FeatureServer/0 从ArcGIS在线门户获取。 我已经在地图上添加了图层Java ARCGIS android无法从querytask结果中获取扩展,java,android,arcgis-runtime,Java,Android,Arcgis Runtime,我在使用ArcGIS android运行时API开发android应用程序方面有新的经验 我正在尝试缩放到一个延伸和延伸的远光灯。但对我来说,它不起作用 要素图层urlishttps://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyGisFileTest/FeatureServer/0 从ArcGIS在线门户获取。 我已经在地图上添加了图层 ArcGISFeatureLayer fl1 = new ArcGISFeat
ArcGISFeatureLayer fl1 = new ArcGISFeatureLayer(
"https://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyGisFileTest/FeatureServer/0",
ArcGISFeatureLayer.MODE.ONDEMAND);
fl1.setOnStatusChangedListener(statusChangedListener);
mMapView.addLayer(fl1);
在这里,我使用edittext从用户输入中获取我的ward\u name
,并将其提交给asyn类以获取数据
我在单击按钮时调用同步任务,并将用户输入的值传递给异步任务
声明部分
//query task
private Callout mCallout;
private ViewGroup mCalloutContent;
private Graphic mIdentifiedGraphic;
private String mFeatureServiceURL;
private GraphicsLayer mGraphicsLayer;
private ProgressDialog progress;
EditText _EdtTxtTextToZoom;
Button _BtnZoomToExtend;
在我的oncreate方法中,我定义了所有的东西
mGraphicsLayer = new GraphicsLayer();
mMapView.addLayer(mGraphicsLayer);
LayoutInflater inflater = getLayoutInflater();
mCallout = mMapView.getCallout();
// Get the layout for the Callout from
// layout->identify_callout_content.xml
mFeatureServiceURL="https://services7.arcgis.com/7FyZZrSIYfiWYztL/ArcGIS/rest/services/MyMapService/FeatureServer/0";
mCalloutContent = (ViewGroup) inflater.inflate(R.layout.identify_callout_content, null);
mCallout.setContent(mCalloutContent);
mIdentifiedGraphic = getFeature(fl1);
_EdtTxtTextToZoom=(EditText)findViewById(R.id.EdtTxtTextToZoom);
_BtnZoomToExtend=(Button)findViewById(R.id.BtnZoomToExtend);
_BtnZoomToExtend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String tempEdtTxtTextToZoom= "";
try {
tempEdtTxtTextToZoom = _EdtTxtTextToZoom.getText().toString();
new QueryFeatureLayer().execute(tempEdtTxtTextToZoom);
} catch (NumberFormatException e) {
e.printStackTrace();
}
Toast.makeText(MainActivity.this, "tempEdtTxtTextToZoom.."+tempEdtTxtTextToZoom, Toast.LENGTH_SHORT).show();
}
});
异步任务
private class QueryFeatureLayer extends AsyncTask<String, Void, FeatureResult> {
// default constructor
public QueryFeatureLayer() {
}
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(MainActivity.this, "", "Please wait....query task is executing");
}
@Override
protected FeatureResult doInBackground(String... params) {
Log.e("params[0]--",params[0]);
String whereClause = "ward_name ='" + params[0] + "'";
Log.e("whereClause--",whereClause);
// Define a new query and set parameters
QueryParameters mParams = new QueryParameters();
mParams.setWhere(whereClause);
mParams.setReturnGeometry(true);
// Define the new instance of QueryTask
QueryTask queryTask = new QueryTask(mFeatureServiceURL);
FeatureResult results;
try {
// run the querytask
results = queryTask.execute(mParams);
Log.e("results---", String.valueOf(results));
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(FeatureResult results) {
// Remove the result from previously run query task
mGraphicsLayer.removeAll();
// Define a new marker symbol for the result graphics
SimpleMarkerSymbol mGreenMarkerSymbol = new SimpleMarkerSymbol(Color.GREEN, 15, SimpleMarkerSymbol.STYLE.CIRCLE);
// Envelope to focus on the map extent on the results
Envelope extent = new Envelope();
// iterate through results
for (Object element : results) {
// if object is feature cast to feature
if (element instanceof Feature) {
Feature feature = (Feature) element;
// convert feature to graphic
Graphic graphic = new Graphic(feature.getGeometry(), mGreenMarkerSymbol, feature.getAttributes());
// merge extent with point
extent.merge((Point)graphic.getGeometry());
Log.e("points----", String.valueOf(graphic.getGeometry()));
// add it to the layer
mGraphicsLayer.addGraphic(graphic);
}
}
Log.e("points----", String.valueOf(extent));
// Set the map extent to the envelope containing the result graphics
mMapView.setExtent(extent, 100);
// Disable the progress dialog
progress.dismiss();
}
}
私有类QueryFeatureLayer扩展异步任务{
//默认构造函数
公共查询功能层(){
}
@凌驾
受保护的void onPreExecute(){
progress=ProgressDialog.show(MainActivity.this,“,”请稍候…正在执行查询任务“);
}
@凌驾
受保护的功能结果doInBackground(字符串…参数){
Log.e(“参数[0]-”,参数[0]);
字符串whereClause=“ward_name=”+参数[0]+“”;
Log.e(“whereClause--”,whereClause);
//定义新查询并设置参数
QueryParameters mParams=新的QueryParameters();
mParams.setWhere(where条款);
mParams.setReturnGeometry(真);
//定义QueryTask的新实例
QueryTask QueryTask=新的QueryTask(mFeatureServiceURL);
特征结果;
试一试{
//运行查询任务
结果=queryTask.execute(mParams);
Log.e(“results--”,String.valueOf(results));
返回结果;
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
@凌驾
PostExecute上受保护的void(功能结果){
//从以前运行的查询任务中删除结果
mGraphicsLayer.removeAll();
//为结果图形定义新的标记符号
SimpleMarkerSymbol mGreenMarkerSymbol=新的SimpleMarkerSymbol(Color.GREEN,15,SimpleMarkerSymbol.STYLE.CIRCLE);
//包络线以聚焦结果上的贴图范围
信封范围=新信封();
//遍历结果
用于(对象元素:结果){
//如果对象是要素强制转换为要素
if(要素的元素实例){
特征=(特征)元素;
//将要素转换为图形
Graphic Graphic=新图形(feature.getGeometry(),mGreenMarkerSymbol,feature.getAttributes());
//将范围与点合并
extent.merge((Point)graphic.getGeometry());
Log.e(“points--”,String.valueOf(graphic.getGeometry());
//将其添加到图层中
mGraphicsLayer.addGraphic(图形);
}
}
Log.e(“points--”,String.valueOf(extent));
//将贴图范围设置为包含结果图形的封套
mMapView.setExtent(extent,100);
//禁用进度对话框
进步。解散();
}
}
你能找出我的错误吗?在上面的示例中,我试图缩放点,但实际上我希望下面的多边形是缩放特定多边形范围的正确代码
for (Object element : results) {
progress.incrementProgressBy(size / 100);
if (element instanceof Feature) {
Feature feature = (Feature) element;
// turn feature into graphic
Graphic graphic = new Graphic(feature.getGeometry(),
feature.getSymbol(), feature.getAttributes());
Polygon p = (Polygon) graphic.getGeometry();
p.queryEnvelope(extent);
extent.merge(extent);
// add graphic to layer
mGraphicsLayer.addGraphic(graphic);